summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/caddyhttp.go
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2019-05-04 13:21:20 -0600
committerMatthew Holt <mholt@users.noreply.github.com>2019-05-04 13:21:20 -0600
commit2eb35933271d5b2ef1ca29aaa8f00f6748c56424 (patch)
tree480d08eb3f9b85353fb858d2b1b6c9cb86f33954 /modules/caddyhttp/caddyhttp.go
parent1136e2cfeed5cc06a0811d39c2560c06f9dd74a2 (diff)
Begin implementing HTTP replacer and static responder
Diffstat (limited to 'modules/caddyhttp/caddyhttp.go')
-rw-r--r--modules/caddyhttp/caddyhttp.go25
1 files changed, 17 insertions, 8 deletions
diff --git a/modules/caddyhttp/caddyhttp.go b/modules/caddyhttp/caddyhttp.go
index de62b79..0731fea 100644
--- a/modules/caddyhttp/caddyhttp.go
+++ b/modules/caddyhttp/caddyhttp.go
@@ -167,14 +167,15 @@ func (hc *httpModuleConfig) automaticHTTPS(handle caddy2.Handle) error {
var defaultALPN = []string{"h2", "http/1.1"}
type httpServerConfig struct {
- Listen []string `json:"listen"`
- ReadTimeout caddy2.Duration `json:"read_timeout"`
- ReadHeaderTimeout caddy2.Duration `json:"read_header_timeout"`
- HiddenFiles []string `json:"hidden_files"` // TODO:... experimenting with shared/common state
- Routes routeList `json:"routes"`
- Errors httpErrorConfig `json:"errors"`
- TLSConnPolicies caddytls.ConnectionPolicies `json:"tls_connection_policies"`
- DisableAutoHTTPS bool `json:"disable_auto_https"`
+ Listen []string `json:"listen"`
+ ReadTimeout caddy2.Duration `json:"read_timeout"`
+ ReadHeaderTimeout caddy2.Duration `json:"read_header_timeout"`
+ HiddenFiles []string `json:"hidden_files"` // TODO:... experimenting with shared/common state
+ Routes routeList `json:"routes"`
+ Errors httpErrorConfig `json:"errors"`
+ TLSConnPolicies caddytls.ConnectionPolicies `json:"tls_connection_policies"`
+ DisableAutoHTTPS bool `json:"disable_auto_https"`
+ DisableAutoHTTPSRedir bool `json:"disable_auto_https_redir"`
tlsApp *caddytls.TLS
}
@@ -190,6 +191,12 @@ func (s httpServerConfig) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
+ // set up the replacer
+ repl := &Replacer{req: r, resp: w, custom: make(map[string]string)}
+ ctx := context.WithValue(r.Context(), ReplacerCtxKey, repl)
+ r = r.WithContext(ctx)
+
+ // build and execute the main middleware chain
stack := s.Routes.buildMiddlewareChain(w, r)
err := executeMiddlewareChain(w, r, stack)
if err != nil {
@@ -329,5 +336,7 @@ func (mrw middlewareResponseWriter) Write(b []byte) (int, error) {
return mrw.ResponseWriterWrapper.Write(b)
}
+const ReplacerCtxKey caddy2.CtxKey = "replacer"
+
// Interface guards
var _ HTTPInterfaces = middlewareResponseWriter{}