-
Notifications
You must be signed in to change notification settings - Fork 155
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
Gateway returns object that did not change instead of 304 (Not Modified) #848
Comments
@vstax Thanks for reporting. It turned out that we have If-Modified-Since aware code block available only if cache.http_cache = true in leo_gateway.conf as below. Instead it should be available regardless of its setting.
Do you think we should implement If-Non-Match aware in addition to If-Modified-Since one? |
@mocchira I see, thank you for identifying the problem. I read somewhere in documentation or issues that "http cache" mode in gateway isn't much used / tested so never tried enabling it.
As I understand it, If-Modified-Since is HTTP/1.0 legacy, and fully HTTP/1.1 complaint client and server are supposed to use ETag and If-None-Match instead. It works more precisely and solves several problems of If-Modified-Since like avoiding false positive when object was updated with the same copy (new Last-Modified date but same ETag). Squid supports ETag and If-None-Match for several years (since around HTTP/1.1 support was merged, i.e. probably 3.0 or 3.2) and looking at documentation, Varnish does as well. Most CDNs use If-None-Match too nowadays, I think. So yes, it probably would be nice to have If-None-Match support. It's more tricky header to support properly, though (like RFC and that Varnish documentation show, there are some special cases like passing multiple ETags or "*"). |
Right. we don't recommend to enable it.
Thanks. we will also support part of If-None-Match (except some special cases). |
It turned out that this long standing issue #216 prevents us from implementing If-None-Match against objects multipart-uploaded properly so we will implement only If-Modified-Since for now. |
@mocchira Another problem is that "Cache-Control" (added through headers option) isn't present in "304" response. It must be present according to RFC (clients want it to update internal date for next expiration), here is example of what happens when it's not there: https://stackoverflow.com/questions/1587667/should-http-304-not-modified-responses-contain-cache-control-headers In practice, squid isn't affected by both problems (it keeps original max-age), but I think it's just some workaround implemented in there and fixing at least missing "Cache-Control" is important. |
@vstax Thanks for checking and reporting the problems. both should be fixed so I will update PR for the Cache-Control one. Since Content-Length one needs the fix on cowboy, I will send another PR on leo-project/cowboy. |
Updated #865 to fix Cache-Control problem. |
Sent leo-project/cowboy#2 to fix Content-Length problem. |
@mocchira Both issues are fixed and everything seems correctly now - thank you! Just one note, unrelated to this ticket, but since we're at it: apparently, according to RFC, Content-Length should be omitted in case of "204" reply as well:
Actually this is even stricter requirement than for 304, as RFC allows to have Content-Length for 304 if it matches the original object's Content-Length but forbids it for 204 in all cases. 204 reply is sent for delete, delete bucket, abort MU operations:
Maybe it's a good idea to extend removal of Content-Length to 204 as well to confirm with RFC. I have no idea if having that header can cause any real problems, though. If If-None-Match support won't be implemented as part of this ticket, it's OK to close this? |
Thanks for pointing this out. I will file as another issue and after we confirm that all test suites for aws-sdk we've supported passed, we will patch responding 204 without Content-Length.
Yes please. |
I'm not 100% sure this is gateway problem and not configuration problem on my side - please advise if it is.
I have custom http headers configured as follows:
I access gateway (S3 mode) through squid. Squid caches objects for an hour. When an hour passes, it asks gateway if the object is changed by specifying "If-Modified-Since" (check through date) and "If-None-Match" (check through ETag) headers. However, instead of returning 304 gateway sends the whole data.
Request:
Reply:
Since client sends
If-Modified-Since: Sat, 23 Sep 2017 04:30:16 GMT
and server knows thatLast-Modified: Sat, 23 Sep 2017 04:30:16 GMT
, this means that If-Modified-Since evaluates to false (object wasn't modified after Modified-Since date), and according to RFC it must send 304 (Not Modified) without data instead of 200 with data: https://tools.ietf.org/html/rfc7232#section-3.3Alternatively, if server knows how to work with ETag and If-None-Match header, it must check that one instead of If-Modified-Since. Here we have
If-None-Match: "ab8d12fb796ea4c868f5c1fca67abba4
from client andETag: "ab8d12fb796ea4c868f5c1fca67abba4"
on server, which means that objects match, condition evaluates to false and according to RFC it must sent 304 as well (https://tools.ietf.org/html/rfc7232#section-3.2).The text was updated successfully, but these errors were encountered: