Merge pull request #8242 from sminnee/simpler-vary-header

FIX: Remove X-Requested-With from default Vary header.
This commit is contained in:
Ingo Schommer 2018-07-05 13:32:46 +12:00 committed by GitHub
commit 13e8b155ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 3 deletions

View File

@ -16,7 +16,7 @@ HTTP:
no-cache: "true" no-cache: "true"
no-store: "true" no-store: "true"
must-revalidate: "true" must-revalidate: "true"
vary: "X-Requested-With, X-Forwarded-Protocol" vary: "X-Forwarded-Protocol"
LeftAndMain: LeftAndMain:
dependencies: dependencies:
versionProvider: %$SilverStripeVersionProvider versionProvider: %$SilverStripeVersionProvider

View File

@ -918,6 +918,9 @@ class Director implements TemplateGlobalProvider {
* by checking for a custom header set by jQuery or * by checking for a custom header set by jQuery or
* wether a manually set request-parameter 'ajax' is present. * wether a manually set request-parameter 'ajax' is present.
* *
* Note that if you plan to use this to alter your HTTP response on a cached page,
* you should add X-Requested-With to the Vary header.
*
* @return boolean * @return boolean
*/ */
public static function is_ajax() { public static function is_ajax() {

View File

@ -209,7 +209,7 @@ when calculating a cache key, usually in addition to the full URL path.
By default, SilverStripe will output a `Vary` header with the following content: By default, SilverStripe will output a `Vary` header with the following content:
``` ```
Vary: X-Requested-With, X-Forwarded-Protocol Vary: X-Forwarded-Protocol
``` ```
To change the value of the `Vary` header, you can change this value by specifying the header in configuration. To change the value of the `Vary` header, you can change this value by specifying the header in configuration.
@ -218,3 +218,6 @@ To change the value of the `Vary` header, you can change this value by specifyin
HTTP: HTTP:
vary: "" vary: ""
``` ```
Note that if you use `Director::is_ajax()` on cached pages then you should add `X-Requested-With` to the vary
header.

View File

@ -77,7 +77,6 @@ class HTTPTest extends FunctionalTest {
$this->assertNotEmpty($v); $this->assertNotEmpty($v);
$this->assertContains("X-Forwarded-Protocol", $v); $this->assertContains("X-Forwarded-Protocol", $v);
$this->assertContains("X-Requested-With", $v);
$this->assertNotContains("Cookie", $v); $this->assertNotContains("Cookie", $v);
$this->assertNotContains("User-Agent", $v); $this->assertNotContains("User-Agent", $v);
$this->assertNotContains("Accept", $v); $this->assertNotContains("Accept", $v);