Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

patch: Content-Length header on connection and error responses #866

Merged
merged 1 commit into from
Dec 17, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/HttpApi/Controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,13 @@ protected function checkContentLength(ConnectionInterface $connection)
->ensureValidAppId($laravelRequest->appId)
->ensureValidSignature($laravelRequest);

$response = $this($laravelRequest);
$response = JsonResponse::create( $this($laravelRequest) );

$connection->send(JsonResponse::create($response));
$content = $response->content();

$response->header( 'Content-Length', strlen($content) );

$connection->send( $response );
$connection->close();
}
}
Expand All @@ -97,11 +101,14 @@ public function onError(ConnectionInterface $connection, Exception $exception)
return;
}

$responseData = json_encode([
'error' => $exception->getMessage(),
]);

$response = new Response($exception->getStatusCode(), [
'Content-Type' => 'application/json',
], json_encode([
'error' => $exception->getMessage(),
]));
'Content-Length' => strlen( $responseData )
], $responseData);

$connection->send(\GuzzleHttp\Psr7\str($response));

Expand Down