提交 584ab144 作者: Jakub Sztandera 提交者: GitHub

Merge branch 'master' into fix/gateway/3868-etag

......@@ -213,7 +213,8 @@ 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("Cache-Control", "public, max-age=29030400, immutable")
// set modtime to a really long time ago, since files are immutable and should stay cached
......
......@@ -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 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论