diff --git a/src/Event/Http/FpmHandler.php b/src/Event/Http/FpmHandler.php index 90665df7c..fc830ffc7 100644 --- a/src/Event/Http/FpmHandler.php +++ b/src/Event/Http/FpmHandler.php @@ -122,7 +122,7 @@ public function handleRequest(HttpRequestEvent $event, Context $context): HttpRe unset($responseHeaders['status']); } - $response = new HttpResponse($status ?? 200, $responseHeaders, $response->getBody()); + $response = new HttpResponse($response->getBody(), $responseHeaders, $status ?? 200); $this->ensureStillRunning(); diff --git a/src/Event/Http/HttpResponse.php b/src/Event/Http/HttpResponse.php index 36154903a..adedf4cfc 100644 --- a/src/Event/Http/HttpResponse.php +++ b/src/Event/Http/HttpResponse.php @@ -20,11 +20,11 @@ final class HttpResponse /** @var string */ private $body; - public function __construct(int $statusCode, array $headers, string $body) + public function __construct(string $body, array $headers, int $statusCode = 200) { - $this->statusCode = $statusCode; - $this->headers = $headers; $this->body = $body; + $this->headers = $headers; + $this->statusCode = $statusCode; } public static function fromPsr7Response(ResponseInterface $response): self @@ -44,7 +44,7 @@ public static function fromPsr7Response(ResponseInterface $response): self $response->getBody()->rewind(); $body = $response->getBody()->getContents(); - return new self($response->getStatusCode(), $headers, $body); + return new self($body, $headers, $response->getStatusCode()); } public function toApiGatewayFormat(bool $multiHeaders = false): array diff --git a/tests/Event/Http/HttpResponseTest.php b/tests/Event/Http/HttpResponseTest.php index 0a8f532de..c8167fc34 100644 --- a/tests/Event/Http/HttpResponseTest.php +++ b/tests/Event/Http/HttpResponseTest.php @@ -12,11 +12,10 @@ class HttpResponseTest extends TestCase public function test conversion to API Gateway format() { $response = new HttpResponse( - 200, + '

Hello world!

', [ 'Content-Type' => 'text/html; charset=utf-8', - ], - '

Hello world!

' + ] ); self::assertSame([ 'isBase64Encoded' => false,