This commit is contained in:
2021-08-04 17:13:26 +08:00
parent 6ccd53562b
commit 819e96abf3
4 changed files with 15 additions and 3 deletions
+2 -1
View File
@@ -14,6 +14,7 @@ use HttpServer\Abstracts\HttpService;
use HttpServer\Http\Formatter\HtmlFormatter;
use HttpServer\Http\Formatter\JsonFormatter;
use HttpServer\Http\Formatter\XmlFormatter;
use Server\ResponseInterface;
use Snowflake\Exception\NotFindClassException;
use Swoole\Http\Response as SResponse;
@@ -21,7 +22,7 @@ use Swoole\Http\Response as SResponse;
* Class Response
* @package Snowflake\Snowflake\Http
*/
class Response extends HttpService
class Response extends HttpService implements ResponseInterface
{
const JSON = 'json';
+2 -1
View File
@@ -6,6 +6,7 @@ namespace Server\Constrict;
use HttpServer\Http\Context;
use HttpServer\Http\Response as HttpResponse;
use Server\ResponseInterface;
/**
@@ -13,7 +14,7 @@ use HttpServer\Http\Response as HttpResponse;
* @package Server
* @mixin HttpResponse
*/
class Response
class Response implements ResponseInterface
{
const JSON = 'json';
+3 -1
View File
@@ -121,7 +121,9 @@ class HTTPServerListener extends Abstracts\Server
if (!($node instanceof Node)) {
throw new RequestException('<h2>HTTP 404 Not Found</h2><hr><i>Powered by Swoole</i>', 404);
}
$responseData = $this->response->setContent($node->dispatch())->setStatusCode(200);
if (!(($responseData = $node->dispatch()) instanceof ResponseInterface)) {
$responseData = $this->response->setContent($node->dispatch())->setStatusCode(200);
}
} catch (Error | Throwable $exception) {
$responseData = $this->exceptionHandler->emit($exception, $this->response);
} finally {
+8
View File
@@ -0,0 +1,8 @@
<?php
namespace Server;
interface ResponseInterface
{
}