Skip to content

Commit

Permalink
Merge pull request ipfs/kubo#5830 from jackloughran/feat/gateway/alwa…
Browse files Browse the repository at this point in the history
…ys-show-hash

Show hash on gateway

This commit was moved from ipfs/kubo@f98652c
  • Loading branch information
Stebalien committed Jan 5, 2019
2 parents 072ba7d + b16fca0 commit 4f38e82
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions gateway/core/corehttp/gateway_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,17 @@ func (i *gatewayHandler) getOrHeadHandler(ctx context.Context, w http.ResponseWr
}
}

var hash string
if !strings.HasPrefix(originalUrlPath, ipfsPathPrefix) {
hash = resolvedPath.Cid().String()
}

// See comment above where originalUrlPath is declared.
tplData := listingTemplateData{
Listing: dirListing,
Path: originalUrlPath,
BackLink: backLink,
Hash: hash,
}
err = listingTemplate.Execute(w, tplData)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions gateway/core/corehttp/gateway_indexPage.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type listingTemplateData struct {
Listing []directoryItem
Path string
BackLink string
Hash string
}

type directoryItem struct {
Expand Down
15 changes: 15 additions & 0 deletions gateway/core/corehttp/gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,9 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
if !strings.Contains(s, "<a href=\"/foo%3F%20%23%3C%27/file.txt\">") {
t.Fatalf("expected file in directory listing")
}
if !strings.Contains(s, dagn2.Cid().String()) {
t.Fatalf("expected hash in directory listing")
}

// make request to directory listing at root
req, err = http.NewRequest("GET", ts.URL, nil)
Expand Down Expand Up @@ -435,6 +438,9 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
if !strings.Contains(s, "<a href=\"/file.txt\">") {
t.Fatalf("expected file in directory listing")
}
if !strings.Contains(s, dagn1.Cid().String()) {
t.Fatalf("expected hash in directory listing")
}

// make request to directory listing
req, err = http.NewRequest("GET", ts.URL+"/foo%3F%20%23%3C%27/bar/", nil)
Expand Down Expand Up @@ -465,6 +471,9 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
if !strings.Contains(s, "<a href=\"/foo%3F%20%23%3C%27/bar/file.txt\">") {
t.Fatalf("expected file in directory listing")
}
if !strings.Contains(s, dagn3.Cid().String()) {
t.Fatalf("expected hash in directory listing")
}

// make request to directory listing with prefix
req, err = http.NewRequest("GET", ts.URL, nil)
Expand Down Expand Up @@ -496,6 +505,9 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
if !strings.Contains(s, "<a href=\"/good-prefix/file.txt\">") {
t.Fatalf("expected file in directory listing")
}
if !strings.Contains(s, dagn1.Cid().String()) {
t.Fatalf("expected hash in directory listing")
}

// make request to directory listing with illegal prefix
req, err = http.NewRequest("GET", ts.URL, nil)
Expand Down Expand Up @@ -535,6 +547,9 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
if !strings.Contains(s, "<a href=\"/file.txt\">") {
t.Fatalf("expected file in directory listing")
}
if !strings.Contains(s, dagn1.Cid().String()) {
t.Fatalf("expected hash in directory listing")
}
}

func TestCacheControlImmutable(t *testing.T) {
Expand Down

0 comments on commit 4f38e82

Please sign in to comment.