Skip to content

Commit 69b721c

Browse files
committed
Update documentation for Last-Modified to avoid PHP 8.5+ deprecations
1 parent 47dba65 commit 69b721c

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

docs/api/response.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ $app->get('/user', function (Psr\Http\Message\ServerRequestInterface $request) {
443443
<h1>Hello Alice</h1>
444444
HTML;
445445

446-
$modified = $date->setTimezone(new DateTimeZone('UTC'))->format(DATE_RFC7231);
446+
$modified = gmdate('D, d M Y H:i:s T', $date->getTimestamp());
447447
if ($request->getHeaderLine('If-Modified-Since') === $modified) {
448448
return new React\Http\Message\Response(
449449
React\Http\Message\Response::STATUS_NOT_MODIFIED,
@@ -481,11 +481,19 @@ Last-Modified: Sat, 06 Nov 2021 12:31:04 GMT
481481

482482
> ℹ️ **Working with dates**
483483
>
484-
> For use in HTTP, you may format any date in the GMT/UTC timezone using the
485-
> [`DATE_RFC7231`](https://www.php.net/manual/en/class.datetimeinterface.php#datetime.constants.rfc7231)
486-
> (PHP 7.1.5+) constant as given above. If you don't know the modification date
487-
> for your response or don't want to expose this information, you may want to
488-
> use [`ETag`](#etag) headers from the previous section instead.
484+
> For use in HTTP, you may format any date using the GMT time zone and the exact
485+
> format as given above. While UTC and GMT are often used interchangeably, the
486+
> HTTP specs require dates to be formatted in GMT.
487+
>
488+
> ```php
489+
> // convert date to GMT first, both forms are equivalent
490+
> $modified = gmdate('D, d M Y H:i:s T', $date->getTimestamp());
491+
> $modified = $date->setTimezone(new DateTimeZone('GMT'))->format('D, d M Y H:i:s T');
492+
> ```
493+
>
494+
> If you don't know the modification date for your response or don't want to
495+
> expose this information, you may want to use [`ETag`](#etag) headers from the
496+
> previous section instead.
489497
490498
## Output buffering
491499

src/FilesystemHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function __invoke(ServerRequestInterface $request): ResponseInterface
111111

112112
$stat = @\stat($path);
113113
if ($stat !== false) {
114-
$headers['Last-Modified'] = \gmdate('D, d M Y H:i:s', $stat['mtime']) . ' GMT';
114+
$headers['Last-Modified'] = \gmdate('D, d M Y H:i:s T', $stat['mtime']);
115115

116116
if ($request->getHeaderLine('If-Modified-Since') === $headers['Last-Modified']) {
117117
return new Response(Response::STATUS_NOT_MODIFIED);

0 commit comments

Comments
 (0)