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

Prefer lower case headers. #3

Merged
merged 1 commit into from
Feb 22, 2022
Merged

Prefer lower case headers. #3

merged 1 commit into from
Feb 22, 2022

Conversation

ioquatix
Copy link
Member

See rack/rack#1812 for more details.

@ioquatix ioquatix force-pushed the lowercase-headers branch 7 times, most recently from 2e1a8cb to 6efa762 Compare February 22, 2022 10:39
@ioquatix ioquatix merged commit 0077ef9 into main Feb 22, 2022
@ioquatix ioquatix deleted the lowercase-headers branch February 22, 2022 10:50
@@ -34,11 +34,11 @@ def lookup(request, entity_store)

# find a cached entry that matches the request.
env = request.env
match = entries.detect{ |req,res| requests_match?((res['Vary'] || res['vary']), env, req) }
match = entries.detect{ |req,res| requests_match?((res['vary'] || res['vary']), env, req) }
Copy link
Contributor

Choose a reason for hiding this comment

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

Was it intentional to check the same value twice? Before, it was checking if there was a match for both the Capitalized Vary and the lowercase vary. But now that everything is lowercase, we only need to check one of them, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, that's correct, do you have time to submit a PR fixing this? Thanks!

requests_match?(vary, env, stored_env)
end

headers = persist_response(response)
headers.delete('Age')
headers.delete('age')
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar comment here. Is it necessary to delete the same header twice?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, if you can submit a PR to fix this, please do! Thanks!

monfresh pushed a commit to monfresh/rack-cache that referenced this pull request Sep 29, 2022
In PR rack#3, headers were converted to lowercase, which resulted in
the same action being performed twice. This PR removes those
duplicate actions.
ioquatix pushed a commit that referenced this pull request Jul 18, 2023
In PR #3, headers were converted to lowercase, which resulted in
the same action being performed twice. This PR removes those
duplicate actions.

Co-authored-by: Moncef Belyamani <moncef@example.com>
cutalion added a commit to cutalion/rack-cache that referenced this pull request Dec 23, 2023
return nil if match.nil?

_, res = match
if body = entity_store.open(res['X-Content-Digest'])
if body = entity_store.open(res['x-content-digest'])

Choose a reason for hiding this comment

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

With this change, after deploying with the updated version of this gem, you can end up in a scenario where a long-term cached item still exists in the metastore with the capitalized header, but when it goes to get the key here using the lowercase header, it returns nil, and passes nil to the open method, resulting in an exception further down, and since on lookups on exceptions, it calls pass instead of fetch, it isn't going to store the response with the updated header and will continue to hit the error

Could check here for both cases, but I think another fine option is just letting people know they should flush their cache if they're upgrading from an earlier version to this one or later.

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you mind creating an issue for this?

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.

None yet

3 participants