mirror of
https://github.com/minio/minio.git
synced 2025-01-11 23:13:23 -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 {
|
if !lrw.headersLogged {
|
||||||
// We assume the response code to be '200 OK' when WriteHeader() is not called,
|
// We assume the response code to be '200 OK' when WriteHeader() is not called,
|
||||||
// that way following Golang HTTP response behavior.
|
// that way following Golang HTTP response behavior.
|
||||||
lrw.writeHeaders(&lrw.headers, http.StatusOK, lrw.Header())
|
lrw.WriteHeader(http.StatusOK)
|
||||||
lrw.headersLogged = true
|
|
||||||
}
|
}
|
||||||
if (lrw.LogErrBody && lrw.StatusCode >= http.StatusBadRequest) || lrw.LogAllBody {
|
if (lrw.LogErrBody && lrw.StatusCode >= http.StatusBadRequest) || lrw.LogAllBody {
|
||||||
// Always logging error responses.
|
// Always logging error responses.
|
||||||
@ -107,12 +106,12 @@ func (lrw *ResponseWriter) Body() []byte {
|
|||||||
|
|
||||||
// WriteHeader - writes http status code
|
// WriteHeader - writes http status code
|
||||||
func (lrw *ResponseWriter) WriteHeader(code int) {
|
func (lrw *ResponseWriter) WriteHeader(code int) {
|
||||||
lrw.StatusCode = code
|
|
||||||
if !lrw.headersLogged {
|
if !lrw.headersLogged {
|
||||||
|
lrw.StatusCode = code
|
||||||
lrw.writeHeaders(&lrw.headers, code, lrw.ResponseWriter.Header())
|
lrw.writeHeaders(&lrw.headers, code, lrw.ResponseWriter.Header())
|
||||||
lrw.headersLogged = true
|
lrw.headersLogged = true
|
||||||
|
lrw.ResponseWriter.WriteHeader(code)
|
||||||
}
|
}
|
||||||
lrw.ResponseWriter.WriteHeader(code)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Flush - Calls the underlying Flush.
|
// Flush - Calls the underlying Flush.
|
||||||
|
Loading…
Reference in New Issue
Block a user