Browse Source

Merge pull request #15355 from cakephp/response-header-date

Fix datetime format in response headers.
othercorey 5 years ago
parent
commit
9fdd1c5dec

+ 2 - 2
src/Http/Response.php

@@ -1370,7 +1370,7 @@ class Response implements ResponseInterface
             }
         }
 
-        $this->_setHeader('Date', gmdate('D, j M Y G:i:s ', time()) . 'GMT');
+        $this->_setHeader('Date', gmdate('D, d M Y H:i:s ', time()) . 'GMT');
 
         $this->modified($since);
         $this->expires($time);
@@ -1395,7 +1395,7 @@ class Response implements ResponseInterface
             }
         }
 
-        return $this->withHeader('Date', gmdate('D, j M Y G:i:s ', time()) . 'GMT')
+        return $this->withHeader('Date', gmdate('D, d M Y H:i:s ', time()) . 'GMT')
             ->withModified($since)
             ->withExpires($time)
             ->withSharable(true)

+ 3 - 3
src/Routing/Middleware/AssetMiddleware.php

@@ -174,9 +174,9 @@ class AssetMiddleware
         return $response->withBody($stream)
             ->withHeader('Content-Type', $contentType)
             ->withHeader('Cache-Control', 'public,max-age=' . $maxAge)
-            ->withHeader('Date', gmdate('D, j M Y G:i:s \G\M\T', time()))
-            ->withHeader('Last-Modified', gmdate('D, j M Y G:i:s \G\M\T', $modified))
-            ->withHeader('Expires', gmdate('D, j M Y G:i:s \G\M\T', $expire));
+            ->withHeader('Date', gmdate('D, d M Y H:i:s \G\M\T', time()))
+            ->withHeader('Last-Modified', gmdate('D, d M Y H:i:s \G\M\T', $modified))
+            ->withHeader('Expires', gmdate('D, d M Y H:i:s \G\M\T', $expire));
     }
 
     /**

+ 4 - 4
tests/TestCase/Http/ResponseTest.php

@@ -722,7 +722,7 @@ class ResponseTest extends TestCase
             $time = new \DateTime('+1 day', new \DateTimeZone('UTC'));
             $response->expires('+1 day');
             $expected = [
-                'Date' => gmdate('D, j M Y G:i:s ', $since) . 'GMT',
+                'Date' => gmdate('D, d M Y H:i:s ', $since) . 'GMT',
                 'Last-Modified' => gmdate('D, j M Y H:i:s ', $since) . 'GMT',
                 'Expires' => $time->format('D, j M Y H:i:s') . ' GMT',
                 'Cache-Control' => 'public, max-age=' . ($time->format('U') - time()),
@@ -735,7 +735,7 @@ class ResponseTest extends TestCase
             $since = time();
             $time = '+5 day';
             $expected = [
-                'Date' => gmdate('D, j M Y G:i:s ', $since) . 'GMT',
+                'Date' => gmdate('D, d M Y H:i:s ', $since) . 'GMT',
                 'Last-Modified' => gmdate('D, j M Y H:i:s ', $since) . 'GMT',
                 'Expires' => gmdate('D, j M Y H:i:s', strtotime($time)) . ' GMT',
                 'Cache-Control' => 'public, max-age=' . (strtotime($time) - time()),
@@ -748,7 +748,7 @@ class ResponseTest extends TestCase
             $since = time();
             $time = time();
             $expected = [
-                'Date' => gmdate('D, j M Y G:i:s ', $since) . 'GMT',
+                'Date' => gmdate('D, d M Y H:i:s ', $since) . 'GMT',
                 'Last-Modified' => gmdate('D, j M Y H:i:s ', $since) . 'GMT',
                 'Expires' => gmdate('D, j M Y H:i:s', $time) . ' GMT',
                 'Cache-Control' => 'public, max-age=0',
@@ -773,7 +773,7 @@ class ResponseTest extends TestCase
         $this->assertFalse($response->hasHeader('Date'));
         $this->assertFalse($response->hasHeader('Last-Modified'));
 
-        $this->assertEquals(gmdate('D, j M Y G:i:s ', $since) . 'GMT', $new->getHeaderLine('Date'));
+        $this->assertEquals(gmdate('D, d M Y H:i:s ', $since) . 'GMT', $new->getHeaderLine('Date'));
         $this->assertEquals(gmdate('D, j M Y H:i:s ', $since) . 'GMT', $new->getHeaderLine('Last-Modified'));
         $this->assertEquals(gmdate('D, j M Y H:i:s', $time) . ' GMT', $new->getHeaderLine('Expires'));
         $this->assertEquals('public, max-age=0', $new->getHeaderLine('Cache-Control'));

+ 4 - 4
tests/TestCase/Routing/Middleware/AssetMiddlewareTest.php

@@ -57,7 +57,7 @@ class AssetMiddlewareTest extends TestCase
         $modified = filemtime(TEST_APP . 'Plugin/TestPlugin/webroot/root.js');
         $request = ServerRequestFactory::fromGlobals([
             'REQUEST_URI' => '/test_plugin/root.js',
-            'HTTP_IF_MODIFIED_SINCE' => date('D, j M Y G:i:s \G\M\T', $modified),
+            'HTTP_IF_MODIFIED_SINCE' => date('D, d M Y H:i:s \G\M\T', $modified),
         ]);
         $response = new Response();
         $next = function ($req, $res) {
@@ -168,7 +168,7 @@ class AssetMiddlewareTest extends TestCase
             $res->getHeaderLine('Content-Type')
         );
         $this->assertEquals(
-            gmdate('D, j M Y G:i:s ', $time) . 'GMT',
+            gmdate('D, d M Y H:i:s ', $time) . 'GMT',
             $res->getHeaderLine('Date')
         );
         $this->assertEquals(
@@ -176,11 +176,11 @@ class AssetMiddlewareTest extends TestCase
             $res->getHeaderLine('Cache-Control')
         );
         $this->assertEquals(
-            gmdate('D, j M Y G:i:s ', $modified) . 'GMT',
+            gmdate('D, d M Y H:i:s ', $modified) . 'GMT',
             $res->getHeaderLine('Last-Modified')
         );
         $this->assertEquals(
-            gmdate('D, j M Y G:i:s ', $expires) . 'GMT',
+            gmdate('D, d M Y H:i:s ', $expires) . 'GMT',
             $res->getHeaderLine('Expires')
         );
     }