Skip to content

Commit

Permalink
refactor: test arg in path alone
Browse files Browse the repository at this point in the history
  • Loading branch information
lidel committed Jan 29, 2024
1 parent 7ae71af commit 6011cdb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
5 changes: 4 additions & 1 deletion handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 6011cdb

Please sign in to comment.