Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get non-standard HTTP headers on nginx?

Tags:

I have a very simple question to the nginx experts out there. This is possibly a bug.

In nginx 1.0.5, given the following nginx.conf:

server {     server_name myserver;      location / {         uwsgi_pass 127.0.0.1:5001;         uwsgi_param HTTP_MY_CUSTOM_HEADER $http_my_custom_header;         include uwsgi_params;            } } 

Why does this works as expected...

$ curl -H "My-Custom-Header: Yes" http://myserver/ 

...but this doesn't.

$ curl -H "MY_CUSTOM_HEADER: Yes" http://myserver/ 

In the latter case, the parameter is passed to my uwsgi application, but it's just an empty string. I know HTTP headers are supposed to be case-insensitive, but nginx behavior is unexpected when the header doesn't follow the usual format (title-cased, underscores instead of dashes).

Anyone had similar need to capture custom headers? Any nginx.conf examples?

like image 609
hcalves Avatar asked Dec 06 '11 00:12

hcalves


People also ask

Can HTTP headers be custom?

There are many uses for custom headers and they are quite commonly used. Even if you aren't using a CDN or haven't specifically defined any custom HTTP headers on your origin server, you may still be sending responses with custom headers.

How do I enable HTTP headers?

Select the web site where you want to add the custom HTTP response header. In the web site pane, double-click HTTP Response Headers in the IIS section. In the actions pane, select Add. In the Name box, type the custom HTTP header name.

How do I add HTTP request header?

To add custom headers to an HTTP request object, use the AddHeader() method. You can use this method multiple times to add multiple headers. For example: oRequest = RequestBuilder:Build('GET', oURI) :AddHeader('MyCustomHeaderName','MyCustomHeaderValue') :AddHeader('MySecondHeader','MySecondHeaderValue') :Request.


1 Answers

Nevermind, figured out there's a setting to it:

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

like image 193
hcalves Avatar answered Oct 16 '22 12:10

hcalves