@cryptotaxi247 / kubo / commits / 84c3f101f

fix(gw): cache-control of index.html websites

This fixes a regression introduced in 0.13.0, where websites hosted via index.html placed in UnixFS directory were always returned with Cache-Control: public, max-age=29030400, immutable even when loaded from mutable /ipns/ contentPath. (cherry picked from commit e832cc2c1db13ee93e5907380a7ea7af9c2a45d4)

Marcin Rataj committed Jul 21, 2022 at 03:41 UTC 84c3f101fdb5b0a9d79999feaa5f44c710b3e938
3 files changed +31 -2
core/corehttp/gateway_handler_unixfs_dir.go
+1 -1
@@ -42,7 +42,7 @@ func (i *gatewayHandler) serveDirectory(ctx context.Context, w http.ResponseWrit
42 originalUrlPath := requestURI.Path
43
44 // Check if directory has index.html, if so, serveFile
45 - idxPath := ipath.Join(resolvedPath, "index.html")
45 + idxPath := ipath.Join(contentPath, "index.html")
46 idx, err := i.api.Unixfs().Get(ctx, idxPath)
47 switch err.(type) {
48 case nil:
test/sharness/t0116-gateway-cache.sh
+29
@@ -67,6 +67,35 @@ test_expect_success "Prepare IPNS unixfs content path for testing" '
67 cat curl_ipns_file_output
68 '
69
70 +# Cache-Control
71 +
72 +# Cache-Control: immutable /ipfs/ file
73 + test_expect_success "GET /ipfs/ unixfs file has expected Cache-Control" '
74 + test_should_contain "< Cache-Control: public, max-age=29030400, immutable" curl_ipfs_file_output
75 + '
76 +# Cache-Control: generated /ipfs/dir/ (listing)
77 + # TODO: test_should_contain "< Cache-Control: public, max-age=TBD" curl_ipfs_dir_listing_output
78 + test_expect_success "GET /ipfs/ unixfs dir listing has no Cache-Control" '
79 + test_should_not_contain "< Cache-Control" curl_ipns_dir_listing_output
80 + '
81 +# Cache-Control: immutable /ipfs/dir/ (index.html)
82 + test_expect_success "GET /ipfs/ unixfs dir with index.html has expected Cache-Control" '
83 + test_should_contain "< Cache-Control: public, max-age=29030400, immutable" curl_ipfs_dir_index.html_output
84 + '
85 +
86 +# Cache-Control: mutable /ipns/ file
87 + test_expect_success "GET /ipns/ unixfs file has no Cache-Control" '
88 + test_should_not_contain "< Cache-Control" curl_ipns_file_output
89 + '
90 +# Cache-Control: generated /ipns/dir/ (listing)
91 + test_expect_success "GET /ipns/ unixfs dir listing has no Cache-Control" '
92 + test_should_not_contain "< Cache-Control" curl_ipns_dir_listing_output
93 + '
94 +# Cache-Control: immutable /ipns/dir/ (index.html)
95 + test_expect_success "GET /ipns/ unixfs dir with index.html has no Cache-Control" '
96 + test_should_not_contain "< Cache-Control" curl_ipns_dir_index.html_output
97 + '
98 +
99 # Cache-Control: only-if-cached
100 test_expect_success "HEAD for /ipfs/ with only-if-cached succeeds when in local datastore" '
101 curl -sv -I -H "Cache-Control: only-if-cached" "http://127.0.0.1:$GWAY_PORT/ipfs/$ROOT1_CID/root2/root3/root4/index.html" > curl_onlyifcached_postitive_head 2>&1 &&
test/sharness/t0117-gateway-block.sh
+1 -1
@@ -68,7 +68,7 @@ test_expect_success "Create text fixtures" '
68 '
69
70 test_expect_success "GET response for application/vnd.ipld.raw includes Cache-Control" '
71 - grep "< Cache-Control" curl_output
71 + grep "< Cache-Control: public, max-age=29030400, immutable" curl_output
72 '
73
74 test_kill_ipfs_daemon