1
0
Fork 0

Support informational headers in middlewares redefining the response writer.

Co-authored-by: LandryBe <lbenguigui@gmail.com>
This commit is contained in:
Romain 2023-06-14 17:42:44 +02:00 committed by GitHub
parent 68ed875966
commit 6885e410f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 471 additions and 7 deletions

View file

@ -36,10 +36,19 @@ func newResponseModifier(w http.ResponseWriter, r *http.Request, modifier func(*
return rm
}
// WriteHeader is, in the specific case of 1xx status codes, a direct call to the wrapped ResponseWriter, without marking headers as sent,
// allowing so further calls.
func (r *responseModifier) WriteHeader(code int) {
if r.headersSent {
return
}
// Handling informational headers.
if code >= 100 && code <= 199 {
r.rw.WriteHeader(code)
return
}
defer func() {
r.code = code
r.headersSent = true