Does the nginx support "Header append."?

For Apache Httpd the “Header” directive can “append” a value to the
exsisting headers of the same name.

e.g.

Before: Vary: Host

Header append Vary User-Agent

After: Vary: Host, User-Agent

But for Nginx, neither “add_header” nor “more_set_headers” directive can
“append” a value to an exsisting headers.

Especially, the “more_set_headers” will create a duplicate headers of
the same name. i.e.

Vary: Host
Vary: User-Agent

So, What’s the reason for it? How should I do for the “append”?

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,179060,179060#msg-179060

On Mon, Feb 28, 2011 at 5:36 PM, sunjipeng_neu [email protected]
wrote:

But for Nginx, neither “add_header” nor “more_set_headers” directive can
“append” a value to an exsisting headers.

Yes, ngx_headers_more does not support header appending yet. But it is
a TODO and patches are also welcomed.

Especially, the “more_set_headers” will create a duplicate headers of
the same name. i.e.

Vary: Host
Vary: User-Agent

I cannot reproduce this with nginx 0.8.54 + ngx_headers_more v0.14.
I’m using the following test case:

location /foo {
    more_set_headers 'Vary: gbk';
    echo hello;
}

location /len {
    default_type 'text/plain';
    more_set_headers 'Vary: hello';
    proxy_pass http://127.0.0.1:$server_port/foo;
}

Then we get

$ curl localhost:1984/len
HTTP/1.1 200 OK
Server: nginx/0.8.54 (without pool)
Date: Tue, 01 Mar 2011 08:52:13 GMT
Content-Type: text/plain
Connection: keep-alive
Content-Length: 6
Vary: hello

hello

$ curl localhost:1984/foo
HTTP/1.1 200 OK
Server: nginx/0.8.54 (without pool)
Date: Tue, 01 Mar 2011 08:51:31 GMT
Content-Type: text/plain
Transfer-Encoding: chunked
Connection: keep-alive
Vary: gbk

hello

Note that accessing /len does not yield duplicate Vary headers. Using
telnet gives exactly the same results.

Could you please provide a minimal sample config that could reproduce
this problem? It’s preferable to create a ticket at the GitHub issues
panel though:

https://github.com/agentzh/headers-more-nginx-module/issues

So, What’s the reason for it? How should I do for the “append”?

ngx_lua does allow header append, but may not be meaningful in your
context. Here’s a small Lua example though:

ngx.header[“Vary”] = ngx.header[“Vary”] … “, UserAgent”

It seems like a good chance to implement the
“output_header_filter_by_lua” directive :wink:

Cheers,
-agentzh

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs