From: Christopher Faulet Date: Fri, 2 Oct 2026 19:19:11 +0000 (+0200) Subject: REGTESTS: filters: Exercise Lua probes around mixed built-in filters X-Git-Tag: v3.5-dev9~59 X-Git-Url: https://git.kaiwu.me/?a=commitdiff_plain;h=b4229ec6178d5d342be4621bb146a3387b714bfc;p=haproxy.git REGTESTS: filters: Exercise Lua probes around mixed built-in filters Inherit a chain combining Lua, trace, cache, compression and bandwidth filters from named defaults. Position Lua probes before and after request and response compression and verify the encoding each probe observes. Activate both bandwidth directions and validate the forwarded bodies. Populate the cache with an uncompressed body, replay it to a client not accepting gzip and verify that the response probes still run on a hit. Override compression and response bandwidth state on a sibling backend without changing the enabled sibling or the inherited Lua probes. --- diff --git a/reg-tests/filters/lua-mixed.vtc b/reg-tests/filters/lua-mixed.vtc new file mode 100644 index 000000000..d1fab181a --- /dev/null +++ b/reg-tests/filters/lua-mixed.vtc @@ -0,0 +1,141 @@ +varnishtest "Lua probes compose with caching, compression, trace and bandwidth filters" + +feature cmd "$HAPROXY_PROGRAM -cc 'feature(LUA) && (feature(SLZ) || feature(ZLIB))'" +feature ignore_unknown_macro + +server s1 { + rxreq + expect req.method == "POST" + expect req.http.x-probe-order == "M.pre;M.post;" + expect req.http.x-probe-encodings == "M.pre:identity;M.post:gzip;" + expect req.http.x-probe-errors == + expect req.http.content-encoding == "gzip" + gunzip + expect req.body == "request body" + txresp -hdr "Content-Type: text/plain" -body "compressed response" + + rxreq + expect req.url == "/cached" + expect req.http.x-probe-order == "M.pre;M.post;" + expect req.http.x-probe-encodings == "M.pre:identity;M.post:identity;" + expect req.http.x-probe-errors == + txresp -hdr "Content-Type: text/plain" -hdr "Cache-Control: max-age=60" -body "cached response" +} -start + +server s2 { + rxreq + expect req.http.x-probe-order == "M.pre;M.post;" + expect req.http.x-probe-encodings == "M.pre:identity;M.post:identity;" + expect req.http.x-probe-errors == + expect req.http.content-encoding == + expect req.body == "request body" + txresp -hdr "Content-Type: text/plain" -body "disabled response" +} -start + +haproxy h1 -conf { + global + chroot / + nbthread 1 + tune.lua.bool-sample-conversion normal + lua-load "${testdir}/lua-probe.lua" + cache c + total-max-size 1 + defaults plain + mode http + timeout connect "${HAPROXY_TEST_TIMEOUT-5s}" + timeout client "${HAPROXY_TEST_TIMEOUT-5s}" + timeout server "${HAPROXY_TEST_TIMEOUT-5s}" + + frontend fe from plain + bind "fd@${fe}" + use_backend uncompressed if { path /disabled } + default_backend compressed + + defaults mixed from plain + compression algo-req gzip + compression algo-res gzip + compression type-req text/plain + compression type-res text/plain + filter-config trace id observer enabled quiet + filter-config cache-store id c enabled + filter-config lua id probe-a enabled M pre data + filter-config lua id probe-b enabled M post + filter-config lua id probe-c M disabled + filter-config bwlim-in id upload enabled default-limit 1m default-period 1s + filter-config bwlim-out id download enabled default-limit 1m default-period 1s + # Move only the second probe after compression, on each channel. + filter-sequence request lua/probe-b:after(http-comp-req) + filter-sequence response lua/probe-b:after(http-comp-res) + + backend compressed from mixed + http-request cache-use c + http-response cache-store c + http-request set-bandwidth-limit upload + http-response set-bandwidth-limit download + server s1 ${s1_addr}:${s1_port} + + backend uncompressed from mixed + filter-disable http-comp-req http-comp-res bwlim-out/download + http-request set-bandwidth-limit upload + server s2 ${s2_addr}:${s2_port} +} -start + +client c1 -connect ${h1_fe_sock} { + txreq -req POST -url /post -hdr "Host: example.org" -hdr "Content-Type: text/plain" -hdr "Accept-Encoding: gzip" -body "request body" + rxresp + expect resp.status == 200 + expect resp.http.x-probe-order == "M.pre;M.post;" + expect resp.http.x-probe-encodings == "M.pre:identity;M.post:gzip;" + expect resp.http.x-probe-request-bytes == "M.pre:12;" + expect resp.http.x-probe-errors == + expect resp.http.content-encoding == "gzip" + gunzip + expect resp.body == "compressed response" + + txreq -url /cached -hdr "Host: example.org" -hdr "Accept-Encoding: gzip" + rxresp + expect resp.status == 200 + expect resp.http.x-probe-order == "M.pre;M.post;" + expect resp.http.x-probe-encodings == "M.pre:identity;M.post:gzip;" + expect resp.http.x-probe-errors == + expect resp.http.content-encoding == "gzip" + gunzip + expect resp.body == "cached response" + + # This response must come from the cache: no third server response exists. + # The cached body is plain and the response probes still run on a hit. + txreq -url /cached -hdr "Host: example.org" + rxresp + expect resp.status == 200 + expect resp.http.age >= 0 + expect resp.http.x-probe-order == "M.pre;M.post;" + expect resp.http.x-probe-encodings == "M.pre:identity;M.post:identity;" + expect resp.http.x-probe-errors == + expect resp.http.content-encoding == + expect resp.body == "cached response" + + # The sibling keeps the Lua and request bandwidth filters, but must not + # compress either direction or change the enabled sibling's instances. + txreq -req POST -url /disabled -hdr "Content-Type: text/plain" -hdr "Accept-Encoding: gzip" -body "request body" + rxresp + expect resp.status == 200 + expect resp.http.x-probe-order == "M.pre;M.post;" + expect resp.http.x-probe-encodings == "M.pre:identity;M.post:identity;" + expect resp.http.x-probe-request-bytes == "M.pre:12;" + expect resp.http.x-probe-errors == + expect resp.http.content-encoding == + expect resp.body == "disabled response" +} -run + +haproxy h1 -cli { + send "show filter instance compressed http-comp-res" + expect ~ "state: enabled, implicit, inherited\n" + send "show filter instance uncompressed http-comp-res" + expect ~ "state: disabled, implicit, inherited\n" + send "show filter instance compressed bwlim-out/download" + expect ~ "state: enabled, inherited\n" + send "show filter instance uncompressed bwlim-out/download" + expect ~ "state: disabled, inherited\n" + send "show filter instance compressed lua/probe-c" + expect ~ "state: disabled, inherited\n" +}