summaryrefslogtreecommitdiffhomepage
path: root/modules
diff options
context:
space:
mode:
authorMatt Holt <[email protected]>2020-05-13 09:52:20 -0600
committerGitHub <[email protected]>2020-05-13 09:52:20 -0600
commit90c7b4b0a1589b3b070b6268fd412d8f95f36eca (patch)
tree5081e2597fb54022f36a1fc384806d95cf374104 /modules
parentaef560c7fc52092a412d9e97112b8cb879c5eda5 (diff)
downloadcaddy-90c7b4b0a1589b3b070b6268fd412d8f95f36eca.tar.gz
caddy-90c7b4b0a1589b3b070b6268fd412d8f95f36eca.zip
reverseproxy: Apply response header ops before copying it (fix #3382) (#3401)
Diffstat (limited to 'modules')
-rw-r--r--modules/caddyhttp/reverseproxy/reverseproxy.go18
1 files changed, 9 insertions, 9 deletions
diff --git a/modules/caddyhttp/reverseproxy/reverseproxy.go b/modules/caddyhttp/reverseproxy/reverseproxy.go
index 9e0f63627..0b4bcdfbc 100644
--- a/modules/caddyhttp/reverseproxy/reverseproxy.go
+++ b/modules/caddyhttp/reverseproxy/reverseproxy.go
@@ -510,6 +510,15 @@ func (h *Handler) reverseProxy(rw http.ResponseWriter, req *http.Request, di Dia
res.Header.Del(h)
}
+ // apply any response header operations
+ if h.Headers != nil && h.Headers.Response != nil {
+ if h.Headers.Response.Require == nil ||
+ h.Headers.Response.Require.Match(res.StatusCode, res.Header) {
+ repl := req.Context().Value(caddy.ReplacerCtxKey).(*caddy.Replacer)
+ h.Headers.Response.ApplyTo(res.Header, repl)
+ }
+ }
+
copyHeader(rw.Header(), res.Header)
// The "Trailer" header isn't included in the Transport's response,
@@ -523,15 +532,6 @@ func (h *Handler) reverseProxy(rw http.ResponseWriter, req *http.Request, di Dia
rw.Header().Add("Trailer", strings.Join(trailerKeys, ", "))
}
- // apply any response header operations
- if h.Headers != nil && h.Headers.Response != nil {
- if h.Headers.Response.Require == nil ||
- h.Headers.Response.Require.Match(res.StatusCode, rw.Header()) {
- repl := req.Context().Value(caddy.ReplacerCtxKey).(*caddy.Replacer)
- h.Headers.Response.ApplyTo(rw.Header(), repl)
- }
- }
-
// TODO: there should be an option to return an error if the response
// matches some criteria; would solve https://github.com/caddyserver/caddy/issues/1447
// by allowing the backend to determine whether this server should treat