diff --git a/http-server/Constrict/Request.php b/http-server/Constrict/Request.php index 20219898..cc86b726 100644 --- a/http-server/Constrict/Request.php +++ b/http-server/Constrict/Request.php @@ -50,14 +50,14 @@ class Request implements RequestInterface /** * @param \Swoole\Http\Request $request - * @return Request + * @return array */ - public static function create(\Swoole\Http\Request $request): RequestInterface + public static function create(\Swoole\Http\Request $request): array { - Context::setContext(ResponseInterface::class, new Response()); + Context::setContext(ResponseInterface::class, $response = new Response()); Context::setContext(RequestMessage::class, RequestMessage::parseRequest($request)); - return Kiri::getDi()->get(Request::class); + return [Kiri::getDi()->get(Request::class), $response]; } } diff --git a/http-server/Service/Http.php b/http-server/Service/Http.php index 3a2303ce..fbf62a98 100644 --- a/http-server/Service/Http.php +++ b/http-server/Service/Http.php @@ -42,18 +42,21 @@ class Http extends \Server\Abstracts\Http implements OnClose, OnConnect { // TODO: Implement onRequest() method. try { - $request = \Server\Constrict\Request::create($request); + [$request, $psr7Response] = \Server\Constrict\Request::create($request); $node = $this->router->Branch_search($request); if (!($node instanceof Node)) { throw new RequestException('

HTTP 404 Not Found


Powered by Swoole', 404); } - if (!(($responseData = $node->dispatch($request)) instanceof ResponseInterface)) { - $responseData = $this->transferToResponse($responseData); + if (!(($psr7Response = $node->dispatch($request)) instanceof ResponseInterface)) { + $psr7Response = $this->transferToResponse($psr7Response); } } catch (Error | \Throwable $exception) { - $responseData = $this->exceptionHandler->emit($exception, $this->response); + $psr7Response = $this->exceptionHandler->emit($exception, $this->response); } finally { - $this->responseEmitter->sender($response, $responseData); + if (!isset($psr7Response)) { + return; + } + $this->responseEmitter->sender($response, $psr7Response); $this->eventDispatch->dispatch(new OnAfterRequest()); } }