summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/headers/headers.go
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2019-09-11 18:48:37 -0600
committerMatthew Holt <mholt@users.noreply.github.com>2019-09-11 18:48:37 -0600
commit005a11cf4b0af5bfbbb72f8572681b327675541c (patch)
treeba075312bab40d49e66cb9fe24f722896b99028c /modules/caddyhttp/headers/headers.go
parent194df652eb9d92bcc61d83055aebe176adc8fa2d (diff)
headers: New 'request_header' directive; handle Host header specially
Before this change, only response headers could be manipulated with the Caddyfile's 'header' directive. Also handle the request Host header specially, since the Go standard library treats it separately from the other header fields...
Diffstat (limited to 'modules/caddyhttp/headers/headers.go')
-rw-r--r--modules/caddyhttp/headers/headers.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/modules/caddyhttp/headers/headers.go b/modules/caddyhttp/headers/headers.go
index e740004..ba9d89d 100644
--- a/modules/caddyhttp/headers/headers.go
+++ b/modules/caddyhttp/headers/headers.go
@@ -58,7 +58,18 @@ type RespHeaderOps struct {
func (h Headers) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error {
repl := r.Context().Value(caddy.ReplacerCtxKey).(caddy.Replacer)
+
apply(h.Request, r.Header, repl)
+
+ // request header's Host is handled specially by the
+ // Go standard library, so if that header was changed,
+ // change it in the Host field since the Header won't
+ // be used
+ if intendedHost := r.Header.Get("Host"); intendedHost != "" {
+ r.Host = intendedHost
+ r.Header.Del("Host")
+ }
+
if h.Response != nil {
if h.Response.Deferred || h.Response.Require != nil {
w = &responseWriterWrapper{