Skip to content

net/http: guarantee that the Transport dial functions are respected in js/wasm #46923

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

Closed

Conversation

neilalexander
Copy link
Contributor

The net/http package has a documented contract that if DialContext, DialDLSContext, Dial or DialTLS are specified in an instance of Transport, that they will be used to set up the connection. If they are not specified, then a reasonable fallback is made (e.g. using the net package).

This is ordinarily true, except for when compiling for the js/wasm target, where the browser's Fetch API is preferred in all cases (except for when it is undefined/unavailable) and therefore the dial functions are all ignored. As a result, the http.Transport implementation under js/wasm doesn't meet that contract.

This PR updates the RoundTrip behaviour of http.Transport so that if DialContext, DialTLSContext, Dial or DialTLS are specified, they are used as expected. The Fetch API will be used as a fallback if they are not specified.

Fixes #27495

…ext, Dial and DialTLS functions in http.Transport are respected, even under JS/WASM

There aren't any particular assumptions that state that the net.Conn has to be an actual socket, but instead might be a kind of virtual network or connection handler. The current API shape tries to use the Fetch API for everything, even when we've tried to tell the Transport not to.
@google-cla
Copy link

google-cla bot commented Jun 25, 2021

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@google-cla google-cla bot added the cla: no Used by googlebot to label PRs as having an invalid CLA. The text of this label should not change. label Jun 25, 2021
@neilalexander
Copy link
Contributor Author

@googlebot I signed it!

@google-cla google-cla bot added cla: yes Used by googlebot to label PRs as having a valid CLA. The text of this label should not change. and removed cla: no Used by googlebot to label PRs as having an invalid CLA. The text of this label should not change. labels Jun 25, 2021
@gopherbot
Copy link
Contributor

This PR (HEAD: 76ce48b) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/go/+/330852 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link
Contributor

Message from Go Bot:

Patch Set 1:

Congratulations on opening your first change. Thank you for your contribution!

Next steps:
A maintainer will review your change and provide feedback. See
https://golang.org/doc/contribute.html#review for more info and tips to get your
patch through code review.

Most changes in the Go project go through a few rounds of revision. This can be
surprising to people new to the project. The careful, iterative review process
is our way of helping mentor contributors and ensuring that their contributions
have a lasting impact.

During May-July and Nov-Jan the Go project is in a code freeze, during which
little code gets reviewed or merged. If a reviewer responds with a comment like
R=go1.11 or adds a tag like "wait-release", it means that this CL will be
reviewed as part of the next development cycle. See https://golang.org/s/release
for more details.


Please don’t reply on this GitHub thread. Visit golang.org/cl/330852.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

This PR (HEAD: 01b6836) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/go/+/330852 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link
Contributor

This PR (HEAD: 911ba26) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/go/+/330852 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link
Contributor

Message from Damien Neil:

Patch Set 3:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/330852.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Neil Alexander:

Patch Set 3:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/330852.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

This PR (HEAD: 23ee196) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/go/+/330852 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link
Contributor

Message from Neil Alexander:

Patch Set 4:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/330852.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Damien Neil:

Patch Set 4:

(2 comments)


Please don’t reply on this GitHub thread. Visit golang.org/cl/330852.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

This PR (HEAD: 0ac1456) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/go/+/330852 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link
Contributor

Message from Neil Alexander:

Patch Set 5:

(3 comments)


Please don’t reply on this GitHub thread. Visit golang.org/cl/330852.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Damien Neil:

Patch Set 5:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/330852.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

This PR (HEAD: 948a0ed) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/go/+/330852 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link
Contributor

Message from Neil Alexander:

Patch Set 6:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/330852.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Damien Neil:

Patch Set 6: Code-Review+2


Please don’t reply on this GitHub thread. Visit golang.org/cl/330852.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Damien Neil:

Patch Set 6: Run-TryBot+1 Trust+1


Please don’t reply on this GitHub thread. Visit golang.org/cl/330852.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Go Bot:

Patch Set 6:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/330852.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Go Bot:

Patch Set 6: TryBot-Result+1

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/330852.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Carlos Amedee:

