Skip to content

Commit

Permalink
refactor: allow Cache-Control to either be empty or set in /ipns
Browse files Browse the repository at this point in the history
  • Loading branch information
hacdias committed Oct 2, 2023
1 parent 2ecf8ff commit f81afb8
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 51 deletions.
21 changes: 13 additions & 8 deletions tests/path_gateway_dag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -803,14 +803,19 @@ func TestGatewayJSONCborAndIPNS(t *testing.T) {
Request: Request().
Path("/ipns/{{id}}/", row.fixture.Key()).
Header("Accept", "text/html"),
Response: Expect().
Headers(
Header("Etag").Contains("DagIndex-"),
Header("Content-Type").Contains("text/html"),
Header("Content-Disposition").IsEmpty(),
// Header("Cache-Control").IsEmpty(),
).Body(
Contains("</html>"),
Response: AllOf(
Expect().
Headers(
Header("Etag").Contains("DagIndex-"),
Header("Content-Type").Contains("text/html"),
Header("Content-Disposition").IsEmpty(),
).Body(
Contains("</html>"),
),
AnyOf(
Expect().Headers(Header("Cache-Control").IsEmpty()),
Expect().Headers(Header("Cache-Control").Matches("public, max-age=*")),
),
),
},
}...)
Expand Down
102 changes: 59 additions & 43 deletions tests/path_gateway_unixfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,76 +328,92 @@ func TestGatewayCacheWithIPNS(t *testing.T) {
Name: "GET for /ipns/ unixfs dir listing succeeds",
Request: Request().
Path("/ipns/{{KEY}}/root2/root3/", ipnsKey),
Response: Expect().
Status(200).
Headers(
// Header("Cache-Control").
// IsEmpty(),
Header("X-Ipfs-Path").
Equals("/ipns/{{KEY}}/root2/root3/", ipnsKey),
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("/ipns/{{KEY}}/root2/root3/", ipnsKey),
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").Matches("public, max-age=*")),
),
),
},
{
Name: "GET for /ipns/ unixfs dir with index.html succeeds",
Request: Request().
Path("/ipns/{{KEY}}/root2/root3/root4/", ipnsKey),
Response: Expect().
Status(200).
Headers(
// Header("Cache-Control").
// IsEmpty(),
Header("X-Ipfs-Path").
Equals("/ipns/{{KEY}}/root2/root3/root4/", ipnsKey),
Header("X-Ipfs-Roots").
Equals("{{CID1}},{{CID2}},{{CID3}},{{CID4}}", fixture.MustGetCid(), fixture.MustGetCid("root2"), fixture.MustGetCid("root2", "root3"), fixture.MustGetCid("root2", "root3", "root4")),
Header("Etag").
Matches(`"{{CID}}"`, fixture.MustGetCid("root2", "root3", "root4")),
Response: AllOf(
Expect().
Status(200).
Headers(
Header("X-Ipfs-Path").
Equals("/ipns/{{KEY}}/root2/root3/root4/", ipnsKey),
Header("X-Ipfs-Roots").
Equals("{{CID1}},{{CID2}},{{CID3}},{{CID4}}", fixture.MustGetCid(), fixture.MustGetCid("root2"), fixture.MustGetCid("root2", "root3"), fixture.MustGetCid("root2", "root3", "root4")),
Header("Etag").
Matches(`"{{CID}}"`, fixture.MustGetCid("root2", "root3", "root4")),
),
AnyOf(
Expect().Headers(Header("Cache-Control").IsEmpty()),
Expect().Headers(Header("Cache-Control").Matches("public, max-age=*")),
),
),
},
{
Name: "GET for /ipns/ unixfs file succeeds",
Request: Request().
Path("/ipns/{{KEY}}/root2/root3/root4/index.html", ipnsKey),
Response: Expect().
Status(200).
Headers(
// Header("Cache-Control").
// IsEmpty(),
Header("X-Ipfs-Path").
Equals("/ipns/{{KEY}}/root2/root3/root4/index.html", ipnsKey),
Header("X-Ipfs-Roots").
Equals("{{CID1}},{{CID2}},{{CID3}},{{CID4}},{{CID5}}", fixture.MustGetCid(), fixture.MustGetCid("root2"), fixture.MustGetCid("root2", "root3"), fixture.MustGetCid("root2", "root3", "root4"), fixture.MustGetCid("root2", "root3", "root4", "index.html")),
Header("Etag").
Equals(`"{{CID}}"`, fixture.MustGetCid("root2", "root3", "root4", "index.html")),
Response: AllOf(
Expect().
Status(200).
Headers(
Header("X-Ipfs-Path").
Equals("/ipns/{{KEY}}/root2/root3/root4/index.html", ipnsKey),
Header("X-Ipfs-Roots").
Equals("{{CID1}},{{CID2}},{{CID3}},{{CID4}},{{CID5}}", fixture.MustGetCid(), fixture.MustGetCid("root2"), fixture.MustGetCid("root2", "root3"), fixture.MustGetCid("root2", "root3", "root4"), fixture.MustGetCid("root2", "root3", "root4", "index.html")),
Header("Etag").
Equals(`"{{CID}}"`, fixture.MustGetCid("root2", "root3", "root4", "index.html")),
),
AnyOf(
Expect().Headers(Header("Cache-Control").IsEmpty()),
Expect().Headers(Header("Cache-Control").Matches("public, max-age=*")),
),
),
},
{
Name: "GET for /ipns/ unixfs dir as DAG-JSON succeeds",
Request: Request().
Path("/ipns/{{KEY}}/root2/root3/root4/", ipnsKey).
Query("format", "dag-json"),
Response: Expect().
Status(200).
Headers(
// Header("Cache-Control").
// IsEmpty(),
Response: AllOf(
Expect().
Status(200),
AnyOf(
Expect().Headers(Header("Cache-Control").IsEmpty()),
Expect().Headers(Header("Cache-Control").Matches("public, max-age=*")),
),
),
},
{
Name: "GET for /ipns/ unixfs dir as JSON succeeds",
Request: Request().
Path("/ipns/{{KEY}}/root2/root3/root4/", ipnsKey).
Query("format", "json"),
Response: Expect().
Status(200).
Headers(
// Header("Cache-Control").
// IsEmpty(),
Response: AllOf(
Expect().
Status(200),
AnyOf(
Expect().Headers(Header("Cache-Control").IsEmpty()),
Expect().Headers(Header("Cache-Control").Matches("public, max-age=*")),
),
),
},
{
Name: "GET for /ipns/ file with matching Etag in If-None-Match returns 304 Not Modified",
Expand Down

0 comments on commit f81afb8

Please sign in to comment.