2

I am also having this issue on an EC2 instance with the latest Amazon Linux build. The getallheaders() function doesn't work when on nginx. All of the posted replacements for getallheaders() only get values from $_SERVER. The problem is that the headers I need are not there.

I am testing my original implementation using Postman (a Chrome App). It has a Headers tab and a Body tab. I can find the entries in the Body tab in the $_POST array. The entries in the Headers tab are not there or in any of the other global arrays.

The code I'm working on is a web service for an app (that I don't control), so I can't change the nature of the calls.

Here are the Headers that I get when calling getallheaders() running on Apache (I removed a few for clarity):

Array
(
    [Host] => api.dashforhealth.com
    [Connection] => keep-alive
    [Cache-Control] => no-cache
    [Origin] => chrome-extension://fhbjgbiflinjbdggehcddcbncdddomop
    [api_key] => this-is-not-the-real-api-key
    [Content-Type] => application/x-www-form-urlencoded
    [Postman-Token] => 76069288-e74e-3791-eb42-f166454d8822
    [auth_key] => this-is-not-the-real-auth-key
    [Accept] => */*
)

The two I'm interested in are api_key and auth_key. How can I get these headers when running in nginx?

Richard Erickson
  • 2,568
  • 8
  • 26
  • 39

1 Answers1

1

There appears to be a setting for this: underscores_in_headers

http://nginx.org/en/docs/http/ngx_http_core_module.html#underscores_in_headers

iewebguy
  • 316
  • 3
  • 16
  • 1
    That solves the problem. I added `underscores_in_headers on;` to the nginx config file for that domain and I can get the headers I need from `$_SERVER`. – Phil Marshall Mar 25 '16 at 14:52