Skip to content

Commit 8733b96

Browse files
bug #62502 [HttpFoundation] Fix Expires response header for EventStream (4513)
This PR was squashed before being merged into the 7.3 branch. Discussion ---------- [HttpFoundation] Fix Expires response header for EventStream | Q | A | ------------- | --- | Branch? | 7.3 | Bug fix? | yes | New feature? |no | Deprecations? |no | Issues | - | License | MIT This PR fixes name of the HTTP response header 'Expires' for Event Stream Response, which is currently missing an 's'. Because of the typo, a server may assume that the 'Expires' header is not set and add its own one. There may be an old agents that do not check Cache-Control and only use value of Expires header, leading into incorrect caching of the response. Some servers tend to set Expires value to a future. This fix is applicable to 7.3, 7.4, 8.x. The SSE has not been implemented before 7.3 and is not present in 6.x. One of the responses when using SSE (notice the expire and the expires headers): ``` HTTP/2 200 cache-control: max-age=0, must-revalidate, no-cache, no-store, private x-accel-buffering: no pragma: no-cache expire: 0 date: Mon, 24 Nov 2025 17:01:30 GMT cache-control: max-age=604800 expires: Mon, 01 Dec 2025 17:01:29 GMT content-type: text/event-stream; charset=UTF-8 server: Apache ... ``` *WIP: Missing tests* Commits ------- b830108 [HttpFoundation] Fix Expires response header for EventStream
2 parents 5122801 + b830108 commit 8733b96

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/Symfony/Component/HttpFoundation/EventStreamResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function __construct(?callable $callback = null, int $status = 200, array
4848
'Cache-Control' => 'private, no-cache, no-store, must-revalidate, max-age=0',
4949
'X-Accel-Buffering' => 'no',
5050
'Pragma' => 'no-cache',
51-
'Expire' => '0',
51+
'Expires' => '0',
5252
];
5353

5454
parent::__construct($callback, $status, $headers);

src/Symfony/Component/HttpFoundation/Tests/EventStreamResponseTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ public function testInitializationWithDefaultValues()
2929
$this->assertNull($response->getRetry());
3030
}
3131

32+
public function testPresentOfExpiresHeader()
33+
{
34+
$response = new EventStreamResponse();
35+
36+
$this->assertTrue($response->headers->has('Expires'));
37+
$this->assertSame('0', $response->headers->get('Expires'));
38+
}
39+
3240
public function testStreamSingleEvent()
3341
{
3442
$response = new EventStreamResponse(function () {

0 commit comments

Comments
 (0)