From 98468af8b6224d29431576fe30a7d92a8676030d Mon Sep 17 00:00:00 2001 From: Francis Lavoie Date: Wed, 22 Jun 2022 15:10:14 -0400 Subject: reverseproxy: Fix double headers in response handlers (#4847) --- .../reverseproxy/forwardauth/caddyfile.go | 47 +++------------------- 1 file changed, 6 insertions(+), 41 deletions(-) (limited to 'modules/caddyhttp/reverseproxy/forwardauth') diff --git a/modules/caddyhttp/reverseproxy/forwardauth/caddyfile.go b/modules/caddyhttp/reverseproxy/forwardauth/caddyfile.go index c22ddde..8230216 100644 --- a/modules/caddyhttp/reverseproxy/forwardauth/caddyfile.go +++ b/modules/caddyhttp/reverseproxy/forwardauth/caddyfile.go @@ -59,13 +59,6 @@ func init() { // Remote-Email {http.reverse_proxy.header.Remote-Email} // } // } -// -// handle_response { -// copy_response_headers { -// exclude Connection Keep-Alive Te Trailers Transfer-Encoding Upgrade -// } -// copy_response -// } // } // func parseCaddyfile(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error) { @@ -217,41 +210,13 @@ func parseCaddyfile(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error) }, ) } - rpHandler.HandleResponse = append(rpHandler.HandleResponse, goodResponseHandler) - // set up handler for denial responses; when a response - // has any other status than 2xx, then we copy the response - // back to the client, and terminate handling. - denialResponseHandler := caddyhttp.ResponseHandler{ - Routes: []caddyhttp.Route{ - { - HandlersRaw: []json.RawMessage{caddyconfig.JSONModuleObject( - &reverseproxy.CopyResponseHeadersHandler{ - Exclude: []string{ - "Connection", - "Keep-Alive", - "Te", - "Trailers", - "Transfer-Encoding", - "Upgrade", - }, - }, - "handler", - "copy_response_headers", - nil, - )}, - }, - { - HandlersRaw: []json.RawMessage{caddyconfig.JSONModuleObject( - &reverseproxy.CopyResponseHandler{}, - "handler", - "copy_response", - nil, - )}, - }, - }, - } - rpHandler.HandleResponse = append(rpHandler.HandleResponse, denialResponseHandler) + // note that when a response has any other status than 2xx, then we + // use the reverse proxy's default behaviour of copying the response + // back to the client, so we don't need to explicitly add a response + // handler specifically for that behaviour; we do need the 2xx handler + // though, to make handling fall through to handlers deeper in the chain. + rpHandler.HandleResponse = append(rpHandler.HandleResponse, goodResponseHandler) // the rest of the config is specified by the user // using the reverse_proxy directive syntax -- cgit v1.2.3