Skip to content

smarthttp: optionally follow info/refs redirects into Endpoint#9

Merged
nodo merged 4 commits intomainfrom
nodo/follow-info-refs-redirects
Apr 24, 2026
Merged

smarthttp: optionally follow info/refs redirects into Endpoint#9
nodo merged 4 commits intomainfrom
nodo/follow-info-refs-redirects

Conversation

@nodo
Copy link
Copy Markdown
Collaborator

@nodo nodo commented Apr 24, 2026

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.Endpoint based 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/refs to a replica.

Conn gains FollowInfoRefsRedirect; when enabled, RequestInfoRefs rewrites Endpoint.Scheme/Endpoint.Host to the final URL after redirects so subsequent PostRPC* calls go directly to the redirected host (leaving Endpoint.Path unchanged). New tests validate both the redirect-following behavior and that the default behavior remains unchanged.

Reviewed by Cursor Bugbot for commit 39e0654. Configure here.

nodo and others added 4 commits April 24, 2026 13:54
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
@nodo nodo requested a review from Soph April 24, 2026 12:14
@nodo nodo merged commit 66ab8c4 into main Apr 24, 2026
3 checks passed
@nodo nodo deleted the nodo/follow-info-refs-redirects branch April 24, 2026 12:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants