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: handle missing vary header values #4031

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

gurgunday
Copy link
Contributor

fixes: #3959

test/types/cache-interceptor.test-d.ts Fixed Show fixed Hide fixed
test/types/cache-interceptor.test-d.ts Fixed Show fixed Hide fixed
test/utils/cache.js Fixed Show fixed Hide fixed
test/utils/cache.js Fixed Show fixed Hide fixed
Comment on lines +34 to +36
for (const key of Object.keys(opts.headers)) {
headers[key.toLowerCase()] = opts.headers[key]
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we don't do this, we lose case insensitivity in the cache unfortunately and the unit test fails

Copy link
Member

Choose a reason for hiding this comment

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

why? I thought headers name were already lowercased elsewhere?

Copy link
Contributor Author

@gurgunday gurgunday Jan 28, 2025

Choose a reason for hiding this comment

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

The keys in the cache are lowercase but opts.headers keys are not

In the last request of the unit test we pass Accept-Encoding and it's value in the opts object is still Accept-Encoding, so the cache thinks the third request still doesn't have an accept-encoding property and uses the stored value

Copy link
Contributor Author

@gurgunday gurgunday Jan 28, 2025

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, the response headers are already lowercased once parsed, but we do not handle the ones passed by the call to dispatch; those can be potentially upper cased

test/issue-3959.js Outdated Show resolved Hide resolved
test/utils/cache.js Show resolved Hide resolved
Comment on lines +34 to +36
for (const key of Object.keys(opts.headers)) {
headers[key.toLowerCase()] = opts.headers[key]
}
Copy link
Member

Choose a reason for hiding this comment

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

why? I thought headers name were already lowercased elsewhere?

gurgunday and others added 2 commits January 28, 2025 08:28
Co-authored-by: Matteo Collina <[email protected]>
Co-authored-by: Matteo Collina <[email protected]>
Comment on lines +34 to +36
for (const key of Object.keys(opts.headers)) {
headers[key.toLowerCase()] = opts.headers[key]
}
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, the response headers are already lowercased once parsed, but we do not handle the ones passed by the call to dispatch; those can be potentially upper cased

test/issue-3959.js Outdated Show resolved Hide resolved
@gurgunday gurgunday requested a review from mcollina January 28, 2025 19:00
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.

Response headers vary: Accept-Encoding is stopping undici from caching the http request
3 participants