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

Better caching #794

Merged
merged 3 commits into from
Dec 6, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/template_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ impl<'r> Responder<'r> for Ructe {
let etag = format!("{:x}", hasher.finish());
if r.headers()
.get("If-None-Match")
.any(|s| s[1..s.len() - 1] == etag)
// This check matches both weak and strong ETags
// NGINX (and maybe other software) sometimes sends ETags with a
// "W/" prefix, that we ignore here
.any(|s| s[1..s.len() - 1] == etag || s[3..s.len() - 1] == etag)
Copy link
Contributor

Choose a reason for hiding this comment

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

can one of you two explain what this does?

Copy link
Contributor

Choose a reason for hiding this comment

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

this should probably get it's comment actually.
We send Etags as 'some_tag', the old match does not verify the ', but check that whatever in-between is the right tag. Nginx apparently change the Etag to W/'some_tag', W/ indicating it's a weak Etag, the content may not be byte-equal, but is semantically identical (which is imo a shitty but correct interpretation of the RFC, as Nginx send compressed data)

The new match ignore that W/ saying it's a weak etag and so match if Nginx modified the header we sent previously

Comment might looks like : // if a strong or weak etag matches

{
Response::build()
.status(Status::NotModified)
Expand Down