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 "path"
|
||||
import "io/fs"
|
||||
import "slices"
|
||||
import "errors"
|
||||
import "strings"
|
||||
import "strconv"
|
||||
@ -48,6 +49,31 @@ func (this *Handler) Init (ctx context.Context) error {
|
||||
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) {
|
||||
remoteAddrStr := req.RemoteAddr
|
||||
if addr := req.Header.Get("CF-Connecting-IP"); addr != "" {
|
||||
@ -274,7 +300,6 @@ func (this *Handler) serveError (
|
||||
if safeMode || this.ErrorDocument == "" {
|
||||
res.Header().Add("Content-Type", "text/plain")
|
||||
res.WriteHeader(status)
|
||||
// TODO: allow customization with templates
|
||||
if message == nil {
|
||||
fmt.Fprintf(res, "%d %s\n", status, http.StatusText(status))
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user