diff --git a/core/corehttp/gateway_handler.go b/core/corehttp/gateway_handler.go index ceaec886a..113fe52b5 100644 --- a/core/corehttp/gateway_handler.go +++ b/core/corehttp/gateway_handler.go @@ -280,7 +280,9 @@ func (i *gatewayHandler) getOrHeadHandler(ctx context.Context, w http.ResponseWr case err == nil: log.Debugf("found index.html link for %s", urlPath) - if urlPath[len(urlPath)-1] != '/' { + dirwithoutslash := urlPath[len(urlPath)-1] != '/' + goget := r.URL.Query().Get("go-get") == "1" + if dirwithoutslash && !goget { // See comment above where originalUrlPath is declared. http.Redirect(w, r, originalUrlPath+"/", 302) log.Debugf("redirect to %s", originalUrlPath+"/") diff --git a/core/corehttp/gateway_test.go b/core/corehttp/gateway_test.go index 005f2844b..14f942b1f 100644 --- a/core/corehttp/gateway_test.go +++ b/core/corehttp/gateway_test.go @@ -490,6 +490,27 @@ func TestCacheControlImmutable(t *testing.T) { } } +func TestGoGetSupport(t *testing.T) { + ts, _ := newTestServerAndNode(t, nil) + t.Logf("test server url: %s", ts.URL) + defer ts.Close() + + // mimic go-get + req, err := http.NewRequest("GET", ts.URL+emptyDir+"?go-get=1", nil) + if err != nil { + t.Fatal(err) + } + + res, err := doWithoutRedirect(req) + if err != nil { + t.Fatal(err) + } + + if res.StatusCode != 200 { + t.Errorf("status is %d, expected 200", res.StatusCode) + } +} + func TestVersion(t *testing.T) { config.CurrentCommit = "theshortcommithash"