mirror of
https://github.com/minio/minio.git
synced 2024-12-24 06:05:55 -05:00
logger: avoid writing audit log response header twice (#10642)
This commit fixes a misuse of the `http.ResponseWriter.WriteHeader`. A caller should **either** call `WriteHeader` exactly once **or** write to the response writer and causing an implicit 200 OK. Writing the response headers more than once causes a `http: superfluous response.WriteHeader call` log message. This commit fixes this by preventing a 2nd `WriteHeader` call being forwarded to the underlying `ResponseWriter`. Updates #10587
This commit is contained in:
parent
effe131090
commit
ed6d2a100f
@ -68,8 +68,7 @@ func (lrw *ResponseWriter) Write(p []byte) (int, error) {
|
||||
if !lrw.headersLogged {
|
||||
// We assume the response code to be '200 OK' when WriteHeader() is not called,
|
||||
// that way following Golang HTTP response behavior.
|
||||
lrw.writeHeaders(&lrw.headers, http.StatusOK, lrw.Header())
|
||||
lrw.headersLogged = true
|
||||
lrw.WriteHeader(http.StatusOK)
|
||||
}
|
||||
if (lrw.LogErrBody && lrw.StatusCode >= http.StatusBadRequest) || lrw.LogAllBody {
|
||||
// Always logging error responses.
|
||||
@ -107,12 +106,12 @@ func (lrw *ResponseWriter) Body() []byte {
|
||||
|
||||
// WriteHeader - writes http status code
|
||||
func (lrw *ResponseWriter) WriteHeader(code int) {
|
||||
lrw.StatusCode = code
|
||||
if !lrw.headersLogged {
|
||||
lrw.StatusCode = code
|
||||
lrw.writeHeaders(&lrw.headers, code, lrw.ResponseWriter.Header())
|
||||
lrw.headersLogged = true
|
||||
lrw.ResponseWriter.WriteHeader(code)
|
||||
}
|
||||
lrw.ResponseWriter.WriteHeader(code)
|
||||
}
|
||||
|
||||
// Flush - Calls the underlying Flush.
|
||||
|
Loading…
Reference in New Issue
Block a user