Skip to content

Commit 5caed9c

Browse files
gantoclaude
andcommitted
proxy: Preserve query string when forwarding to upstream mirrors
The upstream URL was constructed with only Scheme, Host, and Path, dropping any query parameters from the original client request. Add RawQuery to the upstream URL so query strings are forwarded correctly. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 138374a commit 5caed9c

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

pkg/pkgproxy/proxy.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,9 +314,10 @@ func (pp *pkgProxy) tryMirrors(ctx context.Context, rid string, req *http.Reques
314314

315315
upstreamPath := path.Join(mirror.Path, strings.TrimPrefix(req.URL.Path, "/"+repo))
316316
rsp, err = pp.forwardClientRequestToOrigin(ctx, rid, req, &url.URL{
317-
Scheme: mirror.Scheme,
318-
Host: mirror.Host,
319-
Path: upstreamPath,
317+
Scheme: mirror.Scheme,
318+
Host: mirror.Host,
319+
Path: upstreamPath,
320+
RawQuery: req.URL.RawQuery,
320321
}, reqBody)
321322
if err != nil {
322323
slog.Warn("upstream request failed", "request_id", rid, "mirror_index", i, "attempt", attempt, "error", err)

pkg/pkgproxy/proxy_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,25 @@ func TestForwardProxyUpstreamPath(t *testing.T) {
587587
assert.Equal(t, "/basepath/sub/dir/file.rpm", receivedPath)
588588
}
589589

590+
func TestForwardProxyQueryStringPreserved(t *testing.T) {
591+
var receivedRawQuery string
592+
upstream := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
593+
receivedRawQuery = r.URL.RawQuery
594+
w.WriteHeader(http.StatusOK)
595+
}))
596+
defer upstream.Close()
597+
598+
pp, _ := newTestProxy(t, []string{upstream.URL + "/"})
599+
app := newTestApp(pp)
600+
601+
req := httptest.NewRequest(http.MethodGet, "/testrepo/repodata/repomd.xml?age=300&arch=x86_64", nil)
602+
rec := httptest.NewRecorder()
603+
app.ServeHTTP(rec, req)
604+
605+
assert.Equal(t, http.StatusOK, rec.Code)
606+
assert.Equal(t, "age=300&arch=x86_64", receivedRawQuery)
607+
}
608+
590609
// --- httpbin.org tests (gated by environment variable) ---
591610

592611
func TestForwardProxyWithHttpbin(t *testing.T) {

0 commit comments

Comments
 (0)