@cryptotaxi247 / kubo / commits / 5ebf897f6

Show escaped url in gateway 404 message

License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>

Łukasz Magiera committed Jun 22, 2017 at 16:59 UTC 5ebf897f6f3b86d9dc84273d5e1d3fefedbd8066
2 files changed +6 -4
core/corehttp/gateway_handler.go
+5 -4
@@ -134,6 +134,7 @@ func (i *gatewayHandler) optionsHandler(w http.ResponseWriter, r *http.Request)
134 func (i *gatewayHandler) getOrHeadHandler(ctx context.Context, w http.ResponseWriter, r *http.Request) {
135
136 urlPath := r.URL.Path
137 + escapedURLPath := r.URL.EscapedPath()
138
139 // If the gateway is behind a reverse proxy and mounted at a sub-path,
140 // the prefix header can be set to signal this sub-path.
@@ -173,12 +174,12 @@ func (i *gatewayHandler) getOrHeadHandler(ctx context.Context, w http.ResponseWr
174 case nil:
175 case coreiface.ErrOffline:
176 if !i.node.OnlineMode() {
176 - webError(w, "ipfs resolve -r "+urlPath, err, http.StatusServiceUnavailable)
177 + webError(w, "ipfs resolve -r "+escapedURLPath, err, http.StatusServiceUnavailable)
178 return
179 }
180 fallthrough
181 default:
181 - webError(w, "ipfs resolve -r "+urlPath, err, http.StatusNotFound)
182 + webError(w, "ipfs resolve -r "+escapedURLPath, err, http.StatusNotFound)
183 return
184 }
185
@@ -191,7 +192,7 @@ func (i *gatewayHandler) getOrHeadHandler(ctx context.Context, w http.ResponseWr
192 case coreiface.ErrIsDir:
193 dir = true
194 default:
194 - webError(w, "ipfs cat "+urlPath, err, http.StatusNotFound)
195 + webError(w, "ipfs cat "+escapedURLPath, err, http.StatusNotFound)
196 return
197 }
198
@@ -278,7 +279,7 @@ func (i *gatewayHandler) getOrHeadHandler(ctx context.Context, w http.ResponseWr
279 ixnd, err := dirr.Find(ctx, "index.html")
280 switch {
281 case err == nil:
281 - log.Debugf("found index.html link for %s", urlPath)
282 + log.Debugf("found index.html link for %s", escapedURLPath)
283
284 dirwithoutslash := urlPath[len(urlPath)-1] != '/'
285 goget := r.URL.Query().Get("go-get") == "1"
core/corehttp/gateway_test.go
+1
@@ -140,6 +140,7 @@ func TestGatewayGet(t *testing.T) {
140 {"localhost:5001", "/" + k, http.StatusNotFound, "404 page not found\n"},
141 {"localhost:5001", "/ipfs/" + k, http.StatusOK, "fnord"},
142 {"localhost:5001", "/ipns/nxdomain.example.com", http.StatusNotFound, "ipfs resolve -r /ipns/nxdomain.example.com: " + namesys.ErrResolveFailed.Error() + "\n"},
143 + {"localhost:5001", "/ipns/%0D%0A%0D%0Ahello", http.StatusNotFound, "ipfs resolve -r /ipns/%0D%0A%0D%0Ahello: " + namesys.ErrResolveFailed.Error() + "\n"},
144 {"localhost:5001", "/ipns/example.com", http.StatusOK, "fnord"},
145 {"example.com", "/", http.StatusOK, "fnord"},
146 } {