Skip to content

Commit 4a310b2

Browse files
committed
Add Header::RFC7231 constant to avoid hardcoded format string
1 parent 516dc92 commit 4a310b2

3 files changed

Lines changed: 9 additions & 2 deletions

File tree

src/DevEtagSetter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function __invoke(ResourceObject $ro, int|null $time = null, HttpCache|nu
2929
// This is useful for debugging purposes.
3030
// Usually, the ETag is a hash of the resource view or body.
3131
$ro->headers[Header::ETAG] = $uriEtag;
32-
$ro->headers[Header::LAST_MODIFIED] = gmdate('D, d M Y H:i:s \G\M\T', 0);
32+
$ro->headers[Header::LAST_MODIFIED] = gmdate(Header::RFC7231, 0);
3333
$this->setCacheDependency($ro);
3434
}
3535

src/EtagSetter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function __invoke(ResourceObject $ro, int|null $time = null, HttpCache|nu
3737

3838
$etag = $this->getEtag($ro, $httpCache);
3939
$ro->headers[Header::ETAG] = $etag;
40-
$ro->headers[Header::LAST_MODIFIED] = gmdate('D, d M Y H:i:s \G\M\T', $time);
40+
$ro->headers[Header::LAST_MODIFIED] = gmdate(Header::RFC7231, $time);
4141
$this->setCacheDependency($ro);
4242
}
4343

src/Header.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,12 @@ final class Header
1717
public const CACHE_CONTROL = 'Cache-Control';
1818
public const AGE = 'Age';
1919
public const LAST_MODIFIED = 'Last-Modified';
20+
21+
/**
22+
* RFC 7231 date format for HTTP headers
23+
*
24+
* @see https://www.rfc-editor.org/rfc/rfc7231#section-7.1.1.1
25+
*/
26+
public const RFC7231 = 'D, d M Y H:i:s \G\M\T';
2027
public const HTTP_IF_NONE_MATCH = 'HTTP_IF_NONE_MATCH';
2128
}

0 commit comments

Comments
 (0)