Skip to content

Commit e832cc2

Browse files
lidelJorropo
authored andcommitted
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.
1 parent 3181715 commit e832cc2

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

core/corehttp/gateway_handler_unixfs_dir.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func (i *gatewayHandler) serveDirectory(ctx context.Context, w http.ResponseWrit
4242
originalUrlPath := requestURI.Path
4343

4444
// Check if directory has index.html, if so, serveFile
45-
idxPath := ipath.Join(resolvedPath, "index.html")
45+
idxPath := ipath.Join(contentPath, "index.html")
4646
idx, err := i.api.Unixfs().Get(ctx, idxPath)
4747
switch err.(type) {
4848
case nil:

test/sharness/t0116-gateway-cache.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,35 @@ test_expect_success "Prepare IPNS unixfs content path for testing" '
6767
cat curl_ipns_file_output
6868
'
6969

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+
7099
# Cache-Control: only-if-cached
71100
test_expect_success "HEAD for /ipfs/ with only-if-cached succeeds when in local datastore" '
72101
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ test_expect_success "Create text fixtures" '
6868
'
6969

7070
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
7272
'
7373

7474
test_kill_ipfs_daemon

0 commit comments

Comments
 (0)