Skip to content

Commit

Permalink
fix streamedresponse
Browse files Browse the repository at this point in the history
  • Loading branch information
dunglas committed Mar 11, 2023
1 parent 065b8fb commit c8caf02
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpFoundation/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ class Response
];

/**
* Tracks headers already sent in informational responses
* Tracks headers already sent in informational responses.
*/
private array $sentHeaders;

Expand Down
7 changes: 5 additions & 2 deletions src/Symfony/Component/HttpFoundation/StreamedResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,12 @@ public function sendHeaders(/* ?int $statusCode = null */): static
return $this;
}

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

return parent::sendHeaders(...\func_get_args());
return parent::sendHeaders($statusCode);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,15 @@ public function testSetNotModified()
$string = ob_get_clean();
$this->assertEmpty($string);
}

public function testSendInformationalResponse()
{
$response = new StreamedResponse();
$response->sendHeaders(103);

// Informational responses must not override the main status code
$this->assertSame(200, $response->getStatusCode());

$response->sendHeaders();
}
}

0 comments on commit c8caf02

Please sign in to comment.