net/http: dispatch the client through its RoundTripper (fetch on js/wasm) - #83
net/http: dispatch the client through its RoundTripper (fetch on js/wasm)#830pcom wants to merge 1 commit into
Conversation
The client called the package-level dialing roundTrip directly, so a Client with no explicit Transport never reached the build-tagged Transport.RoundTrip — on js/wasm every request died with "Netdev not set" instead of using the fetch API (tinygo-org#66). Client.Do also short-circuited an explicit Transport past the cookie jar, header initialization, and timeout handling. send now takes a RoundTripper, Client.transport() falls back to DefaultTransport as documented, and Do always goes through do/send. The netdev path is unchanged: on !js targets DefaultTransport.RoundTrip is the same package-level roundTrip as before. Verified on js/wasm under node: http.Get with a nil Transport now reaches the fetch transport (its no-fetch-API report) instead of "Netdev not set".
|
This overlaps the redirect loop in #72. I checked a Git merge of e12bf8a and your 13d50d3 and found a conflict in http/client.go. The combined client must retain redirects and sensitive-header rules while routing each request through the selected RoundTripper. Default and explicit transports should both exercise redirects and cookie handling. I have kept the tested fork candidate unchanged and have not opened a duplicate PR or changed your branch. |
|
Agreed the two must compose, so the composition is now built and tested rather than argued: main...0magnet:net:client-transport-dispatch-72 is your e12bf8a with this PR's commit rebased on top. The conflict resolves one way that makes sense: The combined branch also adds the coverage you named: a redirecting fake Proposed order: #72 lands first — it is older and carries the bulk — and this PR then rebases to the combined branch above, which is ready to fast-forward. If a maintainer merges this one first instead, the same resolution applies from the other side and either of us can push it. |
Fixes #66.
A
Clientwith no explicitTransportcalled the package-level dialingroundTripdirectly, so the build-taggedTransport.RoundTripwas never consulted — on js/wasm every request died withNetdev not setinstead of using the fetch API.Client.Doalso short-circuited an explicitTransportpast the cookie jar, header initialization, and timeout handling.This restores the upstream shape:
sendtakes aRoundTripperClient.transport()falls back toDefaultTransport, as its docs already promisedDoalways goes throughdo/send, so an explicitTransportgets cookies and timeouts tooTransportand nilDefaultTransportreportshttp: no Client.Transport or DefaultTransportlike upstreamThe netdev path is unchanged: on
!jstargetsDefaultTransport.RoundTrip(roundtrip.go) is the same package-levelroundTripas before.Tests: three unit tests cover default dispatch, explicit dispatch, and the nil/nil error. Verified behaviorally on js/wasm under node —
http.Getwith a nil Transport now reaches the fetch transport (it reports its own no-fetch-API fallback error under node, as upstream Go does) instead ofNetdev not set.