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: Expose the normal transport RoundTripper for WASM/js #27495

antong opened this Issue Sep 4, 2018 · 4 comments


None yet
4 participants

antong commented Sep 4, 2018

On WASM, the standard http.Transfer RoundTripper is not exposed for external use. Buildflags for wasm replace the standard implementation of RoundTripper with a special version that uses the browser Fetch API. The special JS RoundTripper does not seem to use or honor any of the documented settings provided by http.Transport, such as Dial or DialContext. But the way the special JS RoundTripper is implemented as methods on http.Transport, it prevents using the standard RoundTripper.

There are use cases for using the normal RoundTripper, for instance for testing and simulation in the browser. The normal RoundTripper is compiled and included in the binary anyway, and works perfectly well, but is masked by the browser version.

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


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


What did you do?

I tried to configure a http.Client to use a transport with a custom dial function:

This works on all other platforms including the playground, but on WASM, the same, special Roundtripper is always used and there is no way to use the standard Roundtripper.

What did you expect to see?

Get expected error, all ok

What did you see instead?


On other platforms, I get the expected result


This comment has been minimized.


andybons commented Sep 4, 2018


This comment has been minimized.


antong commented Sep 4, 2018

I quickly tested two hacks to do this, and both seemed to work. Both pass the tests on normal platforms, but I don't know how to run the unit tests on WASM.

Hack 1: Don't implement the special RoundTripper on http.Transport, but make an own jsTransport. Set an instance of this as http.DefaultTransport for GOARCH=wasm. Example: e8050da

Hack 2: Mod the special RoundTripper to instead use the normal RoundTripper if the caller has set options on the Transport. Example: 8137bf5


This comment has been minimized.


agnivade commented Sep 4, 2018


This comment has been minimized.


dmitshur commented Sep 4, 2018

This is also related to #25695.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment