fix: support directory listings even if a 404 page is present
fixes https://github.com/ipfs/go-ipfs/pull/4233#issuecomment-631454543 Basically, there's a trade-off here: 1. We can support directory listings while supporting 404 pages (this PR). 2. If a 404 page is present, directory listings don't work. Given that option 1 is more flexible and users shouldn't be _too_ confused if they land on a directory with no index.html page, I've gone with that option.
Steven Allen committed
May 20, 2020 at 19:07 UTC
6a2fe0a20de795732477c707b606eb947a326402
2 files changed
+3
-7
core/corehttp/gateway_handler.go
-4
@@ -307,10 +307,6 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request
307
return
308
}
309
310
- if i.servePretty404IfPresent(w, r, parsedPath) {
311
- return
312
- }
313
-
310
// storage for directory listing
311
var dirListing []directoryItem
312
dirit := dir.Entries()
core/corehttp/gateway_test.go
+3
-3
@@ -267,8 +267,8 @@ func TestPretty404(t *testing.T) {
267
{"/nope", "*/*", http.StatusNotFound, "Custom 404"},
268
{"/nope", "application/json", http.StatusNotFound, "ipfs resolve -r /ipns/example.net/nope: no link named \"nope\" under QmcmnF7XG5G34RdqYErYDwCKNFQ6jb8oKVR21WAJgubiaj\n"},
269
{"/deeper/nope", "text/html", http.StatusNotFound, "Deep custom 404"},
270
- {"/deeper/", "text/html", http.StatusNotFound, "Deep custom 404"},
271
- {"/deeper", "text/html", http.StatusNotFound, "Deep custom 404"},
270
+ {"/deeper/", "text/html", http.StatusOK, ""},
271
+ {"/deeper", "text/html", http.StatusOK, ""},
272
{"/nope/nope", "text/html", http.StatusNotFound, "Custom 404"},
273
} {
274
var c http.Client
@@ -293,7 +293,7 @@ func TestPretty404(t *testing.T) {
293
t.Fatalf("error reading response from %s: %s", test.path, err)
294
}
295
296
- if string(body) != test.text {
296
+ if test.text != "" && string(body) != test.text {
297
t.Fatalf("unexpected response body from %s: got %q, expected %q", test.path, body, test.text)
298
}
299
}