Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/http: GET request with http.NoBody fails on js/wasm #36339

Open
tarndt opened this issue Dec 31, 2019 · 4 comments
Open

net/http: GET request with http.NoBody fails on js/wasm #36339

tarndt opened this issue Dec 31, 2019 · 4 comments
Assignees

Comments

@tarndt
Copy link

@tarndt tarndt commented Dec 31, 2019

What version of Go are you using (go version)?

$ go version
go version go1.13.4 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
GOARCH=wasm GOOS=js running on Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:71.0) Gecko/20100101 Firefox/71.0

What did you do?

I executed code that makes a HTTP GET request using net/http facilities and it failed with the following error:

Fail:  Get https://localhost:8443/v1/endpoint: net/http: fetch() failed: <object>

I then added js.Global().Get("console").Call("log", args[0]) on line 160 of roundtrip_js.go and observed:

TypeError: "HEAD or GET Request cannot have a body."
    valueCall https://localhost:8443/wasm_exec.js:327
    run https://localhost:8443/wasm_exec.js:475
    <anonymous> https://localhost:8443/:9

I then changed the body of the request created from http.NoBody to nil and observed a successful request being made:

  • Fails: req, err := http.NewRequest(http.MethodGet, URL, http.NoBody)
  • Succeeds: req, err := http.NewRequest(http.MethodGet, URL, nil)

P.S. In roundtrip_js.go and the similar stdlib JavaScript platform code, if existing error reporting code such as:

err := fmt.Errorf("net/http: fetch() failed: %s", args[0].String())

is replaced with:

err := fmt.Errorf("net/http: fetch() failed: %s", js.Error{args[0]})

the output changes from:

net/http: fetch() failed: <object>

To

net/http: fetch() failed: JavaScript error: HEAD or GET Request cannot have a body.

which is substantially more helpful and perhaps warrants another issue. 😸

What did you expect to see?

Success. I expect nil and http.NoBody to function identically with respect to client `*http.Request``'s.

What did you see instead?

Failure, GET requests under GOARCH=wasm GOOS=js fail when the request body is http.NoBody rather than nil.

@smasher164 smasher164 changed the title Use of http.NoBody results in GET request failure under js/wasm net/http: GET request with http.NoBody fails on js/wasm Dec 31, 2019
@agnivade
Copy link
Contributor

@agnivade agnivade commented May 1, 2020

@agnivade agnivade closed this May 1, 2020
@tarndt
Copy link
Author

@tarndt tarndt commented Jun 12, 2020

@agnivade I see the logging was improved, but that diff does look to make any changes that would fix request with http.NoBody from failing when nil succeeds (the primary issue). Was that changed in another diff?

@agnivade
Copy link
Contributor

@agnivade agnivade commented Jun 13, 2020

Oh my apologies, I somehow thought that the issue was about logging. Reopening.

@agnivade agnivade reopened this Jun 13, 2020
@agnivade agnivade self-assigned this Jun 13, 2020
@gopherbot
Copy link

@gopherbot gopherbot commented Jun 13, 2020

Change https://golang.org/cl/237758 mentions this issue: net/http: avoid setting body when NoBody is set for js/wasm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.