Skip to content

Commit 42b2029

Browse files
0x5457neild
authored andcommitted
net/http: remove Content-Encoding header in roundtrip_js
The fetch api will decode the gzip, but Content-Encoding not be deleted. To ensure that the behavior of roundtrip_js is consistent with native. delete the Content-Encoding header when the response body is decompressed by js fetch api. Fixes golang#63139 Change-Id: Ie35b3aa050786e2ef865f9ffa992e30ab060506e Reviewed-on: https://go-review.googlesource.com/c/go/+/530155 Commit-Queue: Damien Neil <[email protected]> Reviewed-by: Bryan Mills <[email protected]> Reviewed-by: Damien Neil <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Damien Neil <[email protected]>
1 parent f83bbaf commit 42b2029

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/net/http/roundtrip_js.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"errors"
1111
"fmt"
1212
"io"
13+
"net/http/internal/ascii"
1314
"strconv"
1415
"strings"
1516
"syscall/js"
@@ -184,11 +185,22 @@ func (t *Transport) RoundTrip(req *Request) (*Response, error) {
184185
}
185186

186187
code := result.Get("status").Int()
188+
189+
uncompressed := false
190+
if ascii.EqualFold(header.Get("Content-Encoding"), "gzip") {
191+
// The fetch api will decode the gzip, but Content-Encoding not be deleted.
192+
header.Del("Content-Encoding")
193+
header.Del("Content-Length")
194+
contentLength = -1
195+
uncompressed = true
196+
}
197+
187198
respCh <- &Response{
188199
Status: fmt.Sprintf("%d %s", code, StatusText(code)),
189200
StatusCode: code,
190201
Header: header,
191202
ContentLength: contentLength,
203+
Uncompressed: uncompressed,
192204
Body: body,
193205
Request: req,
194206
}

0 commit comments

Comments
 (0)