Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[HttpKernel] Fix Apache mod_expires Session Cache-Control issue#33487

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

Merged
fabpot merged 1 commit intosymfony:3.4frompbowyer:patch-1
Sep 8, 2019
Merged

[HttpKernel] Fix Apache mod_expires Session Cache-Control issue#33487

fabpot merged 1 commit intosymfony:3.4frompbowyer:patch-1
Sep 8, 2019

Conversation

@pbowyer
Copy link
Contributor

@pbowyerpbowyer commentedSep 6, 2019
edited
Loading

QA
Branch?3.4 for bug fixes
Bug fix?yes
New feature?no
BC breaks?no
Deprecations?no
Tests pass?yes
LicenseMIT

Apaches'smod_expires is a widely used module to set HTTP caching headers. It allows you to set a default cache lifetime as well as lifetimes by mime_type.

When an application server has set aCache-Control header, mod_expires ignores this and sets its own, resulting in duplicateCache-Control headers and conflicting information. It does thisunless the application server sets anExpires header, in which case mod_expires does nothing. This is documented on the link above:

When theExpires header is already part of the response generated by the server, for example when generated by a CGI script or proxied from an origin server, this module does not change or add anExpires orCache-Control header.

Symfony automatically sets aCache-Control header if a session exists. This patch adds anExpires header to ensure it's respected by mod_expires.

Example 1

With the following Apache config:

<IfModulemod_expires.c>ExpiresActiveonExpiresDefault                                      "access plus1 month"</IfModule>

The HTTP response headers are:

Without the patch

HTTP/1.1 200 OKDate: Fri, 06 Sep 2019 08:02:02 GMTServer: Apache/2.4.37 (Ubuntu)Cache-Control: max-age=0, must-revalidate, privateCache-Control: max-age=2592000Expires: Sun, 06 Oct 2019 08:02:00 GMTVary: Accept-EncodingContent-Encoding: gzipContent-Length: 13099Connection: closeContent-Type: text/html; charset=UTF-8

With the patch

HTTP/1.1 200 OKDate: Fri, 06 Sep 2019 08:21:34 GMTServer: Apache/2.4.37 (Ubuntu)Cache-Control: max-age=0, must-revalidate, privateExpires: Fri, 06 Sep 2019 08:21:34 GMTVary: Accept-EncodingContent-Encoding: gzipContent-Length: 13098Connection: closeContent-Type: text/html; charset=UTF-8

Example 2

With the following Apache config:

<IfModulemod_expires.c>ExpiresActiveonExpiresDefault                                      "access plus1 month"ExpiresByTypetext/html                             "access plus0 seconds"</IfModule>

Without the patch

HTTP/1.1 200 OKDate: Fri, 06 Sep 2019 08:18:40 GMTServer: Apache/2.4.37 (Ubuntu)Cache-Control: max-age=0, must-revalidate, privateCache-Control: max-age=0Expires: Fri, 06 Sep 2019 08:18:39 GMTVary: Accept-EncodingContent-Encoding: gzipContent-Length: 13099Connection: closeContent-Type: text/html; charset=UTF-8

With the patch

HTTP/1.1 200 OKDate: Fri, 06 Sep 2019 08:20:40 GMTServer: Apache/2.4.37 (Ubuntu)Cache-Control: max-age=0, must-revalidate, privateExpires: Fri, 06 Sep 2019 08:20:40 GMTVary: Accept-EncodingContent-Encoding: gzipContent-Length: 13100Connection: closeContent-Type: text/html; charset=UTF-8

@pbowyerpbowyer changed the titleFix Apache mod_expires Cache-Control issueFix Apache mod_expires Session Cache-Control issueSep 6, 2019
@nicolas-grekasnicolas-grekas added this to the4.3 milestoneSep 6, 2019
@nicolas-grekas
Copy link
Member

That's for 3.4, right? Could you please add a test case also?

@nicolas-grekasnicolas-grekas changed the titleFix Apache mod_expires Session Cache-Control issue[HttpKernel] Fix Apache mod_expires Session Cache-Control issueSep 7, 2019
@pbowyer
Copy link
ContributorAuthor

Yes, will redo against 3.4. The code didn't apply to both versions, so it needs a separate patch for each.

@pbowyerpbowyer changed the base branch from4.3 to3.4September 7, 2019 14:25
@pbowyer
Copy link
ContributorAuthor

@nicolas-grekas ✔️ Now against 3.4 ✔️ Test coverage added

