Skip to content

Commit 883f9bb

Browse files
committed
Avoid modifying method on HEAD requests
Traefik sends a forward auth request for every request, including HEAD methods, in order to validate if a request can continue. Due to Go HTTP client being strict to the HTTP SPEC, the response of a HEAD does not include a body, while Traefik expects a validation response to be embedded, causing errors. To mitigate this, when a X-Forwarded-Method is set as HEAD, we'll avoid modifying the HTTP Method response in order to send a body back, allowing head requests to by validated. This is necessary even if an allow rule is set, otherwhise it will fail as well. Mitagates: thomseddon#156
1 parent c4317b7 commit 883f9bb

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

internal/server.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,14 @@ func (s *Server) buildRoutes() {
5656
// forwarded request so it's correctly routed by mux
5757
func (s *Server) RootHandler(w http.ResponseWriter, r *http.Request) {
5858
// Modify request
59-
r.Method = r.Header.Get("X-Forwarded-Method")
59+
60+
/// Avoid HEAD bug
61+
/// https://github.com/thomseddon/traefik-forward-auth/issues/156
62+
var m = r.Header.Get("X-Forwarded-Method")
63+
if m != "HEAD" {
64+
r.Method = m
65+
}
66+
6067
r.Host = r.Header.Get("X-Forwarded-Host")
6168

6269
// Read URI from header if we're acting as forward auth middleware

0 commit comments

Comments
 (0)