-
Notifications
You must be signed in to change notification settings - Fork 567
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
Response headers vary: Accept-Encoding
is stopping undici from caching the http request
#3959
Comments
Many CDNs will always return the Same for GitHub RAW. GitHub RAW always returns |
Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests. |
vary: Accept-Encoding
is stopping undici from caching the http requestvary: Accept-Encoding
is stopping undici from caching the http request
I am not sure of the proper way to fix this: We could simply ignore any missing request headers (those undici are not sending) when parsing the Or we could use a placeholder for those missing request headers, but the placeholder couldn't be a symbol because it can't be properly serialized for storing. |
What does the standard say? cc @flakey5 |
So I think we can ignore it if it's present in the vary header but isn't actually present in the request. The fix would be removing this else block: Lines 273 to 275 in 3eeeeb7
I don't think cache poisoning would be a problem, but it is noteworthy that this change would mean that these two requests considered the same: GET / HTTP/1.1
Host: localhost
HTTP/1.1 200 OK
Date: asd
Vary: a
asd123 GET / HTTP/1.1
Host: localhost
HTTP/1.1 200 OK
Date: asd
asd123
It shouldn't, cache stores get the result of the parsed vary header which maps the header's name to the header's value. The store should be using it to find the request to use. If we ignore a header, it won't be in this mapping meaning it shouldn't be taken into consideration when deciding which response to use. Regardless, that is definitely something that needs be covered in a unit test if we go down this road. |
Wdyt of using |
I am still not sure if this is the path we should take. I am not sure how to properly implement this now.
This should work as long as someone doesn't ignore the typescript definitions and passes a |
Bug Description
I was trying to try out undici cache with the following code snippets:
However, I noticed that the request is never cached.
Reproducible By
See code snippet above.
Expected Behavior
The request should be cached and the
fetch 2
should happen "instantly".Environment
Node.js v22.11.0 on Darwin
Additional context
I noticed that
https://easylist.to/easylist/easylist.txt
is returning theVary: Accept-Encoding
response header regardless of whetherAccept-Encoding
is included in the request header. This causes undici to panic because undici doesn't expectAccept-Encoding
to be included in thecacheKey
:undici/lib/handler/cache-handler.js
Lines 133 to 137 in 2c36442
cc @flakey5
The text was updated successfully, but these errors were encountered: