]> git.kaiwu.me - haproxy.git/commitdiff
REG-TESTS: decompression: check the response header rewriting
authorWilly Tarreau <w@1wt.eu>
Fri, 21 Aug 2026 08:24:54 +0000 (10:24 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 28 Aug 2026 15:26:38 +0000 (17:26 +0200)
Covers two of the fixes in this series: an unrelated "Vary" value that is a
prefix of "accept-encoding" ("Vary: Accept") must survive, a strong ETag
must be weakened since the representation changed, and a content coding
which is only a prefix of a configured algorithm ("Content-Encoding: g")
must not engage decompression.

The case-insensitive comparison of the coding is not covered: vtest always
emits its own lower-cased Content-Encoding next to the one given with -hdr,
so the response carries both and the test would pass either way.

reg-tests/decompression/headers.vtc [new file with mode: 0644]

diff --git a/reg-tests/decompression/headers.vtc b/reg-tests/decompression/headers.vtc
new file mode 100644 (file)
index 0000000..5b66308
--- /dev/null
@@ -0,0 +1,61 @@
+varnishtest "Decompression: response header rewriting"
+
+feature cmd "$HAPROXY_PROGRAM -cc 'feature(SLZ)'"
+feature ignore_unknown_macro
+
+server s1 {
+       # 1. an unrelated Vary value must survive, and a strong ETag must be
+       #    weakened since we alter the representation
+       rxreq
+       expect req.url == "/vary"
+       txresp \
+         -hdr "Content-Encoding: gzip" \
+         -hdr "Vary: Accept" \
+         -hdr "ETag: \"strong\"" \
+         -gzipbody "decompressed"
+
+       # 2. a coding which is only a prefix of a configured algo must not
+       #    engage decompression
+       rxreq
+       expect req.url == "/prefix"
+       txresp -hdr "Content-Encoding: g" -body "not compressed at all"
+} -start
+
+haproxy h1 -conf {
+    global
+    .if feature(THREAD)
+        thread-groups 1
+    .endif
+
+    defaults
+       mode http
+       timeout connect "${HAPROXY_TEST_TIMEOUT-5s}"
+       timeout client  "${HAPROXY_TEST_TIMEOUT-5s}"
+       timeout server  "${HAPROXY_TEST_TIMEOUT-5s}"
+
+    listen decomp-http
+       mode http
+       bind "fd@${decomp_http}"
+       decompression algo-res gzip
+       decompression mode-res auto
+       filter decomp-res
+       server s1 ${s1_addr}:${s1_port}
+} -start
+
+client c1 -connect ${h1_decomp_http_sock} {
+       txreq -url "/vary"
+       rxresp
+       expect resp.status == 200
+       expect resp.body == "decompressed"
+       expect resp.http.content-encoding == "<undef>"
+       # "Accept" is a prefix of "accept-encoding" but a distinct value
+       expect resp.http.vary == "Accept"
+       expect resp.http.etag == "W/\"strong\""
+
+       txreq -url "/prefix"
+       rxresp
+       expect resp.status == 200
+       # "g" is not a supported coding, the body must pass through untouched
+       expect resp.body == "not compressed at all"
+       expect resp.http.content-encoding == "g"
+} -run