]> git.kaiwu.me - haproxy.git/commitdiff
MINOR: flt-http-comp: Don't uselessly init a compression filter
authorChristopher Faulet <cfaulet@haproxy.com>
Mon, 5 Oct 2026 06:30:05 +0000 (08:30 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 9 Oct 2026 14:17:35 +0000 (16:17 +0200)
When a compression filter, request or response, is attached to a stream,
there was no special test to know if the filter will be usable, so when its
direction was not enabled or no algorithm was available for it on the proxy
that declared it.

Now the attach callback returns 0 when the direction is not enabled or when
the compression configuration has no algorithm for the filter's direction,
so the filter is not attached to the stream at all. Its per-stream state is
not allocated and its HTTP callbacks are never called; these filters were
already ignored by the http_headers callback, they are just not instantiated
anymore.

A NULL configuration is also tolerated, so that an implicit instance
inherited by a proxy without the matching capability can keep its metadata
without applicable options.

The check uses the compression options stored in the filter configuration by
the preceding change, and only inspects the proxy that declared the
filter. When the algorithms are configured on the other proxy, that proxy
also gets an implicit filter for the direction, so an instance with a local
algorithm remains attached to perform the compression. This also prepares
the filter instances, where the same options are shared by the legacy
configurations and the instances.

src/flt_http_comp.c

index c90c232064b629010faa142a99839124de3e5b63..0c3650e978313d9fa5982ed971c770adbb0dd56b 100644 (file)
@@ -68,8 +68,16 @@ comp_flt_init(struct proxy *px, struct flt_conf *fconf)
 static int
 comp_strm_init(struct stream *s, struct filter *filter)
 {
+       struct comp *comp = FLT_CONF(filter);
        struct comp_state *st;
 
+       if (filter->config->id == http_comp_req_flt_id &&
+           (!comp || !comp->algo_req || !(comp->flags & COMP_FL_DIR_REQ)))
+               return 0;
+       else if (filter->config->id == http_comp_res_flt_id &&
+                (!comp || !comp->algos_res || !(comp->flags & COMP_FL_DIR_RES)))
+               return 0;
+
        st = pool_alloc(pool_head_comp_state);
        if (st == NULL)
                return -1;