diff --git a/pkg/middlewares/auth/forward.go b/pkg/middlewares/auth/forward.go index 92f8b95ff..708ea85dc 100644 --- a/pkg/middlewares/auth/forward.go +++ b/pkg/middlewares/auth/forward.go @@ -126,6 +126,7 @@ func (fa *forwardAuth) ServeHTTP(rw http.ResponseWriter, req *http.Request) { rw.WriteHeader(http.StatusInternalServerError) return } + defer forwardResponse.Body.Close() body, readError := io.ReadAll(forwardResponse.Body) if readError != nil { @@ -136,7 +137,6 @@ func (fa *forwardAuth) ServeHTTP(rw http.ResponseWriter, req *http.Request) { rw.WriteHeader(http.StatusInternalServerError) return } - defer forwardResponse.Body.Close() // Pass the forward response's body and selected headers if it // didn't return a response within the range of [200, 300).