- Notifications
You must be signed in to change notification settings - Fork22.1k
Response etags to always be weak: Prefixed 'W/' to value returned by Act...#17573
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
guilleiguaran commentedNov 10, 2014
/cc@jeremy |
chancancode commentedNov 10, 2014
Nice! If we make this more conservative, we can probably get away with sneaking this into 4.2:
This seems like an overall improvement to the situation and a good halfway point. Ideally though, we should also figure out the final API we would like to achieve with this (though I'm not sure if something like that is still appropriate for 4.2 at this time)...
With the current API, I'm not sure what's the best way to achieve point 2, and I'd love to hear ideas 😄 |
egilburg commentedNov 10, 2014
"Sorry, Diff contents are not available for this pull request." First time I'm seeing this, why? |
rafaelfranca commentedNov 10, 2014
Good question. I'm seeing this too. |
chancancode commentedNov 10, 2014
Yeah, I have no idea, I had to pull the branch locally to check the diff |
guilleiguaran commentedNov 10, 2014
Same here, I checked the changes inhttps://github.com/rails/rails/pull/17573.diff |
zerothabhishek commentedNov 11, 2014
[Sorry about the late response.] I'm a bit of a noob here, but from what I've seen in the code, our current behavior resembles weak etags more. Even though the etags emitted look strong. I could not find any code that actually creates an etag based off the entire response body. Here's an example to illustrate - In the classic blog post application, we can write the And then here's what we see from the browser -
The same happens when using the I too feel that strong etags are important for cases like |
fabn commentedAug 25, 2015
I'm having a lot of cache misses because of this behavior. I'm using nginx as reverse proxy and when a page is requested with
As a quick alternative theetag_matches? method can be changed to strip any I'm going to tryrails_weak_etags middleware to see if it solves my issues. |
felixbuenemann commentedSep 18, 2015
LGTM. What's missing to get this merged? I don't think there needs to be a configuration options, because the way etags are calculated is already weak validation and Rack::ETag even weakens it's strong etags (a body digest is considered a strong validator based on RFC 7232 Section 2.1, while determining the etag from arbitrary data is considered a weak validator). The current problem without this patch is that NGINX weakens strong ETags when it changes the content encoding (gzip). So right now Another approach would be to consider a weakened etag equivalent to the strong etag sent by action dispatch (but I think sending weak etags as proposed here is the correct approach): moduleActionDispatchmoduleHttpmoduleCachemoduleRequestNORMALIZE_ETAG=/^(?:W\/)?\"|\"$/.freezedefif_none_match_etags(if_none_match ?if_none_match.split(/\s*,\s*/) :[]).collectdo |etag|etag.gsub(NORMALIZE_ETAG,"")endenddefetag_matches?(etag)ifetagetag=etag.gsub(NORMALIZE_ETAG,"")if_none_match_etags.include?(etag)endendendendendend I'm currently using the above code as a monkey patch with rails 4.2.4 to fix If-None-Match on NGINX 1.8. |
fabn commentedSep 19, 2015
I installedrails_weak_etags and everything work like a charm, no monkey patch needed, just a middleware. In any case it would be very nice to have this merged (and backported to rails 4.x) |
bboe commentedNov 20, 2015
Is there any status update on this issue? The |
arthurnn commentedDec 6, 2015
FWIW the last big rails projects I worked on, they all had a middleware to do something like this. |
maclover7 commentedJan 10, 2016
Please rebase. |
zerothabhishek commentedJan 11, 2016
Sorry I was a little out of touch off this. Allow me a bit to rebase. |
…tionDispatch::Http::Cache::Response#etag= such that etags set in fresh_when and stale? are weak. Forrails#17556.
zerothabhishek commentedJan 20, 2016
Rebased. |
jeremy commentedJan 20, 2016
Looks good to merge@chancancode. We'll need a guide update and some mention of how to use strong ETags now (set the header manually, I presume). |
Response etags to always be weak: Prefixed 'W/' to value returned by Act...
chancancode commentedJan 20, 2016
Thanks everyone for working on this, sorry it took so long! I opened a new issue to track the remaining work:#23148 |
zerothabhishek commentedJan 21, 2016
Thanks@chancancode and others. Should this be back-ported to 4.2 as well? |
chancancode commentedJan 21, 2016
This is a new feature/breaking change, so we cannot. We only backport bug fixes. |
sfcgeorge commentedApr 4, 2016
Thanks. Commenting for future Rails 4.2 users on CloudFlare because CF (silently) automatically convert strong ETags to weak ETags by prepending W/ in the header. Googling W/ is pretty ineffective and CloudFlare doesn't document this behaviour so hopefully this comment helps visibility. TLDR use Rails 5 or therails_weak_etags gem. |
...ionDispatch::Http::Cache::Response#etag such that etags set in fresh_when and stale? are weak.Fixes#17556.