# Does the nginx support "Header append."?

**URL:** <https://www.ruby-forum.com/t/does-the-nginx-support-header-append/203824>\
**Category:** NGINX\
**Created:** [February 28, 2011, 10:37am UTC](https://www.ruby-forum.com/t/does-the-nginx-support-header-append/203824 "2011-02-28T10:37:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [February 28, 2011, 10:37am UTC](https://www.ruby-forum.com/t/does-the-nginx-support-header-append/203824/1 "2011-02-28T10:37:49Z")

</div>

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:

> **[Does the nginx support "Header append ..."?](https://forum.nginx.org/read.php?2,179060,179060#msg-179060)**
>
> 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 Bu

---

<div class="post-metadata">

**Author:** ![sunjipeng\_neu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b487fb/32.png) [@sunjipeng\_neu](https://www.ruby-forum.com/u/sunjipeng_neu)\
**Post date:** [March 1, 2011, 10:00am UTC](https://www.ruby-forum.com/t/does-the-nginx-support-header-append/203824/2 "2011-03-01T10:00:28Z")

</div>

On Mon, Feb 28, 2011 at 5:36 PM, sunjipeng\_neu [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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 😉

Cheers,  
-agentzh
