mirror of
https://github.com/minio/minio.git
synced 2024-12-24 06:05:55 -05:00
Avoid logging the body of the http 206 response (#6258)
When an S3 client issues a GET request with range specified, Minio server returns some partial data with 206 http code. The latter is sent in MINIO_HTTP_TRACE output which is incorrect. This PR fixes the issue.
This commit is contained in:
parent
98bce72295
commit
6df20734f9
@ -91,20 +91,15 @@ func (r *recordResponseWriter) WriteHeader(i int) {
|
||||
|
||||
func (r *recordResponseWriter) Write(p []byte) (n int, err error) {
|
||||
n, err = r.ResponseWriter.Write(p)
|
||||
// We log after calling ResponseWriter.Write() because this latter
|
||||
// proactively prepares headers when WriteHeader is not called yet.
|
||||
if !r.headersLogged {
|
||||
// We assume the response code to be '200 OK' when WriteHeader() is not called,
|
||||
// that way following Golang HTTP response behavior.
|
||||
writeHeaders(&r.headers, http.StatusOK, r.ResponseWriter.Header())
|
||||
r.headersLogged = true
|
||||
}
|
||||
if r.statusCode != http.StatusOK && r.statusCode != http.StatusNoContent && r.statusCode != 0 {
|
||||
// We always log error responses.
|
||||
if (r.statusCode != http.StatusOK && r.statusCode != http.StatusPartialContent && r.statusCode != 0) || r.logBody {
|
||||
// Always logging error responses.
|
||||
r.body.Write(p)
|
||||
return
|
||||
}
|
||||
if r.logBody {
|
||||
r.body.Write(p)
|
||||
return
|
||||
}
|
||||
return n, err
|
||||
}
|
||||
@ -180,6 +175,10 @@ func TraceReqHandlerFunc(f http.HandlerFunc, output io.Writer, logBody bool) htt
|
||||
|
||||
b.Write(respBodyRecorder.Headers())
|
||||
fmt.Fprintf(b, "\n")
|
||||
|
||||
// recordResponseWriter{} is configured to record only
|
||||
// responses with http code != 200 & != 206, we don't
|
||||
// have to check for logBody value here.
|
||||
bodyContents := respBodyRecorder.Body()
|
||||
if bodyContents != nil {
|
||||
b.Write(bodyContents)
|
||||
|
Loading…
Reference in New Issue
Block a user