smarthttp: optionally follow info/refs redirects into Endpoint#9
Merged
Conversation
Adds Conn.FollowInfoRefsRedirect (off by default). When set, RequestInfoRefs rewrites Endpoint.Scheme + Endpoint.Host to the final URL after HTTP redirects, so subsequent PostRPC* calls target the redirected node instead of the originally-configured entry point. Matches vanilla git's smart-HTTP behaviour for discovery-aware servers that 307 /info/refs to a hosting replica (the entiredb info/refs discovery design). Endpoint.Path is never modified — it still holds the repo path. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Entire-Checkpoint: 359b871b7cfb
golangci-lint v2.11.4 (matches CI) flagged the discarded w.Write returns and unused *http.Request parameter in the two new FollowInfoRefsRedirect tests. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Entire-Checkpoint: 0b59e56d2ab4
The flag was previously on gitproto.Conn but unreachable from normal gitsync callers — gitproto is an internal package, and neither syncer.Endpoint, internalbridge.Endpoint, nor pkg/gitsync.Endpoint carried it. This made the flag dead config for CLI and library users. Wire it through the endpoint-shaped layers (pkg/gitsync.Endpoint → internalbridge.Endpoint → syncer.Endpoint → gitproto.Conn). Per- endpoint rather than whole-Config so source and target can opt in independently — mirror-worker only needs it on the target. Adds two tests: - An integration test at the gitproto level that runs the full info/refs → follow-up POST sequence against two httptest servers (entry that 307s, node that serves the pack) and asserts the POST lands on the node, not the entry. This is the property that makes the feature useful. - A plumbing test at the syncer level proving newConn propagates the flag from Endpoint to Conn — guards against the exact regression the reviewer flagged. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Entire-Checkpoint: f042a8274858
Entire-Checkpoint: 409696665b2c
Soph
approved these changes
Apr 24, 2026
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.
Adds Conn.FollowInfoRefsRedirect (off by default). When set, RequestInfoRefs rewrites Endpoint.Scheme + Endpoint.Host to the final URL after HTTP redirects, so subsequent PostRPC* calls target the redirected node instead of the originally-configured entry point.
Matches vanilla git's smart-HTTP behaviour for discovery-aware servers that 307 /info/refs to a hosting replica (the entiredb info/refs discovery design). Endpoint.Path is never modified — it still holds the repo path.
Note
Medium Risk
Changes request flow by mutating
Conn.Endpointbased on the final redirected URL, which can affect where subsequent Git RPC POSTs are sent; behavior is gated behind a new opt-in flag and covered by tests.Overview
Adds opt-in support for discovery-aware Git smart-HTTP setups that redirect
/info/refsto a replica.ConngainsFollowInfoRefsRedirect; when enabled,RequestInfoRefsrewritesEndpoint.Scheme/Endpoint.Hostto the final URL after redirects so subsequentPostRPC*calls go directly to the redirected host (leavingEndpoint.Pathunchanged). New tests validate both the redirect-following behavior and that the default behavior remains unchanged.Reviewed by Cursor Bugbot for commit 39e0654. Configure here.