在 Lumen 中使用以下异常处理程序时,X-Powered-By
会重复标头,即使$replace
(方法的第三个参数header()
)默认为 true(即使手动设置,如下所示,也不起作用)。
public function render($request, Exception $e)
{
if ($e instanceof \Symfony\Component\HttpKernel\Exception\NotFoundHttpException)
{
return response(view('not-found'), 404)->header('X-Powered-By', env('APP_NAME')."/".env('APP_VER'), true);
}
return parent::render($e);
}
响应头:
HTTP/1.0 404 Not Found
Date: Sat, 23 May 2015 08:05:13 GMT
Server: Apache
X-Powered-By: PHP/5.6.3
Cache-Control: no-cache
X-Powered-By: AppName/1.0.0
Connection: close
Content-Type: text/html; charset=UTF-8
唯一有效的方法是header_remove('X-Powered-By')
在调用->header
. 我不应该这样做,因为相应$replace
地设置了参数。
有没有更好的方法来防止X-Powered-By
标题的重复?