为什么 Lumen 将带有 headers 的响应发送到 body?

Why Lumen send the response with headers into the body?

当我调用 Lumen 时,无论使用何种方法,响应总是 return header。为什么?

这是路由器:

$router->group(['prefix' => 'test'], function() use ($router) {

    $router->post('an', 'MyController@anAction');
});

这是我控制器的一个动作

public function anAction(Request $request): string {

    $return['result'] = true;
    return response()->json($return);
}

这是回复:

HTTP/1.0 200 OK Cache-Control: no-cache, private Content-Type: application/json Date: Thu, 02 May 2019 14:54:35 GMT {"result":true}

我怎么能有这个?

{"result":true}

我刚 运行 遇到这个问题,是由函数上的类型提示 return 引起的:

public function anAction(Request $request): string {

那是将响应转换为字符串而不是 Illuminate\Http\JsonResponse 它实际上是。改成这个解决了我的问题。

public function anAction(Request $request): \Illuminate\Http\JsonResponse {