Had to force-push a second time to get Appveyor to rerun, as I force-pushed the first time before changing the base branch for the PR.

@fabpot
Copy link
Member

Thank you@pbowyer.

fabpot added a commit that referenced this pull requestSep 8, 2019
…issue (pbowyer)This PR was squashed before being merged into the 3.4 branch (closes#33487).Discussion----------[HttpKernel] Fix Apache mod_expires Session Cache-Control issue| Q             | A| ------------- | ---| Branch?       | 3.4 for bug fixes <!-- see below -->| Bug fix?      | yes| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->| BC breaks?    | no     <!-- seehttps://symfony.com/bc -->| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->| License       | MITApaches's [mod_expires](https://httpd.apache.org/docs/current/mod/mod_expires.html) is a widely used module to set HTTP caching headers. It allows you to set a default cache lifetime as well as lifetimes by mime_type.When an application server has set a `Cache-Control` header, mod_expires ignores this and sets its own, resulting in duplicate `Cache-Control` headers and conflicting information. It does this _unless_ the application server sets an `Expires` header, in which case mod_expires does nothing. This is documented on the link above:> When the `Expires` header is already part of the response generated by the server, for example when generated by a CGI script or proxied from an origin server, this module does not change or add an `Expires` or `Cache-Control` header.Symfony automatically sets a `Cache-Control` header if a session exists. This patch adds an `Expires` header to ensure it's respected by mod_expires.## Example 1With the following Apache config:```apache<IfModule mod_expires.c>    ExpiresActive on    ExpiresDefault                                      "access plus 1 month"</IfModule>```The HTTP response headers are:### Without the patch```HTTP/1.1 200 OKDate: Fri, 06 Sep 2019 08:02:02 GMTServer: Apache/2.4.37 (Ubuntu)Cache-Control: max-age=0, must-revalidate, privateCache-Control: max-age=2592000Expires: Sun, 06 Oct 2019 08:02:00 GMTVary: Accept-EncodingContent-Encoding: gzipContent-Length: 13099Connection: closeContent-Type: text/html; charset=UTF-8```### With the patch```HTTP/1.1 200 OKDate: Fri, 06 Sep 2019 08:21:34 GMTServer: Apache/2.4.37 (Ubuntu)Cache-Control: max-age=0, must-revalidate, privateExpires: Fri, 06 Sep 2019 08:21:34 GMTVary: Accept-EncodingContent-Encoding: gzipContent-Length: 13098Connection: closeContent-Type: text/html; charset=UTF-8```## Example 2With the following Apache config:```apache<IfModule mod_expires.c>    ExpiresActive on    ExpiresDefault                                      "access plus 1 month"    ExpiresByType text/html                             "access plus 0 seconds"</IfModule>```### Without the patch```HTTP/1.1 200 OKDate: Fri, 06 Sep 2019 08:18:40 GMTServer: Apache/2.4.37 (Ubuntu)Cache-Control: max-age=0, must-revalidate, privateCache-Control: max-age=0Expires: Fri, 06 Sep 2019 08:18:39 GMTVary: Accept-EncodingContent-Encoding: gzipContent-Length: 13099Connection: closeContent-Type: text/html; charset=UTF-8```### With the patch```HTTP/1.1 200 OKDate: Fri, 06 Sep 2019 08:20:40 GMTServer: Apache/2.4.37 (Ubuntu)Cache-Control: max-age=0, must-revalidate, privateExpires: Fri, 06 Sep 2019 08:20:40 GMTVary: Accept-EncodingContent-Encoding: gzipContent-Length: 13100Connection: closeContent-Type: text/html; charset=UTF-8```Commits-------9e94276 [HttpKernel] Fix Apache mod_expires Session Cache-Control issue
@fabpotfabpot merged commit9e94276 intosymfony:3.4Sep 8, 2019
This was referencedOct 7, 2019

if ($sessioninstanceof Session ?$session->getUsageIndex() !==end($this->sessionUsageStack) :$session->isStarted()) {
$event->getResponse()
->setExpires(new \DateTime())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Is it on purpose, that this even overrides the expires header that has been set before this line?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

this is about forcing the page to be uncacheable anyway. So yes.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@stofstofstof left review comments

@fabpotfabpotfabpot approved these changes

+1 more reviewer

@danrotdanrotdanrot left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

4.3

Development

Successfully merging this pull request may close these issues.

6 participants

@pbowyer@nicolas-grekas@fabpot@danrot@stof@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp