From b6ad2880323191713a5525bae5eb27d62c1d1c35 Mon Sep 17 00:00:00 2001 From: Agniva De Sarker Date: Sat, 13 Jun 2020 10:37:22 +0530 Subject: [PATCH] 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 --- src/net/http/roundtrip_js.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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) -- 2.50.0