Transfer the object that implemented Jsonable

This commit is contained in:
huangzhhui 2019-06-15 23:51:05 +08:00
parent 4d89c38492
commit 0d74023801

View File

@ -19,6 +19,7 @@ use Hyperf\HttpMessage\Stream\SwooleStream;
use Hyperf\HttpServer\Router\DispatcherFactory;
use Hyperf\Utils\Context;
use Hyperf\Utils\Contracts\Arrayable;
use Hyperf\Utils\Contracts\Jsonable;
use Psr\Container\ContainerInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
@ -159,6 +160,12 @@ class CoreMiddleware implements MiddlewareInterface
->withBody(new SwooleStream(json_encode($response, JSON_UNESCAPED_UNICODE)));
}
if ($response instanceof Jsonable) {
return $this->response()
->withAddedHeader('content-type', 'application/json')
->withBody(new SwooleStream((string) $response));
}
return $this->response()->withBody(new SwooleStream((string) $response));
}