encode: don't WriteHeader unless called (#5060)

This commit is contained in:
WeidiDeng 2022-09-21 22:30:42 +08:00 committed by GitHub
parent beb7dcbf2a
commit 44ad0cedaf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -241,8 +241,6 @@ func (rw *responseWriter) Write(p []byte) (int, error) {
if !rw.wroteHeader {
if rw.statusCode != 0 {
rw.HTTPInterfaces.WriteHeader(rw.statusCode)
} else {
rw.HTTPInterfaces.WriteHeader(http.StatusOK)
}
rw.wroteHeader = true
}
@ -264,10 +262,9 @@ func (rw *responseWriter) Close() error {
rw.init()
}
// issue #5059, don't write status code if not set explicitly.
if rw.statusCode != 0 {
rw.HTTPInterfaces.WriteHeader(rw.statusCode)
} else {
rw.HTTPInterfaces.WriteHeader(http.StatusOK)
}
rw.wroteHeader = true
}