Commit 87d07a97 authored by Jeromy Johnson's avatar Jeromy Johnson Committed by GitHub

Merge pull request #3870 from ipfs/fix/directory-cache-control

gateway: fix erroneous Cache-Control: immutable on dir listings
parents db43aab0 2c4e6434
......@@ -202,7 +202,7 @@ func (i *gatewayHandler) getOrHeadHandler(ctx context.Context, w http.ResponseWr
// and only if it's /ipfs!
// TODO: break this out when we split /ipfs /ipns routes.
modtime := time.Now()
if strings.HasPrefix(urlPath, ipfsPathPrefix) {
if strings.HasPrefix(urlPath, ipfsPathPrefix) && !dir {
w.Header().Set("Etag", etag)
w.Header().Set("Cache-Control", "public, max-age=29030400, immutable")
......
......@@ -23,6 +23,9 @@ import (
id "gx/ipfs/QmeWJwi61vii5g8zQUB9UGegfUbmhTKHgeDFP9XuSp5jZ4/go-libp2p/p2p/protocol/identify"
)
// `ipfs object new unixfs-dir`
var emptyDir = "/ipfs/QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn"
type mockNamesys map[string]path.Path
func (m mockNamesys) Resolve(ctx context.Context, name string) (value path.Path, err error) {
......@@ -461,6 +464,32 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
}
}
func TestCacheControlImmutable(t *testing.T) {
ts, _ := newTestServerAndNode(t, nil)
t.Logf("test server url: %s", ts.URL)
defer ts.Close()
req, err := http.NewRequest("GET", ts.URL+emptyDir+"/", nil)
if err != nil {
t.Fatal(err)
}
res, err := doWithoutRedirect(req)
if err != nil {
t.Fatal(err)
}
// check the immutable tag isn't set
hdrs, ok := res.Header["Cache-Control"]
if ok {
for _, hdr := range hdrs {
if strings.Contains(hdr, "immutable") {
t.Fatalf("unexpected Cache-Control: immutable on directory listing: %s", hdr)
}
}
}
}
func TestVersion(t *testing.T) {
config.CurrentCommit = "theshortcommithash"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment