Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c8caf02

Browse files
committed
fix streamedresponse
1 parent 065b8fb commit c8caf02

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

src/Symfony/Component/HttpFoundation/Response.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ class Response
212212
];
213213

214214
/**
215-
* Tracks headers already sent in informational responses
215+
* Tracks headers already sent in informational responses.
216216
*/
217217
private array $sentHeaders;
218218

src/Symfony/Component/HttpFoundation/StreamedResponse.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,12 @@ public function sendHeaders(/* ?int $statusCode = null */): static
6969
return $this;
7070
}
7171

72-
$this->headersSent = true;
72+
$statusCode = \func_num_args() > 0 ? func_get_arg(0) : null;
73+
if ($statusCode < 100 || $statusCode >= 200) {
74+
$this->headersSent = true;
75+
}
7376

74-
return parent::sendHeaders(...\func_get_args());
77+
return parent::sendHeaders($statusCode);
7578
}
7679

7780
/**

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,15 @@ public function testSetNotModified()
124124
$string = ob_get_clean();
125125
$this->assertEmpty($string);
126126
}
127+
128+
public function testSendInformationalResponse()
129+
{
130+
$response = new StreamedResponse();
131+
$response->sendHeaders(103);
132+
133+
// Informational responses must not override the main status code
134+
$this->assertSame(200, $response->getStatusCode());
135+
136+
$response->sendHeaders();
137+
}
127138
}

0 commit comments

Comments
 (0)