Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gateway: don't redirect to trailing slash if it's go get #3963

Merged
merged 1 commit into from
Jun 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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"

Expand Down