Continuation of: Setting response headers with middleware in Lumen
When using the following exception handler in Lumen, the X-Powered-By
header is duplicated, even though $replace
(the third parameter of the header()
method) defaults to true (even setting it manually, as below, does not work).
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);
}
The response header:
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
The only thing that works is to use header_remove('X-Powered-By')
just before the call to ->header
. I should not have to do this, due to the $replace
parameter being set accordingly.
Are there any better ways to prevent the duplication of the X-Powered-By
header?