First things first:

Yes, I'm aware that this is shortly before 2.0. Either put this into 2.0
or put this into `next` if you consider it too risky (or just wait until
2.0 release before merging).

Also *add backporting instructions*, please. I recommend to backport it to
2.0 at the least.

That said:

This thread contains two "competing" patches to fix the BUG that HAProxy
does not set the `Vary` response header when the compression filter is
applied. When not setting the `Vary` header the response may be miscached
by intermediate caching proxies.

Please select the one you like better, because I wasn't sure. I'll explain
the differences below:

PATCH 1 (the one *without* v2):

This one attempts to only set the `Vary` response header when it's
*required* to not pollute responses that are never going to be compressed
based on the current configuration (e.g. because the Content-Type is not
listed in `compression type`).

To do so the patch adds a new `would_compress` flag and requires careful
checking in `htx_set_comp_reshdr`:

1. All the response conditions must go first.
2. Then the `would_compress` flag must be set.
3. Then the other conditions (e.g. compression rate) must be checked.

Otherwise the `would_compress` flag might be missing due to a temporary
condition, leading to a missing `Vary` header, leading to bugs.

PATCH 2 (the one *with* v2):

This one is more stupid: If compression is enabled for the proxy it sets
the `Vary` header unconditionally. Nothing can go wrong here, but it sets
the header for responses where it is not required. This type of responses
tend to be binary files which usually are rather large, taking up valuable
space in downstream proxies by possibly being cached multiple times (once
per `Accept-Encoding` request header).

Best regards

Tim Duesterhus (1):
  BUG/MEDIUM: compression: Set Vary: Accept-Encoding if the response
    would be compressed

 reg-tests/compression/vary.vtc | 187 +++++++++++++++++++++++++++++++++
 src/flt_http_comp.c            |  81 ++++++++++----
 2 files changed, 248 insertions(+), 20 deletions(-)
 create mode 100644 reg-tests/compression/vary.vtc


Reply via email to