Skip to content
New issue

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

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

Already on GitHub? # to your account

feat: cache etag support #3758

Merged
merged 5 commits into from
Nov 18, 2024
Merged

feat: cache etag support #3758

merged 5 commits into from
Nov 18, 2024

Conversation

flakey5
Copy link
Member

@flakey5 flakey5 commented Oct 21, 2024

Re http caching, adds support for etags for when we need to revalidate a cached response.

No breaking changes to the public api. the etag property is nullable so a cache store could just not implement it and it will be fine. However, I did add it to the tests as if it was required just so we can ensure the builtin cache stores fully support the behavior.

This only checks if the etag exists in the response's headers and ignores it if it's in the trailers for simplicity sakes (as allowed by the spec in 8.8.3)

Closes #3718

@mcollina
Copy link
Member

I think this is a bit too light on tests, and I'm not sure if this implementation is correct.

Can you add some tests where the response is a 304 thanks to if-none-match?

@SukkaW
Copy link
Contributor

SukkaW commented Oct 24, 2024

I think this is a bit too light on tests, and I'm not sure if this implementation is correct.

Can you add some tests where the response is a 304 thanks to if-none-match?

Also, we could test how undici responds to different server implementations. I myself have run into situations when locally stored strong ETag matches the server-sent one yet the server is returning the same ETag with 200 instead of 304.

@flakey5 flakey5 force-pushed the flakey5/3718 branch 2 times, most recently from d914909 to 9eeff6c Compare November 17, 2024 19:01
lib/util/cache.js Outdated Show resolved Hide resolved
lib/util/cache.js Show resolved Hide resolved
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@mcollina
Copy link
Member

@flakey5 this now conflicts

Signed-off-by: flakey5 <73616808+flakey5@users.noreply.github.com>
flakey5 and others added 4 commits November 18, 2024 11:34
Co-authored-by: Carlos Fuentes <me@metcoder.dev>
Signed-off-by: flakey5 <73616808+flakey5@users.noreply.github.com>
Signed-off-by: flakey5 <73616808+flakey5@users.noreply.github.com>
Signed-off-by: flakey5 <73616808+flakey5@users.noreply.github.com>
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@mcollina mcollina merged commit a73fd09 into nodejs:main Nov 18, 2024
36 checks passed
@github-actions github-actions bot mentioned this pull request Dec 3, 2024
This was referenced Dec 16, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Easier way to attach ETag to If-None-Match after #3562
6 participants