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

Show escaped url in gateway 404 message #4005

Merged
merged 1 commit into from
Jun 28, 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
9 changes: 5 additions & 4 deletions core/corehttp/gateway_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ func (i *gatewayHandler) optionsHandler(w http.ResponseWriter, r *http.Request)
func (i *gatewayHandler) getOrHeadHandler(ctx context.Context, w http.ResponseWriter, r *http.Request) {

urlPath := r.URL.Path
escapedURLPath := r.URL.EscapedPath()

// If the gateway is behind a reverse proxy and mounted at a sub-path,
// the prefix header can be set to signal this sub-path.
Expand Down Expand Up @@ -173,12 +174,12 @@ func (i *gatewayHandler) getOrHeadHandler(ctx context.Context, w http.ResponseWr
case nil:
case coreiface.ErrOffline:
if !i.node.OnlineMode() {
webError(w, "ipfs resolve -r "+urlPath, err, http.StatusServiceUnavailable)
webError(w, "ipfs resolve -r "+escapedURLPath, err, http.StatusServiceUnavailable)
return
}
fallthrough
default:
webError(w, "ipfs resolve -r "+urlPath, err, http.StatusNotFound)
webError(w, "ipfs resolve -r "+escapedURLPath, err, http.StatusNotFound)
return
}

Expand All @@ -191,7 +192,7 @@ func (i *gatewayHandler) getOrHeadHandler(ctx context.Context, w http.ResponseWr
case coreiface.ErrIsDir:
dir = true
default:
webError(w, "ipfs cat "+urlPath, err, http.StatusNotFound)
webError(w, "ipfs cat "+escapedURLPath, err, http.StatusNotFound)
return
}

Expand Down Expand Up @@ -278,7 +279,7 @@ func (i *gatewayHandler) getOrHeadHandler(ctx context.Context, w http.ResponseWr
ixnd, err := dirr.Find(ctx, "index.html")
switch {
case err == nil:
log.Debugf("found index.html link for %s", urlPath)
log.Debugf("found index.html link for %s", escapedURLPath)

dirwithoutslash := urlPath[len(urlPath)-1] != '/'
goget := r.URL.Query().Get("go-get") == "1"
Expand Down
1 change: 1 addition & 0 deletions core/corehttp/gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ func TestGatewayGet(t *testing.T) {
{"localhost:5001", "/" + k, http.StatusNotFound, "404 page not found\n"},
{"localhost:5001", "/ipfs/" + k, http.StatusOK, "fnord"},
{"localhost:5001", "/ipns/nxdomain.example.com", http.StatusNotFound, "ipfs resolve -r /ipns/nxdomain.example.com: " + namesys.ErrResolveFailed.Error() + "\n"},
{"localhost:5001", "/ipns/%0D%0A%0D%0Ahello", http.StatusNotFound, "ipfs resolve -r /ipns/%0D%0A%0D%0Ahello: " + namesys.ErrResolveFailed.Error() + "\n"},
{"localhost:5001", "/ipns/example.com", http.StatusOK, "fnord"},
{"example.com", "/", http.StatusOK, "fnord"},
} {
Expand Down