http: Should have been in the last commit
This commit is contained in:
parent
1e7b26f776
commit
ee0bb7e54b
@ -6,6 +6,7 @@ import "fmt"
|
|||||||
import "time"
|
import "time"
|
||||||
import "path"
|
import "path"
|
||||||
import "io/fs"
|
import "io/fs"
|
||||||
|
import "slices"
|
||||||
import "errors"
|
import "errors"
|
||||||
import "strings"
|
import "strings"
|
||||||
import "strconv"
|
import "strconv"
|
||||||
@ -48,6 +49,31 @@ func (this *Handler) Init (ctx context.Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *Handler) Configure (config step.Meta) error {
|
||||||
|
var err error
|
||||||
|
var rateLimit float64
|
||||||
|
if rateLimitStr := config.Get("http.rate-limit"); rateLimitStr != "" {
|
||||||
|
rateLimit, err = strconv.ParseFloat(rateLimitStr, 64)
|
||||||
|
if err != nil { return err }
|
||||||
|
}
|
||||||
|
this.Directories = config.Get("http.serve-directories") == "true"
|
||||||
|
this.StepExt = ucontainer.NewSet(slices.Clone(config["http.step-extension"])...)
|
||||||
|
this.Index = slices.Clone(config["http.index-file"])
|
||||||
|
this.ErrorDocument = config.Get("http.error-document")
|
||||||
|
this.DirectoryDocument = config.Get("http.directory-document")
|
||||||
|
this.DenyAll = ucontainer.NewSet("step.meta")
|
||||||
|
this.RateLimit = time.Duration(rateLimit * float64(time.Second))
|
||||||
|
this.TrustXForwardedFor = config.Get("http.trust-x-forwarded-for") == "true"
|
||||||
|
this.TrustCFConnectingIP = config.Get("http.trust-cf-connecting-ip") == "true"
|
||||||
|
if len(this.StepExt) == 0 {
|
||||||
|
this.StepExt.Add(".step")
|
||||||
|
}
|
||||||
|
if len(this.Index) == 0 {
|
||||||
|
this.Index = []string { "index.step", "index.html", "index" }
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (this *Handler) ServeHTTP (res http.ResponseWriter, req *http.Request) {
|
func (this *Handler) ServeHTTP (res http.ResponseWriter, req *http.Request) {
|
||||||
remoteAddrStr := req.RemoteAddr
|
remoteAddrStr := req.RemoteAddr
|
||||||
if addr := req.Header.Get("CF-Connecting-IP"); addr != "" {
|
if addr := req.Header.Get("CF-Connecting-IP"); addr != "" {
|
||||||
@ -274,7 +300,6 @@ func (this *Handler) serveError (
|
|||||||
if safeMode || this.ErrorDocument == "" {
|
if safeMode || this.ErrorDocument == "" {
|
||||||
res.Header().Add("Content-Type", "text/plain")
|
res.Header().Add("Content-Type", "text/plain")
|
||||||
res.WriteHeader(status)
|
res.WriteHeader(status)
|
||||||
// TODO: allow customization with templates
|
|
||||||
if message == nil {
|
if message == nil {
|
||||||
fmt.Fprintf(res, "%d %s\n", status, http.StatusText(status))
|
fmt.Fprintf(res, "%d %s\n", status, http.StatusText(status))
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user