【发布时间】:2015-05-23 08:17:37
【问题描述】:
续:Setting response headers with middleware in Lumen
在 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 之前使用header_remove('X-Powered-By')。我不应该这样做,因为 $replace 参数已相应设置。
有没有更好的方法来防止X-Powered-By 标头重复?
【问题讨论】:
标签: php http-headers lumen