Skip to content

Commit bca4a26

Browse files
committed
refactor: make Cache-Control on generated html optional
This allows us to ship this as backward-compatible fix
1 parent 9cd2679 commit bca4a26

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

tests/path_gateway_unixfs_test.go

+16-11
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-
Equals("public, max-age=604800, stale-while-revalidate=2678400"),
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)