mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #4818 from nyeholt/3
NEW Use Config for determining Vary header
This commit is contained in:
commit
8368ba7960
@ -10,4 +10,5 @@ HTTP:
|
||||
cache_control:
|
||||
max-age: 0
|
||||
must-revalidate: "true"
|
||||
no-transform: "true"
|
||||
no-transform: "true"
|
||||
vary: "Cookie, X-Forwarded-Protocol, User-Agent, Accept"
|
@ -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) {
|
||||
|
@ -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: ""
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -46,6 +46,31 @@ class HTTPTest extends FunctionalTest {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function testConfigVary() {
|
||||
$body = "<html><head></head><body><h1>Mysite</h1></body></html>";
|
||||
$response = new SS_HTTPResponse($body, 200);
|
||||
Config::inst()->update('Director', 'environment_type', 'live');
|
||||
HTTP::set_cache_age(30);
|
||||
HTTP::add_cache_headers($response);
|
||||
|
||||
$v = $response->getHeader('Vary');
|
||||
$this->assertNotEmpty($v);
|
||||
|
||||
$this->assertContains("Cookie", $v);
|
||||
$this->assertContains("X-Forwarded-Protocol", $v);
|
||||
$this->assertContains("User-Agent", $v);
|
||||
$this->assertContains("Accept", $v);
|
||||
|
||||
Config::inst()->update('HTTP', 'vary', '');
|
||||
|
||||
$response = new SS_HTTPResponse($body, 200);
|
||||
HTTP::add_cache_headers($response);
|
||||
|
||||
$v = $response->getHeader('Vary');
|
||||
$this->assertEmpty($v);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link HTTP::getLinksIn()}
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user