-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Auto add the cache-control
headers?
#25736
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
Comments
That's because your page is using the session, so that it's different per-user, and thus cannot be shared. |
@nicolas-grekas, Thanks. But I not login my account, I want to shared, Because I need CDN cache my pages, can't be implemented? |
I guess you need to understand where the session is used, and then figure out a way to not call that code. |
@nicolas-grekas I still don't understand the rasoning behind this. Why force those headers in the first place? In eZ Platform, it's possible (and on Symfony 2.8 eZ Platform behaves that way) to have a single HTTP cache for two different users, since eZ Platform varies the cache not by cookie, but by user policies, by using |
Yes, on SF 3.4.3 varnish skipping cache. |
@emodric that's very likely, yet Symfony doesn't know about this logic in eZ. Not sending this header was a bug, on which eZ relied apparently. This should be fixed on eZ side. |
Agreed, but nevertheless, it breaks the way eZ worked for years. Forcing these headers should at least be configurable. |
Symfony should respect HTTP semantics by default, this is not an option IMHO. |
I'd rather say Symfony should first respect what user/developer intended to do with the Response object in his controller. Symfony overriding something user might've explicitly set in his controller is not a good t 8000 hing IMO, without being able to disable it. Is there a standard or RFC specifying that these headers must be set if session cookie is present? |
It's "if session cookie is present", it's "if the session is read". See HTTP RFC. @emodric you should open an issue on eZ really. The behavior here is correct. |
@nicolas-grekas Not looked in depth on this, but when was it introduced? So no matter how you put it, introducing it in patch release sounds like a break. |
That said, I agree on the RFC, however to really follow it we all need to look at this from a system perspective. Where we want this behaviour is from the reverse proxy and out. /cc @dbu |
with FOSHttpCache, we explicitly set cache-control headers. unless you set a response to be cacheable, it will still be no-cache. is the current implementation in the response object preventing the application from explicitly setting cache-control headers or does it merely change defaults when there is a cookie? |
Here is the most recent fix on this, it should give you the answers: #25699 |
@dbu As far as I understand, this prevents and overrides headers set by the app in controllers, no questions asked (presuming session is present and started) |
That's correct, you need a listener registered after the SessionListener to override this behavior. |
ugh. well i think it makes sense in all cases except when we do special things where it does make sense to maybe cache a response. its not "hardcoded" in the Response itself, we can still overwrite it. we could put the FOSHttpCacheBundle listener to in FOSHttpCacheBundle we provide the reverse-proxy-ttl custom header and configuration for varnish / a listener for symfony cache kernel to use that over the cache-control header. that is safer, because all systems after the reverse proxy indeed must not cache this. we should encourage people to only use that for user context caching. we have to check if that header is still used when a response is private. its a tricky thing either way - we do not want unsafe defaults, and want to make it at least difficult to shoot yourself into the foot. i am quite busy atm, if somebody can have a deeper look into it and propose a pull request, please do. |
This could be related #25826 (comment) |
Closing as discussed. |
Could you kindly point us to the relevant RFC sections on this? I cannot find any mention of it in RFC 7234: https://tools.ietf.org/html/rfc7234 |
@teohhanhui all the RFC. It's about what can be cached or not. As soon as a page contains a check based on the session, we cannot assume without external knowledge that it doesn't contain personal data/state. As such the default must be "private". |
8000
I definitely agree about the default. No arguments there. But overriding what the user has explicitly set in their application is going much further than having a good default. |
The default is fine. But this "external knowledge" is exactly the app developer, that says "yes, I know all of that, but the response is still cacheable". Why prevent it then? Default is fine. Forcing it not and might be considered a bug imo. |
If we set the header only if no cache-related headers have been set, it'll greatly reduce the pulling-out of hair for many people. 😄 |
Using the session without noticing is super easy: just dump flash messages in your layout and done. I would not consider that the explicitly set "public" C-C is enough to consider it not a mistake when the session has also been used. The current logic considers this as a conflict and defaults to the safest. If you really want to push session-related state into shared caches, you are required to do extra work yes. That's expected to me. |
I don't argue against the intention, as in a general case it is very likely that caching a response that is using the session will be a bug. I guess as workaround a custom response listener and passing the cache config in However – do we log anything in case we are overriding explicitly set cache headers? Might reduce the amount of wtf in this case. |
The correct thing to do is to let the user opt-in to this stricter check, and we could deprecate not using the strict mode, to be removed in the next major version. |
@nicolas-grekas I did miss it, indeed. That looks perfect, so 👍 all around. Sorry for the noise. |
I am using just "http foundation 4.1" and "twig 2.5" packages. They are creating duplicated response headers like that: |
Yes, especially the 3.4 hack as described by @yellow1912 |
You can add this header'Symfony-Session-NoAutoCacheControl' in the response to force to use your Cache-Control : |
Uh oh!
There was an error while loading. Please reload this page.
hello everybody,
I need my CDN service cache my website, so I set
then the
cache-control
header iscache-control:max-age=0, must-revalidate, private, s-maxage=3600
It contains the
max-age=0, must-revalidate, private
is not what I want.What should I do?
Because the response header, so my CDN cannot cache my pages.
thx.
The text was updated successfully, but these errors were encountered: