From: Agniva De Sarker Date: Sat, 13 Jun 2020 05:07:22 +0000 (+0530) Subject: net/http: avoid setting body when NoBody is set for js/wasm X-Git-Tag: go1.16beta1~1349 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=b6ad2880323191713a5525bae5eb27d62c1d1c35;p=gostls13.git net/http: avoid setting body when NoBody is set for js/wasm When http.NoBody is set, it is equivalent to Body being zero bytes. We therefore set the body only if it is of length greater than 0. Manually verified with wasmbrowsertest. Fixes #36339 Change-Id: I9c108c38f99409f72ea101819af572429505a8ad Reviewed-on: https://go-review.googlesource.com/c/go/+/237758 Run-TryBot: Agniva De Sarker TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick Reviewed-by: Johan Brandhorst Reviewed-by: Emmanuel Odeke --- diff --git a/src/net/http/roundtrip_js.go b/src/net/http/roundtrip_js.go index 509d229aad..b09923c386 100644 --- a/src/net/http/roundtrip_js.go +++ b/src/net/http/roundtrip_js.go @@ -98,9 +98,11 @@ func (t *Transport) RoundTrip(req *Request) (*Response, error) { return nil, err } req.Body.Close() - buf := uint8Array.New(len(body)) - js.CopyBytesToJS(buf, body) - opt.Set("body", buf) + if len(body) != 0 { + buf := uint8Array.New(len(body)) + js.CopyBytesToJS(buf, body) + opt.Set("body", buf) + } } fetchPromise := js.Global().Call("fetch", req.URL.String(), opt)