Skip to content

Commit

Permalink
Merge pull request #3963 from ipfs/feat/gateway-go-get
Browse files Browse the repository at this point in the history
gateway: don't redirect to trailing slash if it's go get
  • Loading branch information
whyrusleeping authored Jun 9, 2017
2 parents 1a1935f + 4fe5b3e commit 67828a4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
4 changes: 3 additions & 1 deletion core/corehttp/gateway_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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+"/")
Expand Down
21 changes: 21 additions & 0 deletions core/corehttp/gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit 67828a4

Please sign in to comment.