diff --git a/src/http/StatelessApplication.php b/src/http/StatelessApplication.php index 0656e05a..9f4ad344 100644 --- a/src/http/StatelessApplication.php +++ b/src/http/StatelessApplication.php @@ -275,10 +275,12 @@ public function handle(ServerRequestInterface $request): ResponseInterface $this->state = self::STATE_END; - return $this->terminate($response); + $psrResponse = $this->terminate($response); } catch (Throwable $e) { - return $this->terminate($this->handleError($e)); + $psrResponse = $this->terminate($this->handleError($e)); } + + return $psrResponse; } /** @@ -373,7 +375,7 @@ protected static function parseMemoryLimit(string $limit): int * Resets the StatelessApplication state and prepares the Yii2 environment for handling a PSR-7 request. * * Performs a full reinitialization of the application state, including event tracking, error handler cleanup, - * session management, and PSR-7 request injection. + * request adapter reset, session management, and PSR-7 request injection. * * This method ensures that the application is ready to process a new stateless request in worker or SAPI * environments, maintaining strict type safety and compatibility with Yii2 core components. @@ -406,6 +408,7 @@ protected function reset(ServerRequestInterface $request): void $this->requestedParams = []; $this->errorHandler->setResponse($this->response); + $this->request->reset(); $this->request->setPsr7Request($request); $this->session->close(); @@ -423,7 +426,7 @@ protected function reset(ServerRequestInterface $request): void /** * Finalizes the application lifecycle and converts the Yii2 Response to a PSR-7 ResponseInterface. * - * Cleans up registered events, resets uploaded files, flushes the logger, and resets the request state. + * Cleans up registered events, resets uploaded files, flushes the logger. * * This method ensures that all application resources are released and the response is converted to a PSR-7 * ResponseInterface for interoperability with PSR-7 compatible HTTP stacks. @@ -443,8 +446,6 @@ protected function terminate(Response $response): ResponseInterface Yii::getLogger()->flush(true); - $this->request->reset(); - return $response->getPsr7Response(); }