Prevents superfluous WriteHeader call in the error middleware

Co-authored-by: LandryBe <lbenguigui@gmail.com>
This commit is contained in:
Tom Moulard 2023-01-02 17:00:05 +01:00 committed by GitHub
parent b9a175f5c2
commit e1e86763e3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 2 deletions

View file

@ -233,6 +233,15 @@ func (cc *codeCatcher) Flush() {
// Otherwise, cc.code is actually a 200 here.
cc.WriteHeader(cc.code)
// We don't care about the contents of the response,
// since we want to serve the ones from the error page,
// so we just don't flush.
// (e.g., To prevent superfluous WriteHeader on request with a
// `Transfert-Encoding: chunked` header).
if cc.caughtFilteredCode {
return
}
if flusher, ok := cc.responseWriter.(http.Flusher); ok {
flusher.Flush()
}