KaiserJohaan KaiserJohaan - 7 months ago 80
HTTP Question

Getting request Authorization header in ZF2 controller

I am using ZF2 and for some reason, I can get all the headers I send EXCEPT the Authorization header - it's like its filtered out.

I am trying to get all the headers in the controller like this:

public function createAction($data)
$request = $this->request;
print_r ($request->getHeaders());


I send the request through cURL like this:

curl -i -H "Accept: test" -H "Authorization: 123456" -H "Content-Type: qwerty" -X POST http://localhost/test

All headers prints out EXCEPT authorization header. I can add any arbitrary header and it prints it out - just no the 'Authorization' header...

I've also tried to get()/has() for the authorization header, yet it does not exist.


I finally found the answer here:


Had to add the following to the projects .htaccess:

RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]