From: Christopher Faulet Date: Tue, 29 Sep 2026 13:51:49 +0000 (+0200) Subject: MEDIUM: flt-http-comp: Enable compression directions from algorithms X-Git-Tag: v3.5-dev9~100 X-Git-Url: https://git.kaiwu.me/?a=commitdiff_plain;h=0926d4dd9304e1158bcf3649535cc57ee9a4fd33;p=haproxy.git MEDIUM: flt-http-comp: Enable compression directions from algorithms Compression options used to default to the response direction, even when only a request algorithm was configured. Request compression then needed an explicit direction or comp-req filter declaration. Also, the initial direction depended on whether a filter declaration or a compression option allocated the configuration first. Start with no direction and let algo-req enable request compression and algo/algo-res enable response compression. Add COMP_FL_DIR_FORCED to remember an explicit compression direction, so that subsequent algorithm directives do not re-enable a direction it excluded. This flag is also inherited from defaults along with the other compression settings. Only algorithm and direction directives enable compression implicitly. Type, minimum-size and offload options configure its behavior but do not enable a direction by themselves. Without an algorithm for that direction, no compression can take place anyway. This also avoids implicitly enabling response compression just because request compression options were parsed before an explicit comp-req filter. The legacy compression algo directive still enables responses. --- diff --git a/include/haproxy/compression-t.h b/include/haproxy/compression-t.h index fac475eee..39e417571 100644 --- a/include/haproxy/compression-t.h +++ b/include/haproxy/compression-t.h @@ -44,6 +44,7 @@ #define COMP_FL_OFFLOAD 0x00000001 /* Compression offload */ #define COMP_FL_DIR_REQ 0x00000002 /* Compress requests */ #define COMP_FL_DIR_RES 0x00000004 /* Compress responses */ +#define COMP_FL_DIR_FORCED 0x00000008 /* Compress direction was forced */ struct comp { struct comp_algo *algos_res; /* Algos available for response */ diff --git a/src/flt_http_comp.c b/src/flt_http_comp.c index a5e3c0a6f..1d6ca1a9c 100644 --- a/src/flt_http_comp.c +++ b/src/flt_http_comp.c @@ -857,8 +857,8 @@ parse_compression_options(char **args, int section, struct proxy *proxy, int ret = 0; const char *res; - /* always default to compress responses */ - comp = proxy_get_comp(proxy, COMP_FL_DIR_RES); + /* Algorithms enable their direction unless an explicit direction was set. */ + comp = proxy_get_comp(proxy, 0); if (comp == NULL) { memprintf(err, "'%s': out of memory.", args[0]); ret = -1; @@ -899,6 +899,8 @@ parse_compression_options(char **args, int section, struct proxy *proxy, cur_arg++; continue; } + if (!(comp->flags & COMP_FL_DIR_FORCED)) + comp->flags |= COMP_FL_DIR_RES; } else if (strcmp(args[1], "algo-req") == 0) { struct comp_ctx *ctx; @@ -923,6 +925,8 @@ parse_compression_options(char **args, int section, struct proxy *proxy, ret = -1; goto end; } + if (!(comp->flags & COMP_FL_DIR_FORCED)) + comp->flags |= COMP_FL_DIR_REQ; } else if (strcmp(args[1], "offload") == 0) { if (proxy->cap & PR_CAP_DEF) { @@ -1002,12 +1006,12 @@ parse_compression_options(char **args, int section, struct proxy *proxy, } if (strcmp(args[2], "request") == 0) { comp->flags &= ~COMP_FL_DIR_RES; - comp->flags |= COMP_FL_DIR_REQ; + comp->flags |= (COMP_FL_DIR_FORCED | COMP_FL_DIR_REQ); } else if (strcmp(args[2], "response") == 0) { comp->flags &= ~COMP_FL_DIR_REQ; - comp->flags |= COMP_FL_DIR_RES; + comp->flags |= (COMP_FL_DIR_FORCED | COMP_FL_DIR_RES); } else if (strcmp(args[2], "both") == 0) - comp->flags |= COMP_FL_DIR_REQ | COMP_FL_DIR_RES; + comp->flags |= (COMP_FL_DIR_FORCED | COMP_FL_DIR_REQ | COMP_FL_DIR_RES); else { memprintf(err, "'%s' expects 'request', 'response', or 'both'.", args[0]); ret = -1;