Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 13, 16:45 UTC
forwardauth: Fix case when `copy_headers` is omitted (#4856)
See https://caddy.community/t/using-forward-auth-and-writing-my-own-authenticator-in-php/16410, apparently it didn't work when `copy_headers` wasn't used. This is because we were skipping adding a handler to the routes in the "good response handler", but this causes the logic in `reverseproxy.go` to ignore the response handler since it's empty. Instead, we can just always put in the `header` handler, even with an empty `Set` operation, it's just a no-op, but it fixes that condition in the proxy code.
Francis Lavoie committed
Jun 28, 2022 at 21:23 UTC
58e05cab155643c6543892855f373ea8755eb094
1 file changed
+24
-22
modules/caddyhttp/reverseproxy/forwardauth/caddyfile.go
+24
-22
@@ -185,32 +185,34 @@ func parseCaddyfile(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error)
185
},
186
Routes: []caddyhttp.Route{},
187
}
188
- if len(headersToCopy) > 0 {
189
- handler := &headers.Handler{
190
- Request: &headers.HeaderOps{
191
- Set: http.Header{},
192
- },
193
- }
188
195
- for from, to := range headersToCopy {
196
- handler.Request.Set[to] = []string{
197
- "{http.reverse_proxy.header." + from + "}",
198
- }
199
- }
189
+ handler := &headers.Handler{
190
+ Request: &headers.HeaderOps{
191
+ Set: http.Header{},
192
+ },
193
+ }
194
201
- goodResponseHandler.Routes = append(
202
- goodResponseHandler.Routes,
203
- caddyhttp.Route{
204
- HandlersRaw: []json.RawMessage{caddyconfig.JSONModuleObject(
205
- handler,
206
- "handler",
207
- "headers",
208
- nil,
209
- )},
210
- },
211
- )
195
+ // the list of headers to copy may be empty, but that's okay; we
196
+ // need at least one handler in the routes for the response handling
197
+ // logic in reverse_proxy to not skip this entry as empty.
198
+ for from, to := range headersToCopy {
199
+ handler.Request.Set[to] = []string{
200
+ "{http.reverse_proxy.header." + from + "}",
201
+ }
202
}
203
204
+ goodResponseHandler.Routes = append(
205
+ goodResponseHandler.Routes,
206
+ caddyhttp.Route{
207
+ HandlersRaw: []json.RawMessage{caddyconfig.JSONModuleObject(
208
+ handler,
209
+ "handler",
210
+ "headers",
211
+ nil,
212
+ )},
213
+ },
214
+ )
215
+
216
// note that when a response has any other status than 2xx, then we
217
// use the reverse proxy's default behaviour of copying the response
218
// back to the client, so we don't need to explicitly add a response