cphalcon icon indicating copy to clipboard operation
cphalcon copied to clipboard

[BUG] missing custom header in output from request->getHeaders()

Open zdenekgebauer opened this issue 12 years ago • 23 comments

Array returned from native php functions getallheaders() and apache_request_headers() contains item "Authorization" (header injected via angular), but output from $this->request->getHeaders() don't. Expected result: request->getHeaders() should return all available headers

Tested on: phalcon 1.3.0, Apache/2.4.4 (Win32) PHP/5.4.16

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

zdenekgebauer avatar Apr 03 '14 09:04 zdenekgebauer

same problem on phalcon 1.3.1, Apache/2.4.4 (Win32) PHP/5.4.16

zdenekgebauer avatar Apr 03 '14 09:04 zdenekgebauer

Same problem.

But $_SERVER['PHP_AUTH_USER'] and $req->getBasicAuth() work.

ghost avatar Apr 03 '14 13:04 ghost

Same here, phalcon 1.3.1 ,Apache/2.2.22 , Ubuntu

chrobakos avatar Jun 04 '14 07:06 chrobakos

Any update on this? I got the same issue

Phalcon 1.3.0, PHP 5.4.8, Apache/2.2.26, Mac 10.9.3

nazieb avatar Jun 20 '14 04:06 nazieb

I used php's getallheaders() instead

chrobakos avatar Jun 20 '14 06:06 chrobakos

Same problem here with Phalcon 1.3.2, PHP 5.4.12, Apache/2.4.4, Win7

MickaelViaud avatar Jul 15 '14 10:07 MickaelViaud

Wasted 2 days, missed deliverable date because of this minor tiny issue.....

No updates?

smorhaim-original avatar Sep 18 '14 00:09 smorhaim-original

I am so happy to search the method getHeader() before using it and wasting days. when will this be fixed?

AndreBaumeier avatar Sep 22 '14 02:09 AndreBaumeier

+1

rzajac avatar Oct 05 '14 22:10 rzajac

+1

robertsmolarek avatar Oct 23 '14 10:10 robertsmolarek

Be aware, the above pull-request is for v2.0.0

rianorie avatar Nov 09 '14 19:11 rianorie

+1

renhyl avatar Jan 06 '15 23:01 renhyl

btw $app->request->getHeader() does not grab custom header too.

renhyl avatar Jan 06 '15 23:01 renhyl

if your header is: X-SOMETHING-ELSE you can get it with $app->request->getHeader('HTTP_X_SOMETHING_ELSE');

dragosdm avatar Jan 30 '15 14:01 dragosdm

me too same problem with Phalcon 1.3.2

santosh-x avatar Mar 05 '15 06:03 santosh-x

phalcon 2.0.0 too

w3yyb avatar May 11 '15 03:05 w3yyb

Phalcon 2.0.10 is affected too. IMHO Request->getHeaders() should simply return getallheaders()

Any good reason for header checks in Request->getHeader() ?

nask0 avatar Mar 29 '16 17:03 nask0

I confirm that Phalcon 2.0.10 is affected as well! Imho this needs a quick fix!

micheleangioni avatar Apr 20 '16 18:04 micheleangioni

The implementation seems to be correct. The implementation also happens to be very similart to Zend Framework's implementation as well.

The Issue seems to be that the users are using PHP as a CGI/FastCGI. We will need to do some .htaccess magic in order for it to appear in request->getHeaders();

Something like this maybe? -

# On .htaccess
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1] # Authorization will now be returned by getHeaders()

The reason why getAllHeaders() works is because it actually calls an Apache function to get all the headers. One thing we need to take into account is that not everyone uses Apache as their server! While I haven't tried this, I would imagine this would be an issue in say NGINX or even IIS.

I guess there are two ways we can go about addressing this "bug" -

  1. Check if apache_request_headers() returns anything, then use that otherwise use ​_SERVER with keys starting with HTTP_​ (current implementation).
  2. Update the documentation stating that if you want to capture custom headers, you will need to update .htaccess

I prefer the second option because of the reasons stated above.

References - Zend implementation - https://github.com/zendframework/zend-xmlrpc/blob/master/src/Request/Http.php#L81

Phalcon implementation - https://github.com/phalcon/cphalcon/blob/2.1.x/phalcon/http/request.zep#L791

rahuldroy avatar Jun 10 '16 13:06 rahuldroy

@andresgutierrez / @sergeyklay,

Are we going to do some changes for this based on the previous comment?

rahuldroy avatar Jul 06 '16 05:07 rahuldroy