]> git.kaiwu.me - haproxy.git/commitdiff
MINOR: flt-http-comp: Stop to explicitly loop on the proxy's filter_configs list
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 27 Oct 2026 10:54:35 +0000 (11:54 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 27 Oct 2026 13:08:45 +0000 (14:08 +0100)
The "compression", "comp-req" and "comp-res" filter keyword parsers
scanned the filter_configs list of the proxy by hand to detect an
already declared compression filter configuration, matching on the
filter ids.

The parsers now use flt_find_conf(), the supported way to find a filter
configuration, which walks the right list depending on the filter mode of
the proxy. The "compression" duplicate check resolves the two possible
configurations with two successive lookups, one per direction.

src/flt_http_comp.c

index 15aa16610ace6be2b0d67d2f00e9c0c2099e8a95..4e577bd3bd76dd52f7669ff5c65e22835035aaf2 100644 (file)
@@ -1071,15 +1071,13 @@ static int
 parse_http_comp_flt(char **args, int *cur_arg, struct proxy *px,
                     struct flt_conf *fconf, char **err, void *private)
 {
-       struct flt_conf *fc, *back;
        struct flt_conf *fconf_res;
        struct comp *comp;
 
-       list_for_each_entry_safe(fc, back, &px->filter_configs, list) {
-               if (fc->id == http_comp_req_flt_id || fc->id == http_comp_res_flt_id) {
-                       memprintf(err, "%s: Proxy supports only one compression filter\n", px->id);
-                       return -1;
-               }
+       if (flt_find_conf(px, http_comp_req_flt_id, FLT_SIDE_GLOBAL, NULL, NULL) ||
+           flt_find_conf(px, http_comp_res_flt_id, FLT_SIDE_GLOBAL, NULL, NULL)) {
+               memprintf(err, "%s: Proxy supports only one compression filter\n", px->id);
+               return -1;
        }
 
        /* Allocate the compression options now, they will be filled by the
@@ -1130,14 +1128,11 @@ static int
 parse_http_comp_req_flt(char **args, int *cur_arg, struct proxy *px,
                         struct flt_conf *fconf, char **err, void *private)
 {
-       struct flt_conf *fc, *back;
        struct comp *comp;
 
-       list_for_each_entry_safe(fc, back, &px->filter_configs, list) {
-               if (fc->id == http_comp_req_flt_id) {
-                       memprintf(err, "%s: Proxy supports only one comp-req filter\n", px->id);
-                       return -1;
-               }
+       if (flt_find_conf(px, http_comp_req_flt_id, FLT_SIDE_GLOBAL, NULL, NULL)) {
+               memprintf(err, "%s: Proxy supports only one comp-req filter\n", px->id);
+               return -1;
        }
 
        comp = proxy_get_comp(px, 0);
@@ -1159,14 +1154,11 @@ static int
 parse_http_comp_res_flt(char **args, int *cur_arg, struct proxy *px,
                         struct flt_conf *fconf, char **err, void *private)
 {
-       struct flt_conf *fc, *back;
        struct comp *comp;
 
-       list_for_each_entry_safe(fc, back, &px->filter_configs, list) {
-               if (fc->id == http_comp_res_flt_id) {
-                       memprintf(err, "%s: Proxy supports only one comp-res filter\n", px->id);
-                       return -1;
-               }
+       if (flt_find_conf(px, http_comp_res_flt_id, FLT_SIDE_GLOBAL, NULL, NULL)) {
+               memprintf(err, "%s: Proxy supports only one comp-res filter\n", px->id);
+               return -1;
        }
 
        comp = proxy_get_comp(px, 0);