1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-30 01:52:26 +08:00

Merge pull request #3963 from ipfs/feat/gateway-go-get

gateway: don't redirect to trailing slash if it's go get
This commit is contained in:
Jeromy Johnson
2017-06-08 21:00:22 -07:00
committed by GitHub
2 changed files with 24 additions and 1 deletions

View File

@ -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+"/")

View File

@ -485,6 +485,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"