FIX: Remove X-Requested-With from default Vary header

3.x forward port of https://github.com/silverstripe/silverstripe-framework/pull/8242
This commit is contained in:
Sam Minnee 2018-07-04 13:35:47 +12:00 committed by Daniel Hensby
parent f03d5e8d19
commit bde3121a33
No known key found for this signature in database
GPG Key ID: D8DEBC4C8E7BC8B9
4 changed files with 10 additions and 2 deletions

View File

@ -228,7 +228,7 @@ when calculating a cache key, usually in addition to the full URL.
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.
@ -237,3 +237,6 @@ To change the value of the `Vary` header, you can change this value by specifyin
SilverStripe\Control\HTTP:
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

@ -357,6 +357,9 @@ class PageController extends ContentController
Note this is different from `Vary: Accept-Encoding`,
which is important for compression (e.g. gzip), and usually added by
other layers such as Apache's mod_gzip.
* Removed `Vary: X-Requested-With` since it's only applicable when varying
content based on the client context, mostly for returning different XHR responses
as determined through `Director::is_ajax()`.
* No longer sets `Last-Modified` date in HTTP response headers in `DataObject::__construct()`.
Uses `ETag` calculation based on response body which is more accurate,
and resilient against partial and object caching which can produce stale `Last-Modified` values.

View File

@ -993,6 +993,9 @@ class Director implements TemplateGlobalProvider
* Checks if the current HTTP-Request is an "Ajax-Request" by checking for a custom header set by
* jQuery or whether 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.
*
* @param HTTPRequest $request
* @return bool
*/

View File

@ -135,7 +135,6 @@ class HTTPCacheControlMiddleware implements HTTPMiddleware, Resettable
* @var array
*/
private static $defaultVary = [
"X-Requested-With" => true,
"X-Forwarded-Protocol" => true,
];