From 18d90d85683096ad6fc18c3e68a50a82838c2b38 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Sun, 26 Apr 2020 16:09:02 -0700 Subject: [PATCH 1/2] feat: always show the hash Previously, we only showed this /ipns paths. However, knowing the hash of the current directory is useful regardless. This commit was moved from ipfs/kubo@d8bc5c991e29c5de0c090ff851f6abdf00180a67 --- gateway/core/corehttp/gateway_handler.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/gateway/core/corehttp/gateway_handler.go b/gateway/core/corehttp/gateway_handler.go index f91d42b61..f34bbeb76 100644 --- a/gateway/core/corehttp/gateway_handler.go +++ b/gateway/core/corehttp/gateway_handler.go @@ -330,10 +330,7 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request } } - var hash string - if !strings.HasPrefix(urlPath, ipfsPathPrefix) { - hash = resolvedPath.Cid().String() - } + hash := resolvedPath.Cid().String() // See comment above where originalUrlPath is declared. tplData := listingTemplateData{ From 6161b22ad3a687501d29e5de1e43d02ec961d4d6 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Sun, 26 Apr 2020 16:11:20 -0700 Subject: [PATCH 2/2] feat: show the absolute path every time Even for dnslink websites. fixes https://github.com/ipfs/go-ipfs/issues/7205 This commit was moved from ipfs/kubo@46ae021733e825cb46c915518897816b191c60ef --- gateway/core/corehttp/gateway_handler.go | 2 +- gateway/core/corehttp/gateway_test.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/gateway/core/corehttp/gateway_handler.go b/gateway/core/corehttp/gateway_handler.go index f34bbeb76..2729f04e6 100644 --- a/gateway/core/corehttp/gateway_handler.go +++ b/gateway/core/corehttp/gateway_handler.go @@ -335,7 +335,7 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request // See comment above where originalUrlPath is declared. tplData := listingTemplateData{ Listing: dirListing, - Path: originalUrlPath, + Path: urlPath, BackLink: backLink, Hash: hash, } diff --git a/gateway/core/corehttp/gateway_test.go b/gateway/core/corehttp/gateway_test.go index daf1af07c..edae35e3f 100644 --- a/gateway/core/corehttp/gateway_test.go +++ b/gateway/core/corehttp/gateway_test.go @@ -378,7 +378,7 @@ func TestIPNSHostnameBacklinks(t *testing.T) { s := string(body) t.Logf("body: %s\n", string(body)) - if !strings.Contains(s, "Index of /foo? #<'/") { + if !strings.Contains(s, "Index of /ipns/example.net/foo? #<'/") { t.Fatalf("expected a path in directory listing") } if !strings.Contains(s, "") { @@ -444,7 +444,7 @@ func TestIPNSHostnameBacklinks(t *testing.T) { s = string(body) t.Logf("body: %s\n", string(body)) - if !strings.Contains(s, "Index of /foo? #<'/bar/") { + if !strings.Contains(s, "Index of /ipns/example.net/foo? #<'/bar/") { t.Fatalf("expected a path in directory listing") } if !strings.Contains(s, "") { @@ -478,7 +478,7 @@ func TestIPNSHostnameBacklinks(t *testing.T) { s = string(body) t.Logf("body: %s\n", string(body)) - if !strings.Contains(s, "Index of /good-prefix") { + if !strings.Contains(s, "Index of /ipns/example.net") { t.Fatalf("expected a path in directory listing") } if !strings.Contains(s, "") {