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

Commit 1b032b2

Browse files
authored
patch: Content-Length header on connection and error responses (#866)
1 parent c83137c commit 1b032b2

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/HttpApi/Controllers/Controller.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,13 @@ protected function checkContentLength(ConnectionInterface $connection)
8080
->ensureValidAppId($laravelRequest->appId)
8181
->ensureValidSignature($laravelRequest);
8282

83-
$response = $this($laravelRequest);
83+
$response = JsonResponse::create( $this($laravelRequest) );
8484

85-
$connection->send(JsonResponse::create($response));
85+
$content = $response->content();
86+
87+
$response->header( 'Content-Length', strlen($content) );
88+
89+
$connection->send( $response );
8690
$connection->close();
8791
}
8892
}
@@ -97,11 +101,14 @@ public function onError(ConnectionInterface $connection, Exception $exception)
97101
return;
98102
}
99103

104+
$responseData = json_encode([
105+
'error' => $exception->getMessage(),
106+
]);
107+
100108
$response = new Response($exception->getStatusCode(), [
101109
'Content-Type' => 'application/json',
102-
], json_encode([
103-
'error' => $exception->getMessage(),
104-
]));
110+
'Content-Length' => strlen( $responseData )
111+
], $responseData);
105112

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

0 commit comments

Comments
 (0)