Skip to content

proxy: Follow multi-hop upstream redirects - #173

Merged
ganto merged 4 commits into
mainfrom
feature/follow-multi-hop-redirects
Nov 13, 2026
Merged

ganto merged 4 commits into
mainfrom
feature/follow-multi-hop-redirects

Conversation

@ganto

@ganto ganto commented Nov 13, 2026

Copy link
Copy Markdown
Owner

Summary

tryMirrors followed only one redirect per mirror attempt. A second redirect (as Fedora COPR sends) reached the client as a 3xx, and the package never got cached.

 tryMirrors
   for each mirror, attempt
     rsp = forward(mirror URL)
-    if rsp is redirect
-      rsp = forward(Location)
+    for hop := 0; rsp is redirect; hop++
+      if hop == 10                      -> fail attempt, next mirror
+      if https -> http downgrade        -> fail attempt, next mirror
+      rsp = forward(Location)
     if rsp is 200 -> return

If every mirror fails this way the client gets 502 Bad Gateway, never a 3xx. New spec: openspec/specs/upstream-redirects/spec.md.

Evidence

  • Before: (new tests run against main's proxy.go)
    --- FAIL: TestForwardProxyMultiHopRedirect
    --- FAIL: TestForwardProxyRedirectLoop
    --- FAIL: TestForwardProxyRedirectExactlyMaxHops
    --- FAIL: TestForwardProxyRedirectHTTPSDowngradeRejected
    
    After:
    --- PASS: TestForwardProxyRedirect
    --- PASS: TestForwardProxyMultipleRedirectStatusCodes
    --- PASS: TestForwardProxyRetryAfterRedirect5xx
    --- PASS: TestForwardProxyMultiHopRedirect
    --- PASS: TestForwardProxyRedirectLoop
    --- PASS: TestForwardProxyRedirectExactlyMaxHops
    --- PASS: TestForwardProxyRedirectLimitFallsBackToNextMirror
    --- PASS: TestForwardProxyRedirectHTTPSDowngradeRejected
    

Merge Danger

Door: two-way

Change is local to tryMirrors. No config or cache format changes; a revert restores the old behavior.

Blast Radius: upstream-fetching

A mirror that redirects from HTTPS to HTTP now fails instead of being followed. The proxy then tries the next mirror, or returns 502 if none is left.

🤖 Generated with Claude Code

ganto and others added 4 commits November 13, 2026 22:22
Fedora COPR now redirects twice (COPR -> Red Hat Pulp -> S3), but
tryMirrors followed only one redirect and passed the second 302 through
to the client, so nothing was cached.

Follow up to 10 redirects per mirror attempt. Reject HTTPS -> HTTP
downgrades, and treat an exceeded hop limit or rejected downgrade as a
failed mirror so the next one is tried (502 if none remain).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Bumps [reviewdog/action-actionlint](https://github.com/reviewdog/action-actionlint) from 1.76.0 to 1.81.2.
- [Release notes](https://github.com/reviewdog/action-actionlint/releases)
- [Commits](reviewdog/action-actionlint@320fcdd...7abf25e)

---
updated-dependencies:
- dependency-name: reviewdog/action-actionlint
  dependency-version: 1.81.2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
@ganto
ganto merged commit b765cbb into main Nov 13, 2026
22 checks passed
@ganto
ganto deleted the feature/follow-multi-hop-redirects branch November 13, 2026 21:41
@ganto ganto added the enhancement New feature or request label Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant