Skip to content

Commit 896b825

Browse files
committed
Remove deprecated constants from RFC7231 for date formats
1 parent 5383794 commit 896b825

4 files changed

Lines changed: 14 additions & 13 deletions

File tree

src/Cookie.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
namespace Framework\HTTP;
1111

1212
use DateTime;
13-
use DateTimeInterface;
1413
use DateTimeZone;
1514
use Exception;
1615
use InvalidArgumentException;
@@ -64,7 +63,7 @@ public function toString() : string
6463
$string = $this->getName() . '=' . $this->getValue();
6564
$part = $this->getExpires();
6665
if ($part !== null) {
67-
$string .= '; expires=' . $this->expires->format(DateTimeInterface::RFC7231);
66+
$string .= '; expires=' . $this->expires->format('D, d M Y H:i:s \G\M\T');
6867
$string .= '; Max-Age=' . $this->expires->diff(new DateTime('-1 second'))->s;
6968
}
7069
$part = $this->getPath();

src/Response.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
namespace Framework\HTTP;
1111

1212
use DateTime;
13-
use DateTimeInterface;
1413
use DateTimeZone;
1514
use Framework\HTTP\Debug\HTTPCollector;
1615
use InvalidArgumentException;
@@ -796,7 +795,7 @@ public function setDate(DateTime $datetime) : static
796795
$date->setTimezone(new DateTimeZone('UTC'));
797796
$this->setHeader(
798797
ResponseHeader::DATE,
799-
$date->format(DateTimeInterface::RFC7231)
798+
$date->format('D, d M Y H:i:s \G\M\T')
800799
);
801800
return $this;
802801
}
@@ -836,7 +835,7 @@ public function setExpires(DateTime $datetime) : static
836835
$date->setTimezone(new DateTimeZone('UTC'));
837836
$this->setHeader(
838837
ResponseHeader::EXPIRES,
839-
$date->format(DateTimeInterface::RFC7231)
838+
$date->format('D, d M Y H:i:s \G\M\T')
840839
);
841840
return $this;
842841
}
@@ -856,7 +855,7 @@ public function setLastModified(DateTime $datetime) : static
856855
$date->setTimezone(new DateTimeZone('UTC'));
857856
$this->setHeader(
858857
ResponseHeader::LAST_MODIFIED,
859-
$date->format(DateTimeInterface::RFC7231)
858+
$date->format('D, d M Y H:i:s \G\M\T')
860859
);
861860
return $this;
862861
}

src/ResponseDownload.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ public function setDownload(
8686
"Could not get the file modification time of '{$this->filepath}'"
8787
);
8888
}
89-
$this->setHeader(ResponseHeader::LAST_MODIFIED, \gmdate(\DATE_RFC7231, $filemtime));
89+
$this->setHeader(
90+
ResponseHeader::LAST_MODIFIED,
91+
\gmdate('D, d M Y H:i:s \G\M\T', $filemtime)
92+
);
9093
$filename ??= \basename($filepath);
9194
$filename = \htmlspecialchars($filename, \ENT_QUOTES | \ENT_HTML5);
9295
$filename = \strtr($filename, ['/' => '_', '\\' => '_']);

tests/ResponseTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ public function testToString() : void
437437
{
438438
$startLine = 'HTTP/1.1 200 OK';
439439
$headerLines = [
440-
'Date: ' . \gmdate(\DATE_RFC7231),
440+
'Date: ' . \gmdate('D, d M Y H:i:s \G\M\T'),
441441
'Content-Type: text/html; charset=UTF-8',
442442
];
443443
$body = <<<'HTML'
@@ -463,7 +463,7 @@ public function testToStringWithoutBodyAndContentType() : void
463463
{
464464
$startLine = 'HTTP/1.1 200 OK';
465465
$headerLines = [
466-
'Date: ' . \gmdate(\DATE_RFC7231),
466+
'Date: ' . \gmdate('D, d M Y H:i:s \G\M\T'),
467467
];
468468
$message = $startLine . "\r\n"
469469
. \implode("\r\n", $headerLines) . "\r\n"
@@ -478,12 +478,12 @@ public function testToStringWithDownload() : void
478478
$length = \strlen($body);
479479
$startLine = 'HTTP/1.1 200 OK';
480480
$headerLines = [
481-
'Last-Modified: ' . \gmdate(\DATE_RFC7231, (int) \filemtime($filename)),
481+
'Last-Modified: ' . \gmdate('D, d M Y H:i:s \G\M\T', (int) \filemtime($filename)),
482482
'Content-Disposition: attachment; filename="file.txt"',
483483
'Accept-Ranges: bytes',
484484
'Content-Length: ' . $length,
485485
'Content-Type: text/plain',
486-
'Date: ' . \gmdate(\DATE_RFC7231),
486+
'Date: ' . \gmdate('D, d M Y H:i:s \G\M\T'),
487487
];
488488
$this->response->setDownload($filename);
489489
$message = $startLine . "\r\n"
@@ -515,12 +515,12 @@ public function testToStringWithDownloadMultipart() : void
515515
$length = \strlen($body);
516516
$startLine = 'HTTP/1.1 206 Partial Content';
517517
$headerLines = [
518-
'Last-Modified: ' . \gmdate(\DATE_RFC7231, (int) \filemtime($filename)),
518+
'Last-Modified: ' . \gmdate('D, d M Y H:i:s \G\M\T', (int) \filemtime($filename)),
519519
'Content-Disposition: attachment; filename="fo_o.b&quot;ar"',
520520
'Accept-Ranges: bytes',
521521
'Content-Length: ' . $length,
522522
'Content-Type: multipart/x-byteranges; boundary=' . $boundary,
523-
'Date: ' . \gmdate(\DATE_RFC7231),
523+
'Date: ' . \gmdate('D, d M Y H:i:s \G\M\T'),
524524
];
525525
$this->response->setDownload($filename, filename: 'fo/o.b"ar');
526526
$message = $startLine . "\r\n"

0 commit comments

Comments
 (0)