diff --git a/_config/config.yml b/_config/config.yml index 31dbd1682..8d7eaef34 100644 --- a/_config/config.yml +++ b/_config/config.yml @@ -10,4 +10,5 @@ HTTP: cache_control: max-age: 0 must-revalidate: "true" - no-transform: "true" \ No newline at end of file + no-transform: "true" + vary: "Cookie, X-Forwarded-Protocol, User-Agent, Accept" \ No newline at end of file diff --git a/control/HTTP.php b/control/HTTP.php index b1b2b3cae..2359d5836 100644 --- a/control/HTTP.php +++ b/control/HTTP.php @@ -358,7 +358,10 @@ class HTTP { // To do: User-Agent should only be added in situations where you *are* actually // varying according to user-agent. - $responseHeaders['Vary'] = 'Cookie, X-Forwarded-Protocol, User-Agent, Accept'; + $vary = $config->get('HTTP', 'vary'); + if ($vary && strlen($vary)) { + $responseHeaders['Vary'] = $vary; + } } else { if($body) { diff --git a/docs/en/02_Developer_Guides/08_Performance/02_HTTP_Cache_Headers.md b/docs/en/02_Developer_Guides/08_Performance/02_HTTP_Cache_Headers.md index 455a3c4e9..268a45a0f 100644 --- a/docs/en/02_Developer_Guides/08_Performance/02_HTTP_Cache_Headers.md +++ b/docs/en/02_Developer_Guides/08_Performance/02_HTTP_Cache_Headers.md @@ -31,3 +31,23 @@ clause in `Cache-Control` and `Pragma` will be included. Used to set the modification date to something more recent than the default. [api:DataObject::__construct] calls [api:HTTP::register_modification_date(] whenever a record comes from the database ensuring the newest date is present. + +### Vary: cache header + +By default, SilverStripe will output a `Vary` header (used by upstream caches for determining uniqueness) +that looks like + +``` +Cookie, X-Forwarded-Protocol, User-Agent, Accept +``` + +To change the value of the `Vary` header, you can change this value by specifying the header in configuration + +```yml +HTTP: + vary: "" +``` + + + + diff --git a/tests/control/HTTPTest.php b/tests/control/HTTPTest.php index b0bd98703..d15bc3655 100644 --- a/tests/control/HTTPTest.php +++ b/tests/control/HTTPTest.php @@ -46,6 +46,31 @@ class HTTPTest extends FunctionalTest { } } + + public function testConfigVary() { + $body = "