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

[http-cache] follow up #3733

Merged
merged 9 commits into from
Oct 15, 2024
Merged

[http-cache] follow up #3733

merged 9 commits into from
Oct 15, 2024

Conversation

Uzlopak
Copy link
Contributor

@Uzlopak Uzlopak commented Oct 14, 2024

follow up of http-cache pr

@Uzlopak Uzlopak force-pushed the followup-http-cache branch from 08bfb82 to c65844d Compare October 14, 2024 19:19
@Uzlopak Uzlopak requested review from ronag and metcoder95 and removed request for ronag October 14, 2024 20:07
@@ -75,14 +75,14 @@ class CacheHandler extends DecoratorHandler {
)

if (
UNSAFE_METHODS.includes(this.#req.method) &&
!this.#methods.includes(this.#requestOptions.method) &&
Copy link
Contributor Author

Choose a reason for hiding this comment

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

WHy did we check for unsafe methods? this whole if condition seems actually kind of dubious.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@flakey5

The invalidation logic is kind of strange. Also what is the point of passing methods, when they are ignored anyway? So I guess actually methods would have been an array of safe methods?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A cache MUST invalidate the target URI (Section 7.1 of [HTTP]) when it receives a non-error status code in response to an unsafe request method (including methods whose safety is unknown).

So I guess my proposed change should be right, as the passed methods will be considered safe methods. Especially in regard of the last sentence in the spec, that methods whose safety is unknown is also covered.

Comment on lines -38 to -39
// Safe methods the user wants and unsafe methods
const methods = [...globalOpts.methods, ...UNSAFE_METHODS]
Copy link
Contributor Author

@Uzlopak Uzlopak Oct 14, 2024

Choose a reason for hiding this comment

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

why did we "mixed" with unsafe methods?

this would result in caching unsafe requests

Copy link
Member

@flakey5 flakey5 Oct 15, 2024

Choose a reason for hiding this comment

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

this allows requests with unsafe methods to get to the cache handler, where they'll cause a cache purge if the response is a success

@Uzlopak Uzlopak requested a review from mcollina October 14, 2024 20:48
@Uzlopak
Copy link
Contributor Author

Uzlopak commented Oct 14, 2024

@flakey5 PTAL

@Uzlopak Uzlopak changed the title followup http-cache [http-cache] follow up Oct 14, 2024
@Uzlopak Uzlopak merged commit 68107da into main Oct 15, 2024
38 checks passed
@Uzlopak Uzlopak deleted the followup-http-cache branch October 15, 2024 21:55
flakey5 added a commit to flakey5/undici that referenced this pull request Oct 16, 2024
Fixes bug introduced in nodejs#3733 where unsafe methods no longer make it to
the cache handler and cause a cache purge for an origin.

Also removes a duplicate test file.

Signed-off-by: flakey5 <73616808+flakey5@users.noreply.github.com>
Uzlopak pushed a commit that referenced this pull request Oct 19, 2024
* fix: unsafe methods not causing cache purge

Fixes bug introduced in #3733 where unsafe methods no longer make it to
the cache handler and cause a cache purge for an origin.

Also removes a duplicate test file.

Signed-off-by: flakey5 <73616808+flakey5@users.noreply.github.com>

* Update cache.js

* extend test to check that safe methods we're not caching don't purge the
cache

Signed-off-by: flakey5 <73616808+flakey5@users.noreply.github.com>

* code review

Signed-off-by: flakey5 <73616808+flakey5@users.noreply.github.com>

---------

Signed-off-by: flakey5 <73616808+flakey5@users.noreply.github.com>
@github-actions github-actions bot mentioned this pull request Dec 3, 2024
@github-actions github-actions bot mentioned this pull request Dec 16, 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.

3 participants