Patch Set 6: Trust+1


Please don’t reply on this GitHub thread. Visit golang.org/cl/330852.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Richard Musiol:

Patch Set 6:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/330852.
After addressing review feedback, remember to publish your drafts!

gopherbot pushed a commit that referenced this pull request Oct 28, 2021
…n js/wasm

The net/http package has a documented contract that if DialContext, DialDLSContext, Dial or DialTLS are specified in an instance of Transport, that they will be used to set up the connection. If they are not specified, then a reasonable fallback is made (e.g. using the net package).

This is ordinarily true, except for when compiling for the js/wasm target, where the browser's Fetch API is preferred in all cases (except for when it is undefined/unavailable) and therefore the dial functions are all ignored. As a result, the http.Transport implementation under js/wasm doesn't meet that contract.

This PR updates the RoundTrip behaviour of http.Transport so that if DialContext, DialTLSContext, Dial or DialTLS are specified, they are used as expected. The Fetch API will be used as a fallback if they are not specified.

Fixes #27495

Change-Id: I88c6eb6ffdd077827b421d606f3e60ebdafd538f
GitHub-Last-Rev: 948a0ed
GitHub-Pull-Request: #46923
Reviewed-on: https://go-review.googlesource.com/c/go/+/330852
Reviewed-by: Damien Neil <[email protected]>
Trust: Damien Neil <[email protected]>
Trust: Carlos Amedee <[email protected]>
Run-TryBot: Damien Neil <[email protected]>
TryBot-Result: Go Bot <[email protected]>
@gopherbot
Copy link
Contributor

This PR is being closed because golang.org/cl/330852 has been merged.

@gopherbot gopherbot closed this Oct 28, 2021
neilalexander added a commit to neilalexander/go that referenced this pull request Nov 1, 2021
This PR adds a note into the Go 1.18 changelog for CL330852 / golang#46923.
gopherbot pushed a commit that referenced this pull request Nov 11, 2021
This PR adds a note into the Go 1.18 changelog for CL 330852.

Updates #46923.

Change-Id: I99150e9275ce23fcf3697d6a22ac216818223c74
GitHub-Last-Rev: b2772ce
GitHub-Pull-Request: #49258
Reviewed-on: https://go-review.googlesource.com/c/go/+/360297
Trust: Roland Shoemaker <[email protected]>
Reviewed-by: Dmitri Shuralyov <[email protected]>
e-nikolov pushed a commit to e-nikolov/json that referenced this pull request Nov 25, 2021
…n js/wasm

The net/http package has a documented contract that if DialContext, DialDLSContext, Dial or DialTLS are specified in an instance of Transport, that they will be used to set up the connection. If they are not specified, then a reasonable fallback is made (e.g. using the net package).

This is ordinarily true, except for when compiling for the js/wasm target, where the browser's Fetch API is preferred in all cases (except for when it is undefined/unavailable) and therefore the dial functions are all ignored. As a result, the http.Transport implementation under js/wasm doesn't meet that contract.

This PR updates the RoundTrip behaviour of http.Transport so that if DialContext, DialTLSContext, Dial or DialTLS are specified, they are used as expected. The Fetch API will be used as a fallback if they are not specified.

Fixes #27495

Change-Id: I88c6eb6ffdd077827b421d606f3e60ebdafd538f
GitHub-Last-Rev: 948a0ed97ec4661f03cd346335f1d3d180f4c1ae
GitHub-Pull-Request: golang/go#46923
Reviewed-on: https://go-review.googlesource.com/c/go/+/330852
Reviewed-by: Damien Neil <[email protected]>
Trust: Damien Neil <[email protected]>
Trust: Carlos Amedee <[email protected]>
Run-TryBot: Damien Neil <[email protected]>
TryBot-Result: Go Bot <[email protected]>
e-nikolov pushed a commit to e-nikolov/json that referenced this pull request Nov 25, 2021
…n js/wasm

The net/http package has a documented contract that if DialContext, DialDLSContext, Dial or DialTLS are specified in an instance of Transport, that they will be used to set up the connection. If they are not specified, then a reasonable fallback is made (e.g. using the net package).

