Skip to content

Commit

Permalink
Show escaped url in gateway 404 message
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
  • Loading branch information
magik6k committed Jun 22, 2017
1 parent db6073b commit 647e275
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
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

0 comments on commit 647e275

Please sign in to comment.