After two days’ work, I’ve now got the “headers_more” module passing
the its own test suite. This is an enhanced version of the standard
“headers” module because it provides more utilities like resetting or
clearing output headers. Builtin headers, like “Content-Type”,
“Content-Length”, and “Server”, are also manipulatable
It also allows you to specify an optional HTTP status code criteria
using the -s option and an optional content type criteria using the -t
option.
One important TODO is to allow variables within the new headers’
values. That’s where “headers_more” is “less” than the standard
“headers” module
Okay, I’ve just shamelessly stolen the implementation directly from
the standard “headers” module, and made variables-in-header-values
work as expected. For example,
set $my_server 'Super Star Server';
more_set_headers 'Server: $my_server';
But another TODO comes into my mind: adding support for input headers!
Stay tuned
Okay, the input header support has finally landed in v0.05 after a few
hours’ big refactoring and hacking. Here’s some funny examples:
location /foo {
set $my_host 'my dog';
more_set_input_headers 'Host: $my_host';
more_set_input_headers -t 'text/plain' 'X-Foo: bah';
# now $host and $http_host have their new values...
}
The “input header filter” runs in the access phase. I’m not sure if
it’s completely right but this phase lets me pass all the related
tests in
Theoretically it should also work with subrequests. But unfortunately
the ngx_http_subrequest function in the core seems to be buggy
regarding r->headers_in handling IIRC. So be careful with that
Thanks Cliff W. for providing such an excellent
facility that makes
me much more motivated to write documentation
Great work… this will be invaluable for conditionally adding keywords
like “public” to Cache-Control headers (which is necessary for clients
to persistently cache SSL resources in most browsers). Should
drastically simplify configuration files.
Does anyone know if there any plans to move the “headers_more” module
(or any of the others) into the mainline nginx code base? It would be
very nice to have this in a stable release someday…