Skip to content

Commit

Permalink
Include the git blob id of the dir-index bundle in the ETag
Browse files Browse the repository at this point in the history
While the content of raw files retrieved via the gateway should never
change, the look and feel of the directory index can and will change
between versions of go-ipfs.

Incorporate the hash of assets/bindata.go into the ETag when appropriate


This commit was moved from ipfs/kubo@2d5f8b4
  • Loading branch information
ribasushi committed May 25, 2020
1 parent a16c116 commit de69041
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions gateway/core/corehttp/gateway_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/gabriel-vasile/mimetype"
"github.com/ipfs/go-cid"
files "github.com/ipfs/go-ipfs-files"
assets "github.com/ipfs/go-ipfs/assets"
dag "github.com/ipfs/go-merkledag"
mfs "github.com/ipfs/go-mfs"
path "github.com/ipfs/go-path"
Expand Down Expand Up @@ -222,16 +223,26 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request

defer dr.Close()

// Check etag send back to us
etag := "\"" + resolvedPath.Cid().String() + "\""
if r.Header.Get("If-None-Match") == etag || r.Header.Get("If-None-Match") == "W/"+etag {
var responseEtag string

// we need to figure out whether this is a directory before doing most of the heavy lifting below
_, ok := dr.(files.Directory)

if ok && assets.BindataVersionHash != "" {
responseEtag = `"DirIndex-` + assets.BindataVersionHash + `_CID-` + resolvedPath.Cid().String() + `"`
} else {
responseEtag = `"` + resolvedPath.Cid().String() + `"`
}

// Check etag sent back to us
if r.Header.Get("If-None-Match") == responseEtag || r.Header.Get("If-None-Match") == `W/`+responseEtag {
w.WriteHeader(http.StatusNotModified)
return
}

i.addUserHeaders(w) // ok, _now_ write user's headers.
w.Header().Set("X-IPFS-Path", urlPath)
w.Header().Set("Etag", etag)
w.Header().Set("Etag", responseEtag)

// set these headers _after_ the error, for we may just not have it
// and don't want the client to cache a 500 response...
Expand Down

0 comments on commit de69041

Please sign in to comment.