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 #63139
Change-Id: Ie35b3aa050786e2ef865f9ffa992e30ab060506e
Reviewed-on: https://go-review.googlesource.com/c/go/+/530155
Commit-Queue: Damien Neil <dneil@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Damien Neil <dneil@google.com>
"errors"
"fmt"
"io"
+ "net/http/internal/ascii"
"strconv"
"strings"
"syscall/js"
}
code := result.Get("status").Int()
+
+ uncompressed := false
+ if ascii.EqualFold(header.Get("Content-Encoding"), "gzip") {
+ // The fetch api will decode the gzip, but Content-Encoding not be deleted.
+ header.Del("Content-Encoding")
+ header.Del("Content-Length")
+ contentLength = -1
+ uncompressed = true
+ }
+
respCh <- &Response{
Status: fmt.Sprintf("%d %s", code, StatusText(code)),
StatusCode: code,
Header: header,
ContentLength: contentLength,
+ Uncompressed: uncompressed,
Body: body,
Request: req,
}