111
This commit is contained in:
@@ -46,7 +46,7 @@ class Http extends \Server\Abstracts\Http implements OnClose, OnConnect
|
|||||||
throw new RequestException('<h2>HTTP 404 Not Found</h2><hr><i>Powered by Swoole</i>', 404);
|
throw new RequestException('<h2>HTTP 404 Not Found</h2><hr><i>Powered by Swoole</i>', 404);
|
||||||
}
|
}
|
||||||
if (!(($responseData = $node->dispatch()) instanceof ResponseInterface)) {
|
if (!(($responseData = $node->dispatch()) instanceof ResponseInterface)) {
|
||||||
$responseData = $this->response->withStatus(200)->withBody(new Stream($responseData));
|
$responseData = $this->transferToResponse($responseData);
|
||||||
}
|
}
|
||||||
} catch (Error | \Throwable $exception) {
|
} catch (Error | \Throwable $exception) {
|
||||||
$responseData = $this->exceptionHandler->emit($exception, $this->response);
|
$responseData = $this->exceptionHandler->emit($exception, $this->response);
|
||||||
@@ -57,6 +57,20 @@ class Http extends \Server\Abstracts\Http implements OnClose, OnConnect
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $responseData
|
||||||
|
* @return \Server\ResponseInterface
|
||||||
|
*/
|
||||||
|
private function transferToResponse($responseData): ResponseInterface
|
||||||
|
{
|
||||||
|
$this->response->withStatus(200);
|
||||||
|
if (is_array($responseData)) {
|
||||||
|
return $this->response->withBody(new Stream(json_encode($responseData, JSON_UNESCAPED_UNICODE)));
|
||||||
|
}
|
||||||
|
return $this->response->withBody(new Stream((string)$responseData));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Server $server
|
* @param Server $server
|
||||||
* @param int $fd
|
* @param int $fd
|
||||||
|
|||||||
Reference in New Issue
Block a user