Skip to content

Commit f1d01d3

Browse files
lidelacejam
andauthored
fix: Cache-Control for generated UnixFS dir listings on /ipfs (#219)
* fix: Verify Cache-Control header for UnixFS directories * refactor: make Cache-Control on generated html optional This allows us to ship this as backward-compatible fix * docs: v0.6.1 changelog --------- Co-authored-by: Joshua Noble <jnoble@filebase.com>
1 parent 0ae5313 commit f1d01d3

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [0.6.1] - 2024-07-29
8+
### Changed
9+
- Support meaningful `Cache-Control` on generated UnixFS directory listing responses on `/ipfs` namespace
10+
711
## [0.6.0] - 2024-06-10
812
### Changed
913
- Gateway URL

tests/path_gateway_unixfs_test.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,20 +84,25 @@ func TestGatewayCache(t *testing.T) {
8484
tests := SugarTests{
8585
{
8686
Name: "GET for /ipfs/ unixfs dir listing succeeds",
87+
Hint: "UnixFS directory listings are generated HTML, which may change over time, and can't be cached forever. Still, should have a meaningful cache-control header.",
8788
Request: Request().
8889
Path("/ipfs/{{CID}}/root2/root3/", fixture.MustGetCid()),
89-
Response: Expect().
90-
Status(200).
91-
Headers(
92-
Header("Cache-Control").
93-
IsEmpty(),
94-
Header("X-Ipfs-Path").
95-
Equals("/ipfs/{{CID}}/root2/root3/", fixture.MustGetCid()),
96-
Header("X-Ipfs-Roots").
97-
Equals("{{CID1}},{{CID2}},{{CID3}}", fixture.MustGetCid(), fixture.MustGetCid("root2"), fixture.MustGetCid("root2", "root3")),
98-
Header("Etag").
99-
Matches("DirIndex-.*_CID-{{cid}}", fixture.MustGetCid("root2", "root3")),
90+
Response: AllOf(
91+
Expect().
92+
Status(200).
93+
Headers(
94+
Header("X-Ipfs-Path").
95+
Equals("/ipfs/{{CID}}/root2/root3/", fixture.MustGetCid()),
96+
Header("X-Ipfs-Roots").
97+
Equals("{{CID1}},{{CID2}},{{CID3}}", fixture.MustGetCid(), fixture.MustGetCid("root2"), fixture.MustGetCid("root2", "root3")),
98+
Header("Etag").
99+
Matches("DirIndex-.*_CID-{{cid}}", fixture.MustGetCid("root2", "root3")),
100+
),
101+
AnyOf(
102+
Expect().Headers(Header("Cache-Control").IsEmpty()),
103+
Expect().Headers(Header("Cache-Control").Equals("public, max-age=604800, stale-while-revalidate=2678400")),
100104
),
105+
),
101106
},
102107
{
103108
Name: "GET for /ipfs/ unixfs dir with index.html succeeds",

0 commit comments

Comments
 (0)