From 9e8d9bf837febcc387130d78ac2a3435a728bf1b Mon Sep 17 00:00:00 2001 From: oppiliappan Date: Thu, 13 Nov 2025 10:36:41 +0000 Subject: [PATCH] appview/router: fix url rewriter Change-Id: vxnsylzpprznkvqlvwoltztqlytqyzzs the appview rewrites urls of the form: host.com/did-plc-foo/repo => host.com/did:plc:foo/repo host.com/@handle.com/repo => host.com/handle.com/repo however, the rewriter did not preserve query parameters or fragments: host.com/@handle.com/repo?foo=bar => host.com/handle.com/repo? this resulted in url rewrites being broken for git clones, which usees the "service" query parameter: ../repo/info/refs?service=git-upload-pack => ../repo/info/refs? the new url rewriter simply takes the existing url and replaces the path component, thus preserving all other bits of the url. Signed-off-by: oppiliappan --- appview/state/router.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/appview/state/router.go b/appview/state/router.go index 7aabd5a5..fd2c4e84 100644 --- a/appview/state/router.go +++ b/appview/state/router.go @@ -57,14 +57,22 @@ func (s *State) Router() http.Handler { if userutil.IsFlattenedDid(firstPart) { unflattenedDid := userutil.UnflattenDid(firstPart) redirectPath := strings.Join(append([]string{unflattenedDid}, pathParts[1:]...), "/") - http.Redirect(w, r, "/"+redirectPath, http.StatusFound) + + redirectURL := *r.URL + redirectURL.Path = "/" + redirectPath + + http.Redirect(w, r, redirectURL.String(), http.StatusFound) return } // if using a handle with @, rewrite to work without @ if normalized := strings.TrimPrefix(firstPart, "@"); userutil.IsHandle(normalized) { redirectPath := strings.Join(append([]string{normalized}, pathParts[1:]...), "/") - http.Redirect(w, r, "/"+redirectPath, http.StatusFound) + + redirectURL := *r.URL + redirectURL.Path = "/" + redirectPath + + http.Redirect(w, r, redirectURL.String(), http.StatusFound) return } -- 2.43.0