This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
Go to file
Fabien Potencier e3d90db747 bug #22036 Set Date header in Response constructor already (mpdude)
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 https://github.com/symfony/symfony/pull/14912#issuecomment-110105215.

Commits
-------

3a7fa7ede2 Set Date header in Response constructor already
2017-03-22 14:18:49 -07:00
.composer Drop hirak/prestissimo 2016-05-12 07:44:15 -05:00
.github [github] Add a reminder about CHANGELOG.md files 2017-03-06 21:03:23 +01:00
src/Symfony bug #22036 Set Date header in Response constructor already (mpdude) 2017-03-22 14:18:49 -07:00
.editorconfig Add EditorConfig File 2012-06-16 14:08:15 +02:00
.gitignore Add appveyor.yml for C.I. on Windows 2015-08-25 23:41:37 +02:00
.php_cs.dist Merge branch '2.7' into 2.8 2017-01-21 08:53:15 -08:00
.travis.yml [travis] Test with hhvm 3.18 2017-03-08 10:42:29 +01:00
appveyor.yml Merge branch '2.7' into 2.8 2017-01-03 12:26:18 +01:00
CHANGELOG-2.2.md Merge branch '2.2' into 2.3 2013-12-03 15:51:26 +01:00
CHANGELOG-2.3.md updated CHANGELOG for 2.3.42 2016-05-30 10:40:50 +02:00
CHANGELOG-2.4.md updated CHANGELOG for 2.4.9 2014-09-03 11:50:09 +02:00
CHANGELOG-2.5.md updated CHANGELOG for 2.5.10 2015-02-02 10:26:02 +01:00
CHANGELOG-2.6.md updated CHANGELOG for 2.6.10 2015-07-13 11:34:21 +02:00
CHANGELOG-2.7.md updated CHANGELOG for 2.7.25 2017-03-05 17:33:13 -08:00
CHANGELOG-2.8.md updated CHANGELOG for 2.8.18 2017-03-05 19:54:29 -08:00
composer.json Merge branch '2.7' into 2.8 2017-02-18 18:37:18 +01:00
CONTRIBUTING.md Mention the community review guide 2016-12-18 22:02:35 +01:00
CONTRIBUTORS.md update CONTRIBUTORS for 2.7.25 2017-03-05 17:33:23 -08:00
LICENSE updated LICENSE year 2017-01-02 12:30:00 -08:00
phpunit Use PHPUnit 6.0 on PHP 7.* test lines 2017-02-21 14:43:45 +01:00
phpunit.xml.dist use the clock mock for progress indicator tests 2016-03-17 10:19:04 +01:00
README.md Rename StackOverflow to Stack Overflow 2017-03-08 11:34:04 +01:00
UPGRADE-2.1.md Remove aligned '=>' and '=' 2014-10-26 08:30:58 +01:00
UPGRADE-2.2.md Merge branch '2.3' into 2.5 2014-10-01 07:50:18 +02:00
UPGRADE-2.3.md [Doc] Use Markdown syntax highlighting 2014-10-01 07:38:33 +02:00
UPGRADE-2.4.md Updated UPGRADE-2.4.md 2015-06-08 16:44:57 +02:00
UPGRADE-2.5.md Merge branch '2.5' into 2.6 2015-01-05 21:59:13 +01:00
UPGRADE-2.6.md Fix grammar 2014-12-30 09:24:50 +01:00
UPGRADE-2.7.md Update UPGRADE-2.7.md 2016-11-07 10:23:54 +03:00
UPGRADE-2.8.md [DoctrineBridge] Fix deprecation message/documentation of implementing UserProviderInterface using the entity provider 2016-11-17 00:18:19 +01:00
UPGRADE-3.0.md Merge branch '2.7' into 2.8 2017-01-31 22:48:58 +01:00

Symfony is a PHP framework for web applications and a set of reusable PHP components. Symfony is used by thousands of web applications (including BlaBlaCar.com and Spotify.com) and most of the popular PHP projects (including Drupal and Magento).

Installation

Documentation

Community

Contributing

Symfony is an Open Source, community-driven project with thousands of contributors. Join them contributing code or contributing documentation.

Security Issues

If you discover a security vulnerability within Symfony, please follow our disclosure procedure.

About Us

Symfony development is sponsored by SensioLabs, lead by the Symfony Core Team and supported by Symfony contributors.