mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-12-02 11:48:08 +08:00
Transfer the object that implemented Jsonable
This commit is contained in:
parent
4d89c38492
commit
0d74023801
@ -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));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user