diff --git a/CHANGELOG.md b/CHANGELOG.md index 043b2cc49..c276c6206 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ 1. [](#new) * Added support for overriding configuration by using environment variables * Use PHP 7.4 serialization (the old `Serializable` methods are now final and cannot be overridden) + * Enabled `ETag` setting by default for 304 responses 1. [](#improved) * Make it possible to use an absolute path when loading a blueprint * Make serialize methods final in `ContentBlock`, `AbstractFile`, `FormTrait`, `ObjectCollectionTrait` and `ObjectTrait` diff --git a/system/config/system.yaml b/system/config/system.yaml index 0a102c0a2..9925b76bf 100644 --- a/system/config/system.yaml +++ b/system/config/system.yaml @@ -73,7 +73,7 @@ pages: expires: 604800 # Page expires time in seconds (604800 seconds = 7 days) cache_control: # Can be blank for no setting, or a valid `cache-control` text value last_modified: false # Set the last modified date header based on file modification timestamp - etag: false # Set the etag header tag + etag: true # Set the etag header tag vary_accept_encoding: false # Add `Vary: Accept-Encoding` header redirect_default_route: false # Automatically redirect to a page's default route redirect_default_code: 302 # Default code to use for redirects diff --git a/system/src/Grav/Common/Grav.php b/system/src/Grav/Common/Grav.php index b8e6a9b63..851d84c1c 100644 --- a/system/src/Grav/Common/Grav.php +++ b/system/src/Grav/Common/Grav.php @@ -273,9 +273,10 @@ class Grav extends Container // Handle ETag and If-None-Match headers. if ($response->getHeaderLine('ETag') === '1') { $etag = md5($body); - $response = $response->withHeader('ETag', $etag); + $response = $response->withHeader('ETag', '"' . $etag . '"'); - if ($noCache === false && $this['request']->getHeaderLine('If-None-Match') === $etag) { + $search = trim($this['request']->getHeaderLine('If-None-Match'), '"'); + if ($noCache === false && $search === $etag) { $response = $response->withStatus(304); $body = ''; } @@ -335,9 +336,10 @@ class Grav extends Container // Handle ETag and If-None-Match headers. if ($response->getHeaderLine('ETag') === '1') { $etag = md5($body); - $response = $response->withHeader('ETag', $etag); + $response = $response->withHeader('ETag', '"' . $etag . '"'); - if ($noCache === false && $request->getHeaderLine('If-None-Match') === $etag) { + $search = trim($this['request']->getHeaderLine('If-None-Match'), '"'); + if ($noCache === false && $search === $etag) { $response = $response->withStatus(304); $body = ''; }