Monorepo for Tangled tangled.org

appview/router: fix url rewriter

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 <me@oppi.li>

oppi.li 9e8d9bf8 5c69fb2b

verified
Changed files
+10 -2
appview
state
+10 -2
appview/state/router.go
··· 57 57 if userutil.IsFlattenedDid(firstPart) { 58 58 unflattenedDid := userutil.UnflattenDid(firstPart) 59 59 redirectPath := strings.Join(append([]string{unflattenedDid}, pathParts[1:]...), "/") 60 - http.Redirect(w, r, "/"+redirectPath, http.StatusFound) 60 + 61 + redirectURL := *r.URL 62 + redirectURL.Path = "/" + redirectPath 63 + 64 + http.Redirect(w, r, redirectURL.String(), http.StatusFound) 61 65 return 62 66 } 63 67 64 68 // if using a handle with @, rewrite to work without @ 65 69 if normalized := strings.TrimPrefix(firstPart, "@"); userutil.IsHandle(normalized) { 66 70 redirectPath := strings.Join(append([]string{normalized}, pathParts[1:]...), "/") 67 - http.Redirect(w, r, "/"+redirectPath, http.StatusFound) 71 + 72 + redirectURL := *r.URL 73 + redirectURL.Path = "/" + redirectPath 74 + 75 + http.Redirect(w, r, redirectURL.String(), http.StatusFound) 68 76 return 69 77 } 70 78