KaiserJohaan KaiserJohaan - 6 days ago 4
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());
exit();

}


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.

Answer

I finally found the answer here:

http://zend-framework-community.634137.n4.nabble.com/HTTP-Digest-authentication-does-not-work-with-PHP-as-CGi-td4658790.html

Had to add the following to the projects .htaccess:

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