Accessing HTTP request headers in nginx module

Maxim Dounin mdounin at mdounin.ru
Fri Mar 28 13:07:10 UTC 2014


Hello!

On Fri, Mar 28, 2014 at 01:06:00AM +0100, Mapper Uno wrote:

> Thanks for reply. However, I am still not clear how to access the
> "custom" headers in module handler. Pls see my comments inline.
> 
> B.R. wrote in post #1141281:
> > In nginx, you have the http_<header name> embedded variable in the core
> > module
> > <http://nginx.org/en/docs/http/ngx_http_core_module.html#variables>to
> > access HTTP headers.
> I can see that variables can be accessed by http_<header name>, however
> the link says "names matching the Apache Server variables", which to me
> indicates that these are not "custom" headers. With reference to my
> above example, how can I access my custom header "OPERATION" in module
> handler ?

Please make sure to read not only the first sentence.  Note the 
"Also there are other variables" in the same paragraph.  The 
$http_* variables provide access to all headers, including any 
custom ones.  And it is documented as:

$http_name
arbitrary request header field; the last part of a variable name 
is the field name converted to lower case with dashes replaced by 
underscores

Therefore, you may either use the $http_operation variable to 
access the header you are looking for.  Or you may take a look at 
the source code to find out how it's implemented.  Take a look at 
the src/http/ngx_http_variables.c, functions 
ngx_http_variable_unknown_header_in() and 
ngx_http_variable_unknown_header() (first one says the header 
should be searched in r->headers_in.headers list, second one does 
actual search).

-- 
Maxim Dounin
http://nginx.org/



More information about the nginx mailing list