public function handleMessage(NetworkConnectionInterface $conn, NetworkMessageInterface $message)
{
if (!$message instanceof HttpRequestInterface) {
if (!isset($conn->controller)) {
return $this->close($conn, 500);
}
return $conn->controller->handleMessage($conn, $message);
}
if ($this->checkOrigin && ($header = $message->getHeaderLine('Origin')) !== '') {
$origin = parse_url($header, PHP_URL_HOST) ?: $header;
if ($origin !== '' && !$this->isOriginAllowed($origin)) {
return $this->close($conn, 403);
}
}
$context = $this->matcher->getContext();
$context->setMethod($message->getMethod());
$context->setHost($message->getUri()->getHost());
$route = [];
try {
$route = $this->matcher->match($message->getUri()->getPath());
} catch (MethodNotAllowedException $nae) {
return $this->close($conn, 403);
} catch (ResourceNotFoundException $nfe) {
return $this->close($conn, 404);
} catch (Error $ex) {
return $this->close($conn, 500);
} catch (Exception $ex) {
return $this->close($conn, 500);
}
$conn->controller = $route['_controller'];
try {
$conn->controller->handleConnect($conn);
$conn->controller->handleMessage($conn, $message);
return;
} catch (Error $ex) {
} catch (Exception $ex) {
}
$conn->controller->handleError($conn, $ex);
}