]> Cypherpunks.ru repositories - gostls13.git/commitdiff
net/http: avoid setting body when NoBody is set for js/wasm
authorAgniva De Sarker <agnivade@yahoo.co.in>
Sat, 13 Jun 2020 05:07:22 +0000 (10:37 +0530)
committerAgniva De Sarker <agniva.quicksilver@gmail.com>
Sat, 15 Aug 2020 15:29:33 +0000 (15:29 +0000)
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 <agniva.quicksilver@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Johan Brandhorst <johan.brandhorst@gmail.com>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
src/net/http/roundtrip_js.go

index 509d229aadae73448143caa6a60c4a88c10e2fc7..b09923c38601bd5ffe814a4b9c2ce733caf20bf0 100644 (file)
@@ -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)