diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 63e8deb..00ee682 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -4,6 +4,7 @@ * Functions that need to be loaded on every Drupal request. */ +use Drupal\Component\Datetime\DateTimePlus; use Drupal\Component\Utility\Crypt; use Drupal\Component\Utility\Environment; use Drupal\Component\Utility\NestedArray; @@ -845,7 +846,7 @@ function drupal_page_header() { $default_headers = array( 'Expires' => 'Sun, 19 Nov 1978 05:00:00 GMT', - 'Last-Modified' => gmdate('D, d M Y H:i:s', REQUEST_TIME) . ' GMT', + 'Last-Modified' => gmdate(DateTimePlus::RFC2616, REQUEST_TIME), 'Cache-Control' => 'no-cache, must-revalidate, post-check=0, pre-check=0', 'ETag' => '"' . REQUEST_TIME . '"', ); @@ -867,7 +868,7 @@ function drupal_serve_page_from_cache(Response $response, Request $request) { // Only allow caching in the browser and prevent that the response is stored // by an external proxy server when the following conditions apply: // 1. There is a session cookie on the request. - // 2. The Vary: Cookie header is on the response. + // 2. The Vary: Cookie header is on the response.q // 3. The Cache-Control header does not contain the no-cache directive. if ($request->cookies->has(session_name()) && in_array('Cookie', $response->getVary()) && diff --git a/core/lib/Drupal/Component/Datetime/DateTimePlus.php b/core/lib/Drupal/Component/Datetime/DateTimePlus.php index 4c4122c..7ce8c04 100644 --- a/core/lib/Drupal/Component/Datetime/DateTimePlus.php +++ b/core/lib/Drupal/Component/Datetime/DateTimePlus.php @@ -31,6 +31,13 @@ class DateTimePlus extends \DateTime { const FORMAT = 'Y-m-d H:i:s'; /** + * A RFC2616 compliant subset of RFC1123. + * + * Example: Sun, 06 Nov 1994 08:49:37 GMT + */ + const RFC2616 = 'D, d M Y H:i:s \G\M\T'; + + /** * An array of possible date parts. */ protected static $dateParts = array( diff --git a/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php index d07c716..aef1910 100644 --- a/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php @@ -7,6 +7,7 @@ namespace Drupal\Core\EventSubscriber; +use Drupal\Component\Datetime\DateTimePlus; use Drupal\Core\Config\Config; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Language\Language; @@ -174,7 +175,7 @@ protected function setResponseCacheable(Response $response, Request $request) { // Last-Modified and an ETag header on the response. if (!$response->headers->has('Last-Modified')) { $timestamp = REQUEST_TIME; - $response->setLastModified(new \DateTime(gmdate('D, d M Y H:i:s', REQUEST_TIME) . ' GMT')); + $response->setLastModified(new \DateTime(gmdate(DateTimePlus::RFC2616, REQUEST_TIME))); } else { $timestamp = $response->getLastModified()->getTimestamp(); diff --git a/core/modules/aggregator/src/Plugin/aggregator/fetcher/DefaultFetcher.php b/core/modules/aggregator/src/Plugin/aggregator/fetcher/DefaultFetcher.php index 0cc5d77..0cec424 100644 --- a/core/modules/aggregator/src/Plugin/aggregator/fetcher/DefaultFetcher.php +++ b/core/modules/aggregator/src/Plugin/aggregator/fetcher/DefaultFetcher.php @@ -9,6 +9,7 @@ use Drupal\aggregator\Plugin\FetcherInterface; use Drupal\aggregator\FeedInterface; +use Drupal\Component\Datetime\DateTimePlus; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use GuzzleHttp\ClientInterface; use GuzzleHttp\Exception\RequestException; @@ -65,7 +66,7 @@ public function fetch(FeedInterface $feed) { $request->addHeader('If-None-Match', $feed->getEtag()); } if ($feed->getLastModified()) { - $request->addHeader('If-Modified-Since', gmdate('D, d M Y H:i:s', $feed->getLastModified()). ' GMT'); + $request->addHeader('If-Modified-Since', gmdate(DateTimePlus::RFC2616, $feed->getLastModified())); } try { diff --git a/core/modules/aggregator/tests/modules/aggregator_test/src/Controller/AggregatorTestRssController.php b/core/modules/aggregator/tests/modules/aggregator_test/src/Controller/AggregatorTestRssController.php index faab095..c1d04c5 100644 --- a/core/modules/aggregator/tests/modules/aggregator_test/src/Controller/AggregatorTestRssController.php +++ b/core/modules/aggregator/tests/modules/aggregator_test/src/Controller/AggregatorTestRssController.php @@ -6,6 +6,7 @@ namespace Drupal\aggregator_test\Controller; +use Drupal\Component\Datetime\DateTimePlus; use Drupal\Core\Controller\ControllerBase; use Drupal\Component\Utility\Crypt; use Symfony\Component\HttpFoundation\Response; @@ -41,7 +42,7 @@ public function testFeed($use_last_modified, $use_etag, Request $request) { // Send appropriate response. We respond with a 304 not modified on either // etag or on last modified. if ($use_last_modified) { - $response->headers->set('Last-Modified', gmdate('D, d M Y H:i:s', $last_modified) . ' GMT'); + $response->headers->set('Last-Modified', gmdate(DateTimePlus::RFC2616, $last_modified)); } if ($use_etag) { $response->headers->set('ETag', $etag); diff --git a/core/modules/system/src/Tests/Bootstrap/PageCacheTest.php b/core/modules/system/src/Tests/Bootstrap/PageCacheTest.php index 9945686..38dfe96 100644 --- a/core/modules/system/src/Tests/Bootstrap/PageCacheTest.php +++ b/core/modules/system/src/Tests/Bootstrap/PageCacheTest.php @@ -7,6 +7,7 @@ namespace Drupal\system\Tests\Bootstrap; +use Drupal\Component\Datetime\DateTimePlus; use Symfony\Component\Routing\RequestContext; use Drupal\simpletest\WebTestBase; use Drupal\Core\Cache\Cache; @@ -141,7 +142,7 @@ function testConditionalRequests() { $this->assertResponse(200, 'Conditional request without If-None-Match returned 200 OK.'); $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', 'Page was cached.'); - $this->drupalGet('', array(), array('If-Modified-Since: ' . gmdate('D, d M Y H:i:s', strtotime($last_modified) + 1) . ' GMT', 'If-None-Match: ' . $etag)); + $this->drupalGet('', array(), array('If-Modified-Since: ' . gmdate(DateTimePlus::RFC2616, strtotime($last_modified) + 1), 'If-None-Match: ' . $etag)); $this->assertResponse(200, 'Conditional request with new a If-Modified-Since date newer than Last-Modified returned 200 OK.'); $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', 'Page was cached.'); diff --git a/core/modules/toolbar/toolbar.module b/core/modules/toolbar/toolbar.module index 4059978..f3c42e6 100644 --- a/core/modules/toolbar/toolbar.module +++ b/core/modules/toolbar/toolbar.module @@ -138,7 +138,7 @@ function _toolbar_initialize_page_cache() { // accesses the callback URL again (e.g., after clearing the browser cache or // when force-reloading a Drupal page). $max_age = 3600 * 24 * 365; - drupal_add_http_header('Expires', gmdate('D, d M Y H:i:s', REQUEST_TIME + $max_age) . ' GMT'); + drupal_add_http_header('Expires', gmdate(DateTimePlus::RFC2616, REQUEST_TIME + $max_age)); drupal_add_http_header('Cache-Control', 'private, max-age=' . $max_age); }