Skip to content

Commit

Permalink
fix: Cache-Control for generated UnixFS dir listings on /ipfs (#219)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
lidel and acejam authored Jul 29, 2024
1 parent 0ae5313 commit f1d01d3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.6.1] - 2024-07-29
### Changed
- Support meaningful `Cache-Control` on generated UnixFS directory listing responses on `/ipfs` namespace

## [0.6.0] - 2024-06-10
### Changed
- Gateway URL
Expand Down
27 changes: 16 additions & 11 deletions tests/path_gateway_unixfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,25 @@ func TestGatewayCache(t *testing.T) {
tests := SugarTests{
{
Name: "GET for /ipfs/ unixfs dir listing succeeds",
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.",
Request: Request().
Path("/ipfs/{{CID}}/root2/root3/", fixture.MustGetCid()),
Response: Expect().
Status(200).
Headers(
Header("Cache-Control").
IsEmpty(),
Header("X-Ipfs-Path").
Equals("/ipfs/{{CID}}/root2/root3/", fixture.MustGetCid()),
Header("X-Ipfs-Roots").
Equals("{{CID1}},{{CID2}},{{CID3}}", fixture.MustGetCid(), fixture.MustGetCid("root2"), fixture.MustGetCid("root2", "root3")),
Header("Etag").
Matches("DirIndex-.*_CID-{{cid}}", fixture.MustGetCid("root2", "root3")),
Response: AllOf(
Expect().
Status(200).
Headers(
Header("X-Ipfs-Path").
Equals("/ipfs/{{CID}}/root2/root3/", fixture.MustGetCid()),
Header("X-Ipfs-Roots").
Equals("{{CID1}},{{CID2}},{{CID3}}", fixture.MustGetCid(), fixture.MustGetCid("root2"), fixture.MustGetCid("root2", "root3")),
Header("Etag").
Matches("DirIndex-.*_CID-{{cid}}", fixture.MustGetCid("root2", "root3")),
),
AnyOf(
Expect().Headers(Header("Cache-Control").IsEmpty()),
Expect().Headers(Header("Cache-Control").Equals("public, max-age=604800, stale-while-revalidate=2678400")),
),
),
},
{
Name: "GET for /ipfs/ unixfs dir with index.html succeeds",
Expand Down

0 comments on commit f1d01d3

Please sign in to comment.