Skip to content

Commit

Permalink
FIX: Remove X-Requested-With from default Vary header
Browse files Browse the repository at this point in the history
3.x forward port of silverstripe#8242
  • Loading branch information
Sam Minnee authored and chillu committed Jul 23, 2018
1 parent 389cc0d commit 03c3bdf
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
Expand Up @@ -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.
Expand All @@ -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.
3 changes: 3 additions & 0 deletions docs/en/04_Changelogs/4.2.0.md
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions src/Control/Director.php
Expand Up @@ -993,6 +993,9 @@ public static function forceWWW(HTTPRequest $request = null)
* 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
*/
Expand Down
1 change: 0 additions & 1 deletion src/Control/Middleware/HTTPCacheControlMiddleware.php
Expand Up @@ -136,7 +136,6 @@ public function process(HTTPRequest $request, callable $delegate)
* @var array
*/
private static $defaultVary = [
"X-Requested-With" => true,
"X-Forwarded-Protocol" => true,
];

Expand Down

0 comments on commit 03c3bdf

Please sign in to comment.