This is ordinarily true, except for when compiling for the js/wasm target, where the browser's Fetch API is preferred in all cases (except for when it is undefined/unavailable) and therefore the dial functions are all ignored. As a result, the http.Transport implementation under js/wasm doesn't meet that contract.

This PR updates the RoundTrip behaviour of http.Transport so that if DialContext, DialTLSContext, Dial or DialTLS are specified, they are used as expected. The Fetch API will be used as a fallback if they are not specified.

Fixes #27495

Change-Id: I88c6eb6ffdd077827b421d606f3e60ebdafd538f
GitHub-Last-Rev: 948a0ed97ec4661f03cd346335f1d3d180f4c1ae
GitHub-Pull-Request: golang/go#46923
Reviewed-on: https://go-review.googlesource.com/c/go/+/330852
Reviewed-by: Damien Neil <[email protected]>
Trust: Damien Neil <[email protected]>
Trust: Carlos Amedee <[email protected]>
Run-TryBot: Damien Neil <[email protected]>
TryBot-Result: Go Bot <[email protected]>
e-nikolov pushed a commit to e-nikolov/json that referenced this pull request Nov 25, 2021
…n js/wasm

The net/http package has a documented contract that if DialContext, DialDLSContext, Dial or DialTLS are specified in an instance of Transport, that they will be used to set up the connection. If they are not specified, then a reasonable fallback is made (e.g. using the net package).

This is ordinarily true, except for when compiling for the js/wasm target, where the browser's Fetch API is preferred in all cases (except for when it is undefined/unavailable) and therefore the dial functions are all ignored. As a result, the http.Transport implementation under js/wasm doesn't meet that contract.

This PR updates the RoundTrip behaviour of http.Transport so that if DialContext, DialTLSContext, Dial or DialTLS are specified, they are used as expected. The Fetch API will be used as a fallback if they are not specified.

Fixes #27495

Change-Id: I88c6eb6ffdd077827b421d606f3e60ebdafd538f
GitHub-Last-Rev: 948a0ed97ec4661f03cd346335f1d3d180f4c1ae
GitHub-Pull-Request: golang/go#46923
Reviewed-on: https://go-review.googlesource.com/c/go/+/330852
Reviewed-by: Damien Neil <[email protected]>
Trust: Damien Neil <[email protected]>
Trust: Carlos Amedee <[email protected]>
Run-TryBot: Damien Neil <[email protected]>
TryBot-Result: Go Bot <[email protected]>
bassosimone pushed a commit to ooni/oohttp that referenced this pull request May 21, 2022
…n js/wasm

The net/http package has a documented contract that if DialContext, DialDLSContext, Dial or DialTLS are specified in an instance of Transport, that they will be used to set up the connection. If they are not specified, then a reasonable fallback is made (e.g. using the net package).

This is ordinarily true, except for when compiling for the js/wasm target, where the browser's Fetch API is preferred in all cases (except for when it is undefined/unavailable) and therefore the dial functions are all ignored. As a result, the http.Transport implementation under js/wasm doesn't meet that contract.

This PR updates the RoundTrip behaviour of http.Transport so that if DialContext, DialTLSContext, Dial or DialTLS are specified, they are used as expected. The Fetch API will be used as a fallback if they are not specified.

Fixes #27495

Change-Id: I88c6eb6ffdd077827b421d606f3e60ebdafd538f
GitHub-Last-Rev: 948a0ed97ec4661f03cd346335f1d3d180f4c1ae
GitHub-Pull-Request: golang/go#46923
Reviewed-on: https://go-review.googlesource.com/c/go/+/330852
Reviewed-by: Damien Neil <[email protected]>
Trust: Damien Neil <[email protected]>
Trust: Carlos Amedee <[email protected]>
Run-TryBot: Damien Neil <[email protected]>
TryBot-Result: Go Bot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Used by googlebot to label PRs as having a valid CLA. The text of this label should not change.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

net/http: Expose the normal transport RoundTripper for WASM/js
2 participants