net/http: follow redirects in the client again - #72
Open
yohimik wants to merge 1 commit into
Open
Conversation
The client keeps CheckRedirect and ErrUseLastResponse, but Client.do lost its redirect loop, so a 3xx went straight back to the caller with an unread body. A request for a GitHub release asset returned 302 and zero bytes where Go returns 200 and the file. Port the loop of Go back. It makes up to 10 hops through checkRedirect and defaultCheckRedirect, has redirectBehavior for the 301, 302 and 303 change to GET and for the 307 and 308 replay with GetBody, resolves Location against the URL of the current request, drops sensitive headers when a hop leaves the initial domain, reads and closes an intermediate body, and honours ErrUseLastResponse. The port makes two changes. shouldCopyHeaderOnRedirect compares the hostnames as they are and not through idnaASCII, so the Unicode and the punycode spelling of one IDN host count as two hosts. And roundTrip uses Request.URL.Host when Request.Host is empty, because only NewRequest fills Request.Host and a redirect hop builds its request directly.
This was referenced Aug 30, 2026
Author
|
tinygo-org/net main has not moved since this branch was opened. It is still |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
net/http: follow redirects in the client again
Repository tinygo-org/net. Branch
upstream-pr/http-redirects, basemain.What this does
The client keeps
CheckRedirectandErrUseLastResponse, butClient.dolostits redirect loop, so a 3xx went straight back to the caller with an unread
body. A request for a GitHub release asset returned 302 and zero bytes where Go
returns 200 and the file.
This ports the loop of Go back into
http/client.go. It hascheckRedirectanddefaultCheckRedirect,redirectBehaviorwith the 301, 302 and 303 change to GET and the 307 and 308replay with
GetBody,Locationresolved against the URL of the current request,ErrUseLastResponsehonoured,refererForURLwith the https to http rule.The code follows the upstream Go source, with its comments, so a later update
from upstream is a straight comparison.
Two changes from upstream
shouldCopyHeaderOnRedirectcompares the hostnames as they are and notthrough
idnaASCII, which needsgolang.org/x/net/idnaand its tables. TheUnicode and the punycode spelling of one IDN host thus count as two hosts and
lose their sensitive headers. That is the safe direction. The rule for a
subdomain is the upstream one.
roundTripusesRequest.URL.HostwhenRequest.Hostis empty, because onlyNewRequestfillsRequest.Hostand a redirect hop builds its requestdirectly.
Evidence
There is no CI in this repository. Checked by hand on macOS 26.6 arm64 with a
TinyGo build that carries the matching toolchain change.
http.Get("https://example.com/")builds and completes.A downstream product ships binaries built with these changes in a production
release. dispat v1.4.0 is published and is not a prerelease. It carries
dispat-tiny-linux-amd64anddispat-tiny-linux-arm64, built by the forkrelease v0.42.0-net.4 from sha256-pinned tarballs and smoke-executed under
binfmt before upload, beside six binaries from the gc toolchain.
https://github.com/yohimik/dispat/releases/tag/services%2Fdispat%2Fv1.4.0
The acceptance record of that repository is committed at
packages/docs/docs/internals/tinygo.md. It reports the net.2 to net.4acceptance history, an integration suite of 694 rows that passes with 0 failures
and 1 documented skip on darwin, and a size table of 0.58x to 0.63x against the
gc equivalents with TinyGo
-opt=z -no-debugagainstgo build -trimpath -ldflags "-s -w". Those figures come from that document. They are not ameasurement of this branch.
The self-update path of that program downloads a release asset over HTTPS, which
is the redirect case above.
Scope
http/client.go. No API change.linux as it stands.
Known gaps
http.Client.Timeoutis still inert in this port. The loop does not add adeadline of its own. That is a separate piece of work.
Transportimplementation, so a caller-suppliedTransportisstill driven directly and does not take part in the redirect handling.
Related pull requests
This change is part of one body of work. Together the changes make programs that use the network and child processes work on hosted linux and macOS. A full CLI was tested end to end with all of them and ships binaries built this way, see dispat v1.4.0 in the evidence section.
In tinygo-org/tinygo
In this repository
A merge order that works. The remaining bug fixes are independent. tinygo-org/tinygo#5633 goes before tinygo-org/tinygo#5635. HTTPS on linux needs only tinygo-org/tinygo#5633 and tinygo-org/tinygo#5635. Full darwin support also needs tinygo-org/tinygo#5636, the net changes and a new src/net submodule pin.
Related owner work
The Crier listener and close audit is separate from these PR measurements. The historical Linux arm64 run passed 142 tests with local patches. It predates later Crier changes and is not release validation.
Current integration status
Darwin fcntl work is in tinygo-org/tinygo#5612. tinygo-org/tinygo#5632 is closed and remains a history reference only. The integer and pointer tests were offered on #5612. Builder socket and spawn symbols in tinygo-org/tinygo#5636 are an independent prerequisite at 6fded0c9. The direct syscall test needs no net update, so that PR does not wait for this net series. tinygo-org/tinygo#5634 is limited to process support.
#82 supplies the separate ListenConfig implementation. Close guard tests and a limited shutdown fix stay on the fork branch codex/close-audit for coordination with the #77 owner. They are not equivalent to the poller. No second shutdown PR was opened.
Published fork and downstream evidence
The net.2 fork release combines the coordinated changes at
95fba82a, with net0f460803. It differs from accepted candidatee7d34c8conly in the version constant. Linux, macOS and Windows branch CI and tag CI passed on their first attempts.Dispat source
909dc401, with harness0990c6db, passed 796 test events with no failures or skips on each native Darwin ARM64 and Linux ARM64 candidate run. Crier source7d687fc8passed raw and stripped E2E on native Linux ARM64 and emulated Linux AMD64, each with 144 top-level tests and 156 passing events, no failures or skips. Both applications use TinyGo-built update fixtures and test trusted TLS, certificate refusal, original backup hashes and byte-identical offline rollback. Their workflows also exercise files, environment variables, concurrency and child processes. Crier includes real FFmpeg and webrender/canvas rendering.Crier's unchanged 13-image pixel gate passed. It uses an approved two-line explicit-rounding webrender build patch for both compilers. The earlier gradient mismatch was permitted fused arithmetic, not a TinyGo compiler error. Candidate stripped sizes are 13,835,824 versus 30,277,794 Go bytes on ARM64 (54.30% smaller), and 16,446,968 versus 32,518,306 on AMD64 (49.42% smaller).
These are combined-candidate application results, not proof that this PR alone supplies the features. They supersede the earlier Crier comparison. Published-toolchain probes and application acceptance have since completed. The final Crier v1.1.1 release evidence is below. Dispat controls its own publication. WaitDelay, in-flight deadlines and full descriptor lifetime remain open. This enables tested CLI client workflows, not general Go or server compatibility.
Owner sync, 6 September
The owner of #77 adopted our repeated-Close guard as
9dc11e1, with tests adapted to its nonblocking sockets. The owner of #80 adopted the Zone correction as7b7aacband removed the test dependency on #82. These are PR branches, not upstream merges.The owner of #83 supplied combined branch
0magnet/net:client-transport-dispatch-72at423aacc3, with #72 first and transport dispatch on top. The source retains the redirect loop and Host fallback. Proposed order is #72, then #83 rebased onto it. The three committed transport tests do not contain the reported redirect and sensitive-header tests, so their commit was requested in the review reply. The combined branch has not been independently executed here and is not included in net.2. New #84 uses the existing integer-conversion shim intlssock.goand is also not included. No duplicate PR is needed.Published Crier v1.1.1 evidence
Crier v1.1.1 is public at source
acac2f0eand uses published TinyGo0.43.0-net.2. Its final acceptance report and SHA-256 manifest identify the exact release bytes. The public tag, asset sizes and report digest were checked. These final sizes supersede the candidate sizes above.The report records 144 top-level tests and 156 passing events for each raw and stripped run on native ARM64 and emulated AMD64, with no failures or skips. It covers real CLI files, environment and concurrent work, child processes, TLS, update/rollback fixtures, uploads, real FFmpeg, and webrender/canvas rendering. The unchanged 13-image gate passes on both targets. AMD64 is exact; ARM64 has 12 exact images and four event-card pixels with channel difference 1. Both compilers use the same explicit-rounding webrender build patch. Standard Go tests, 90.6% coverage, lint and docs also pass.
This is combined-fork application evidence, not isolated proof for this PR or general server support. The generic emulated AMD64
osclosure assertions still fail and also fail with ordinary Go under that emulation; they are not counted as passing. Native AMD64 CI and the final published AMD64netpackage pass. The report retains other platform and deadline/descriptor limits. Tiny binaries are opt-in; normal install/self-update selects standard Go assets.Published Dispat v1.8.1 CLI evidence
Dispat v1.8.1 CLI is public. Its size and SHA-256 manifest records build source
40c58236, Go 1.26.8 and TinyGo0.43.0-net.2. The public asset metadata and manifest digest were checked.These are final published CLI asset sizes, not the earlier candidate measurements. They do not replace the separately identified test evidence or remove known runtime limits. The full release workflow has now completed successfully at the recorded build source, including its Windows, macOS and Ubuntu checks. This does not change the test and platform limits stated above.