-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[HttpFoundation] HttpCache doesn't refresh stale responses containing an ETag #19390
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
Labels
Comments
This seems to be a duplicate of #6746. |
nicolas-grekas
added a commit
that referenced
this issue
Jul 25, 2016
…ontaining an ETag (maennchen) This PR was merged into the 2.7 branch. Discussion ---------- [2.7] [HttpFoundation] HttpCache refresh stale responses containing an ETag | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? |no | BC breaks? |no | Deprecations? |no | Tests pass? | yes | Fixed tickets | #19390, #6746 | License | MIT | Doc PR | This PR is the replacement of #19391, which points at the wrong branch. Commits ------- 96df6b9 [HttpFoundation] HttpCache refresh stale responses containing an ETag
This was referenced Mar 17, 2017
fabpot
added a commit
that referenced
this issue
Mar 22, 2017
This PR was squashed before being merged into the 2.8 branch (closes #22036). Discussion ---------- Set Date header in Response constructor already | Q | A | ------------- | --- | Branch? | 2.8 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | Setting the `Date` header in the `Response` constructor has been removed in #14912 and changed to a more lazy approach in `getDate()`. That way, methods like `getAge()`, `getTtl()` or `isFresh()` cause side effects as they eventually call `getDate()` and the Request "starts to age" once you call them. I don't know if this would be a nice test, but current behaviour is ```php $response = new Response(); $response->setSharedMaxAge(10); sleep(20); $this->assertTrue($response->isFresh()); sleep(5); $this->assertTrue($response->isFresh()); sleep(5); $this->assertFalse($response->isFresh()); ``` A particular weird case is the `isCacheable()` method, because it calls `isFresh()` only under certain conditions, like particular status codes, no `ETag` present etc. This symptom is also described under "Cause of the problem" in #19390, however the problem is worked around there in other ways. So, this PR suggests to effectively revert #14912. Additionally, I'd like to suggest to move this special handling of the `Date` header into the `ResponseHeaderBag`. If the `ResponseHeaderBag` guards that we always have the `Date`, we would not need special logic in `sendHeaders()` and could also take care of #14912 (comment). Commits ------- 3a7fa7e Set Date header in Response constructor already
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Problem
HttpCache doesn't refresh stale responses containing an
ETag
and is also not able to increment theAge
header of the cached response.Affected Version
I tested the Problem on
v3.1
, but it seems to be around since a long time.Scenarios
Scenario with an
ETag
1st Call, Cleared Cache:
2nd Call after a few seconds (not the
Age
which is still 0):The cache will not expire and the response will never be refreshed.
Scenario without an
ETag
1st Call, Cleared Cache:
2nd Call after a few seconds (not the
Age
which increments):Cause of the Problem
The
Date
header of the original request is set by accident by calling this function:https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php#L426
isCacheable
will set set date by callingisFresh
,getTtl
,getAge
,getDate
. This however does not happen if there is aETag
header.Solution
Instead of relying on a date header which may be set by accident by a getter method, the date should explicitly be set for all cached responses. I'd propose to add the
Date
header if not already set in the methodHttpCache::store
.https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php#L583
Workaround for now
The text was updated successfully, but these errors were encountered: