alphagov/cdn-acceptance-tests — pull request #97 by dcarley (2014-09-04 10:19:22+00:00)
Title: Add test for Accept-Encoding with gzip compression

This is probably the most important use of the `Vary` header which prevents
compression content from being sent to clients that don't support it and
vice versa. However it seems that the implementation is slightly different
on each vendor:

- Varnish (mocks)

Doesn't require `Vary` in the response and doesn't inject the header
itself back to the client. It only makes a single request to origin,
always asking for gzip regardless of what the client asked for, then it
will store the gzip object and decompress it for clients that haven't
asked for gzip.

- CloudFlare

Support this despite `TestCacheVary` not passing. You don't need to add a
`Vary` header in the response, but they inject this back to the client
anyway.

- Fastly

Works as expected. Does require `Vary` on the response. Only seem to make
a single origin request because they're using Varnish 2.x before (native
gzip support was added).

The `client.DisableCompression` isn't strictly necessary because, looking at
the code, the transport won't do this if the request already has an
`Accept-Encoding` header and we're adding a dummy value when we don't want
gzip. However I think it's better to be explicit.

It's also worth noting that we use an empty string value to indicate that no
`Content-Encoding` header is sent back in the uncompressed response. This is
just what `net/http` does.

---

Based on a conversation with @samjsharpe the other day. This might make us more comfortable with skipping the Vary test for CF for the moment.