Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gateway): Cache-Control header for UnixFS directories #639

Closed
wants to merge 1 commit into from

Conversation

acejam
Copy link
Contributor

@acejam acejam commented Jul 25, 2024

Cache-Control headers are currently not being returned when viewing the directory index page of a UnixFS directory. This is because rq.ttl returns 0.

For example, the following request path is missing a Cache-Control header: /ipfs/<cid>/

According to the Path Gateway Specification:

Cache-Control: public, max-age=29030400, immutable must be returned for every immutable resource under /ipfs/ namespace.

https://specs.ipfs.tech/http-gateways/path-gateway/#cache-control-response-header

This PR sets the appropriate header.

@acejam acejam requested review from lidel, hacdias and a team as code owners July 25, 2024 21:29

This comment was marked as resolved.

Copy link
Member

@lidel lidel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for raising this.

This is bit more tricky, because HTML listing is quality-of-life improvement for web browsers, and not the actual immutable data.

Generated HTML listing of UnixFS directory is NOT immutable and should not be cached forever.

  • Proper fix for /ipns/ is to implement TTL handling.
  • Proper fix for /ipfs/ may not exist. A fair compromise may be to cache for a week, and also allow for serving stale cache while check for update happens asynchronously. This ensures CDNs serve content fast, but we dont cache generated HTML forever. See proposed value inline.

Would you have time to submit related PRs to

?

We need to update conformance tests before this can be shipped. (CI is currently failing).

gateway/handler_unixfs_dir.go Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
@lidel lidel changed the title Fix: Return immutable Cache-Control headers for UnixFS directories fix(gateway): Cache-Control header for UnixFS directories Jul 26, 2024
@acejam
Copy link
Contributor Author

acejam commented Jul 26, 2024

@lidel gateway-conformance PR here: ipfs/gateway-conformance#218

@lidel
Copy link
Member

lidel commented Jul 29, 2024

Thanks! Had to push some test fixes but your fork does not allow it, so continuing in #643

@lidel lidel closed this Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants