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: set cache-control header correctly #19

Merged
merged 9 commits into from Mar 21, 2024
Merged

fix: set cache-control header correctly #19

merged 9 commits into from Mar 21, 2024

Conversation

2color
Copy link
Member

@2color 2color commented Mar 13, 2024

Description

Set the cache-control cache header conditionally for immutable responses.

For mutable responses, i.e. IPNS and DNSLink, the correct max-age in the cache-control would be the TTL of the record . Determining the right TTL would require modifying the parseUrlString method and a few of the methods to also return TTL and is outside the scope of this PR. Should be ok initially to just to omit the header given that Kubo does this.

fixes #17

Notes & open questions

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation if necessary (this includes comments as well)
  • I have added tests that prove my fix is effective or that my feature works

@2color
Copy link
Member Author

2color commented Mar 14, 2024

As discussed in Helia WG:

Until we change the APIs to return the TTL for DNSLink and IPNS records, we should default to a 5 minute max-age. This is in line with Kubo (see ipfs/boxo#329 (comment))

@achingbrain
Copy link
Member

achingbrain commented Mar 14, 2024

Related - ipfs/helia#471 - exposes the resolved IPNS record and DNSLink Answers to IPNS callers to allow accurately setting this field.

Turns out it's non-breaking since we already return an object so it's a simple thing to add.

2color and others added 2 commits March 15, 2024 12:37
* feat: implement new ipns record&answer properties

* fix: parseUrlString response includes defined ttl, set ttl if ipnsCached

* test: fix firefox failure

* feat: support http range header (#10)

* chore: limit body parameters to the types used

* chore: add response-header helper and tests

* feat: add range header parsing support

* feat: verified-fetch supports range-requests

* test: fix dns test asserting test failure since we are catching it now

* fix: return 500 error when streaming unixfs content throws

* fix: cleanup code and unexecuting tests hiding errors

* chore: some cleanup and code coverage

* tmp: most things working

* fix: stream slicing and test correctness

* chore: fixed some ByteRangeContext tests

* test: add back header helpers

* fix: unixfs tests are passing

* fix: range-requests on raw content

* feat: tests are passing

moved transform stream over to https://github.com/SgtPooki/streams

* chore: log string casing

* chore: use 502 response instead of 500

* chore: use libp2p/interface for types in src

* chore: failing to create range resp logs error

* chore: Apply suggestions from code review

* chore: fix broken tests from github PR patches (my own)

* chore: re-enable stream tests for ByteRangeContext

* chore: clean up getBody a bit

* chore: ByteRangeContext getBody cleanup

* chore: apply suggestions from code review

Co-authored-by: Alex Potsides <alex@achingbrain.net>

* fix: getSlicedBody uses correct types

* chore: remove extra stat call

* chore: fix jsdoc with '*/'

* chore: fileSize is public property, but should not be used

* test: fix blob comparisons that broke or were never worjing properly

* chore: Update byte-range-context.ts

Co-authored-by: Alex Potsides <alex@achingbrain.net>

* chore: jsdoc cleanup

* Revert "chore: fileSize is public property, but should not be used"

This reverts commit 46dc133.

* chore: jsdoc comments explaining .fileSize use

* chore: isRangeRequest is public

* chore: getters/setters update

* chore: remove unnecessary _contentRangeHeaderValue

* chore: ByteRangeContext uses setFileSize and getFileSize

* chore: remove .stat changes that are no longer needed

---------

Co-authored-by: Alex Potsides <alex@achingbrain.net>

* chore(release): 1.2.0 [skip ci]

## @helia/verified-fetch [1.2.0](https://github.com/ipfs/helia-verified-fetch/compare/@helia/verified-fetch-1.1.3...@helia/verified-fetch-1.2.0) (2024-03-15)

### Features

* support http range header ([#10](#10)) ([9f5078a](9f5078a))

### Trivial Changes

* fix build ([#22](#22)) ([01261fe](01261fe))

* chore(release): 1.7.0 [skip ci]

## @helia/verified-fetch-interop [1.7.0](https://github.com/ipfs/helia-verified-fetch/compare/@helia/verified-fetch-interop-1.6.0...@helia/verified-fetch-interop-1.7.0) (2024-03-15)

### Dependencies

* **@helia/verified-fetch:** upgraded to 1.2.0

* chore: apply pr comments

* fix: some ipns ttl precision cleanup

---------

Co-authored-by: Alex Potsides <alex@achingbrain.net>
Co-authored-by: semantic-release-bot <semantic-release-bot@martynus.net>
@SgtPooki
Copy link
Member

i'll get this merged in shortly.

Copy link
Member

@SgtPooki SgtPooki left a comment

Choose a reason for hiding this comment

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

self review.

@SgtPooki
Copy link
Member

@2color if you're good with the changes here, we should merge it.

Copy link
Member Author

@2color 2color left a comment

Choose a reason for hiding this comment

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

LGTM with the exception of the way we handle IPNS TTL which I think might be worth double checking before we entrench a bug further.

Either way, thanks for helping get this past the finish line 🏁🙏

@SgtPooki SgtPooki mentioned this pull request Mar 21, 2024
3 tasks
@SgtPooki SgtPooki merged commit 114f3a4 into main Mar 21, 2024
19 checks passed
@SgtPooki SgtPooki deleted the fix/cache-header branch March 21, 2024 02:44
github-actions bot pushed a commit that referenced this pull request Mar 21, 2024
## @helia/verified-fetch [1.3.0](https://github.com/ipfs/helia-verified-fetch/compare/@helia/verified-fetch-1.2.1...@helia/verified-fetch-1.3.0) (2024-03-21)

### Features

* abort signals are respected ([#26](#26)) ([30148fe](30148fe))

### Bug Fixes

* set cache-control header correctly ([#19](#19)) ([114f3a4](114f3a4)), closes [#17](#17) [#23](#23) [#10](#10)
Copy link

🎉 This PR is included in version 1.3.0 🎉

The release is available on npm package (@latest dist-tag)

Your semantic-release bot 📦🚀

Copy link

🎉 This PR is included in version 1.9.0 🎉

The release is available on npm package (@latest dist-tag)

Your semantic-release bot 📦🚀

Copy link

github-actions bot commented May 9, 2024

🎉 This PR is included in version 1.0.0 🎉

The release is available on npm package (@latest dist-tag)

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cache-Control headers for mutable resources are wrong
4 participants