Closed
Description
Hi, would it be good if I submit the following diff file?
It basically treats x-gzip as gzip, as noted in the HTTP 0.9 RFC: https://www.ietf.org/rfc/rfc1945.txt section 3.5
For the request header, that may not be that important, but for the response it may save more than one response from legacy servers.
@@ -2012,7 +2012,8 @@ func (pc *persistConn) readLoop() {
}
resp.Body = body
- if rc.addedGzip && strings.EqualFold(resp.Header.Get("Content-Encoding"), "gzip") {
+ if rc.addedGzip && (strings.EqualFold(resp.Header.Get("Content-Encoding"), "gzip") ||
+ strings.EqualFold(resp.Header.Get("Content-Encoding"), "x-gzip")) {
resp.Body = &gzipReader{body: body}
resp.Header.Del("Content-Encoding")
resp.Header.Del("Content-Length")
@@ -2368,9 +2369,9 @@ func (pc *persistConn) roundTrip(req *transportRequest) (resp *Response, err err
// requested it.
requestedGzip := false
if !pc.t.DisableCompression &&
- req.Header.Get("Accept-Encoding") == "" &&
req.Header.Get("Range") == "" &&
req.Method != "HEAD" {
+
// Request gzip only, not deflate. Deflate is ambiguous and
// not as universally supported anyway.
// See: https://zlib.net/zlib_faq.html#faq39
@@ -2383,8 +2384,14 @@ func (pc *persistConn) roundTrip(req *transportRequest) (resp *Response, err err
// We don't request gzip if the request is for a range, since
// auto-decoding a portion of a gzipped document will just fail
// anyway. See https://golang.org/issue/8923
- requestedGzip = true
- req.extraHeaders().Set("Accept-Encoding", "gzip")
+ if req.Header.Get("Accept-Encoding") == "" || req.Header.Get("Accept-Encoding") == "gzip" {
+ requestedGzip = true
+ req.extraHeaders().Set("Accept-Encoding", "gzip")
+ } else if req.Header.Get("Accept-Encoding") == "x-gzip" {
+ requestedGzip = true
+ req.extraHeaders().Set("Accept-Encoding", "x-gzip")
+ }
+
}
var continueCh chan struct{}