Skip to content

Commit

Permalink
Add optional body to Response construct
Browse files Browse the repository at this point in the history
  • Loading branch information
drmad committed Apr 7, 2023
1 parent da01d40 commit 53ee4b4
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@
*/
class Response extends Psr\Response implements Stringable
{
public function __construct()
public function __construct(?StreamInterface $body = null)
{
$this->body = new Psr\Stream('php://temp', 'w');
if (!$body) {
$body = new Psr\Stream('php://temp', 'w');
}
$this->body = $body;
}

public static function fromString($string)
Expand All @@ -20,7 +23,7 @@ public static function fromString($string)

return (new self)
->withBody($body)
->withHeader('Content-length', strlen($string))
->withHeader('Content-Length', strlen($string))
;
}

Expand Down

0 comments on commit 53ee4b4

Please sign in to comment.