public function onRequest(ReactRequest $request, ReactResponse $response)
{
$content = '';
$headers = $request->getHeaders();
$contentLength = isset($headers['Content-Length']) ? (int) $headers['Content-Length'] : 0;
$request->on('data', function ($data) use($request, $response, &$content, $contentLength) {
// Read data (may be empty for GET request)
$content .= $data;
// Handle request after receive
if (strlen($content) >= $contentLength) {
$symfonyRequest = static::mapRequest($request, $content);
try {
// Execute
$symfonyResponse = $this->application->handle($symfonyRequest);
} catch (\Throwable $t) {
// Executed only in PHP 7, will not match in PHP 5.x
$this->fatalError($response, $t);
return;
} catch (\Exception $e) {
// Executed only in PHP 5.x, will not be reached in PHP 7
$this->fatalError($response, $e);
return;
}
static::mapResponse($response, $symfonyResponse);
if ($this->application instanceof SymfonyHttpKernel\TerminableInterface) {
$this->application->terminate($symfonyRequest, $symfonyResponse);
}
}
});
}