trace: Print either Transfer-Encoding or Content-Length (#8314)

If Transfer-Encoding is set client would have
never set Content-Length as its considered
malformed HTTP request
This commit is contained in:
Harshavardhana 2019-09-27 10:19:27 -07:00 committed by GitHub
parent f3022e891d
commit 4155f4e49b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -100,8 +100,10 @@ func Trace(f http.HandlerFunc, logBody bool, w http.ResponseWriter, r *http.Requ
// Setup a http request body recorder
reqHeaders := r.Header.Clone()
reqHeaders.Set("Content-Length", strconv.Itoa(int(r.ContentLength)))
reqHeaders.Set("Host", r.Host)
if len(r.TransferEncoding) == 0 {
reqHeaders.Set("Content-Length", strconv.Itoa(int(r.ContentLength)))
}
for _, enc := range r.TransferEncoding {
reqHeaders.Add("Transfer-Encoding", enc)
}