multiple vary headers and gzip

Jeff Kaufman jefftk at google.com
Thu Dec 12 16:29:14 UTC 2013


In the ngx_pagespeed module we produce css files which refer to either
foo.webp or foo.jpg depending on whether the user agent we're serving
them to advertises webp support in the Accept header.  We would like
to serve these publicly cacheable with "Vary: Accept".  Because css is
text-based these should also be gzipped when serving to user agents
that advertise gzip in the Accept-Encoding header, which means
including "Vary: gzip".

Currently this means these css files will be served with:

    Vary: Accept
    Vary: Accept-Encoding

We would rather serve these as:

    Vary: Accept, Accept-Encoding

because many user agents don't properly handle multiple headers with
the same name.

We're considering adding code to our module like:

#if (NGX_HTTP_GZIP)
  if (r->gzip_vary == 1 && vary_header_already_present(r)) {
     r->gzip_vary = 0;
     add_accept_encoding_to_existing_vary_header(r);
  }
#endif

This is based on the corresponding code from ngx_http_header_filter_module.cc.

This isn't an ideal solution because it couples us more tightly than
we'd like to an aspect of nginx internals we're currently relatively
separate from, but it's the best we have at the moment.  Is there
something that would be better for us to do here?

(We also considered trying to add a filter after
ngx_http_header_filter_module that coalesces duplicate headers with
the same name, but it doesn't seem to be possible to modify headers at
that stage.)

Jeff Kaufman



More information about the nginx-devel mailing list