Skip to content

Commit 065b8fb

Browse files
committed
review
1 parent f79e4a7 commit 065b8fb

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,9 +430,6 @@ protected function sendEarlyHints(iterable $links, Response $response = null): R
430430
return $response;
431431
}
432432

433-
/**
434-
* @internal
435-
*/
436433
private function populateEarlyHints(iterable $links): \Generator
437434
{
438435
foreach ($links as $link) {

src/Symfony/Component/HttpFoundation/Response.php

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -351,21 +351,28 @@ public function sendHeaders(/* ?int $statusCode = null */): static
351351

352352
// headers
353353
foreach ($this->headers->allPreserveCaseWithoutCookies() as $name => $values) {
354-
$previousValues = $this->sentHeaders[$name] ?? null;
355-
if ($previousValues === $values) {
356-
// Header already sent in a previous response, it will be automatically copied in this response by PHP
357-
continue;
358-
}
354+
$newValues = $values;
355+
$replace = false;
356+
357+
// As recommended by RFC 8297, PHP automatically copies headers from previous 103 responses, we need to deal with that if headers changed
358+
if (103 === $statusCode) {
359+
$previousValues = $this->sentHeaders[$name] ?? null;
360+
if ($previousValues === $values) {
361+
// Header already sent in a previous response, it will be automatically copied in this response by PHP
362+
continue;
363+
}
359364

360-
$replace = 0 === strcasecmp($name, 'Content-Type');
365+
$replace = 0 === strcasecmp($name, 'Content-Type');
366+
367+
if (null !== $previousValues && array_diff($previousValues, $values)) {
368+
header_remove($name);
369+
$previousValues = null;
370+
}
361371

362-
if (null !== $previousValues && array_diff($previousValues, $values)) {
363-
header_remove($name);
364-
$previousValues = null;
372+
$newValues = null === $previousValues ? $values : array_diff($values, $previousValues);
365373
}
366374

367-
$newValues = null === $previousValues ? $values : array_diff($values, $previousValues);
368-
foreach ($newValues as $value) {
375+
foreach ($newValues as $value) {
369376
header($name.': '.$value, $replace, $this->statusCode);
370377
}
371378

0 commit comments

Comments
 (0)