diff --git a/handler_test.go b/handler_test.go index fc5df68..959bc31 100644 --- a/handler_test.go +++ b/handler_test.go @@ -54,7 +54,7 @@ func TestRPCRedirectsToKubo(t *testing.T) { tests := []rpcRedirectTest{ {"/api/v0/name/resolve?arg=some-arg", "http://example.com/api/v0/name/resolve?arg=some-arg", http.StatusTemporaryRedirect}, - {"/api/v0/name/resolve/ipfs.io?arg=some-arg", "http://example.com/api/v0/name/resolve/ipfs.io?arg=some-arg", http.StatusTemporaryRedirect}, + {"/api/v0/name/resolve/some-arg", "http://example.com/api/v0/name/resolve/some-arg", http.StatusTemporaryRedirect}, {"/api/v0/resolve?arg=some-arg", "http://example.com/api/v0/resolve?arg=some-arg", http.StatusTemporaryRedirect}, {"/api/v0/dag/resolve?arg=some-arg", "http://example.com/api/v0/dag/resolve?arg=some-arg", http.StatusTemporaryRedirect}, {"/api/v0/dns?arg=some-arg", "http://example.com/api/v0/dns?arg=some-arg", http.StatusTemporaryRedirect}, diff --git a/handlers.go b/handlers.go index e2f0d3d..5834aa1 100644 --- a/handlers.go +++ b/handlers.go @@ -253,7 +253,10 @@ func newKuboRPCHandler(endpoints []string) http.Handler { redirectToKubo := func(w http.ResponseWriter, r *http.Request) { // Naively choose one of the Kubo RPC clients. endpoint := endpoints[rand.Intn(len(endpoints))] - url := endpoint + r.URL.Path + "?" + r.URL.RawQuery + url := endpoint + r.URL.Path + if r.URL.RawQuery != "" { + url += "?" + r.URL.RawQuery + } goLog.Debugw("api request redirected to kubo", "url", r.URL, "redirect", url) http.Redirect(w, r, url, http.StatusTemporaryRedirect) }