headers-more-nginx-module icon indicating copy to clipboard operation
headers-more-nginx-module copied to clipboard

Add headers if not set.

Open SamMousa opened this issue 9 years ago • 3 comments

Currently this module adds support for a combined set/add which overwrites or adds a header, meaning the value of the header is always changed.

It would be great if it could also offer a set/skips function which sets if not present and skips otherwise.

SamMousa avatar Jul 12 '16 09:07 SamMousa

@SamMousa Patches welcome. BTW, such requirements can be easily and efficiently done via the ngx_http_lua module:

https://github.com/openresty/lua-nginx-module/

That's why I'm reluctant to develop more and more such little things myself in this simple module.

agentzh avatar Jul 15 '16 20:07 agentzh

Another way to achieve that might be through a map, e.g. something like this:

map $sent_http_referrer_policy $referrer_policy {
    ""         "strict-origin-when-cross-origin";
    default    $sent_http_referrer_policy;
}
....
more_set_headers "Referrer-Policy: $referrer_policy";

Certainly, a short more_set_headers -i as in #65 offers significanlty better maintainability and readability, but the above solution should work too.

mkasimd avatar Apr 21 '21 22:04 mkasimd