@marcel91200 / caddy Mirror · read-only / commits / 90c7b4b0
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 14, 05:15 UTC

reverseproxy: Apply response header ops before copying it (fix #3382) (#3401)

Matt Holt committed May 13, 2020 at 09:52 UTC 90c7b4b0a1589b3b070b6268fd412d8f95f36eca
1 file changed +9 -9
modules/caddyhttp/reverseproxy/reverseproxy.go
+9 -9
@@ -510,6 +510,15 @@ func (h *Handler) reverseProxy(rw http.ResponseWriter, req *http.Request, di Dia
510 res.Header.Del(h)
511 }
512
513 + // apply any response header operations
514 + if h.Headers != nil && h.Headers.Response != nil {
515 + if h.Headers.Response.Require == nil ||
516 + h.Headers.Response.Require.Match(res.StatusCode, res.Header) {
517 + repl := req.Context().Value(caddy.ReplacerCtxKey).(*caddy.Replacer)
518 + h.Headers.Response.ApplyTo(res.Header, repl)
519 + }
520 + }
521 +
522 copyHeader(rw.Header(), res.Header)
523
524 // 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
532 rw.Header().Add("Trailer", strings.Join(trailerKeys, ", "))
533 }
534
526 - // apply any response header operations
527 - if h.Headers != nil && h.Headers.Response != nil {
528 - if h.Headers.Response.Require == nil ||
529 - h.Headers.Response.Require.Match(res.StatusCode, rw.Header()) {
530 - repl := req.Context().Value(caddy.ReplacerCtxKey).(*caddy.Replacer)
531 - h.Headers.Response.ApplyTo(rw.Header(), repl)
532 - }
533 - }
534 -
535 // TODO: there should be an option to return an error if the response
536 // matches some criteria; would solve https://github.com/caddyserver/caddy/issues/1447
537 // by allowing the backend to determine whether this server should treat