From 9549b05b9477ff0e147bcc1fa0cb21ac562efac6 Mon Sep 17 00:00:00 2001 From: Aurelien DARRAGON Date: Thu, 5 Mar 2026 19:00:09 +0100 Subject: [PATCH] MINOR: flt_http_comp: define and use proxy_get_comp() helper function proxy_get_comp() function can be used to retrieve proxy->comp options or allocate and initialize it if missing For now, it is solely used by parse_compression_options(), but the goal is to be able to use this helper from multiple origins. --- src/flt_http_comp.c | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/src/flt_http_comp.c b/src/flt_http_comp.c index 79dbcb84a..6a744f401 100644 --- a/src/flt_http_comp.c +++ b/src/flt_http_comp.c @@ -782,6 +782,27 @@ struct flt_ops comp_ops = { .http_end = comp_http_end, }; +/* returns compression options from proxy or allocates them if + * needed + * + * When compression options are created, flags will be set to + * + * Returns NULL in case of memory error + */ +static inline struct comp *proxy_get_comp(struct proxy *proxy, int defaults) +{ + struct comp *comp; + + if (proxy->comp == NULL) { + comp = calloc(1, sizeof(*comp)); + if (unlikely(!comp)) + return NULL; + comp->flags = defaults; + proxy->comp = comp; + } + return proxy->comp; +} + static int parse_compression_options(char **args, int section, struct proxy *proxy, const struct proxy *defpx, const char *file, int line, @@ -791,19 +812,13 @@ parse_compression_options(char **args, int section, struct proxy *proxy, int ret = 0; const char *res; - if (proxy->comp == NULL) { - comp = calloc(1, sizeof(*comp)); - if (unlikely(!comp)) { - memprintf(err, "'%s': out of memory.", args[0]); - ret = -1; - goto end; - } - /* Always default to compress responses */ - comp->flags = COMP_FL_DIR_RES; - proxy->comp = comp; + /* always default to compress responses */ + comp = proxy_get_comp(proxy, COMP_FL_DIR_RES); + if (comp == NULL) { + memprintf(err, "'%s': out of memory.", args[0]); + ret = -1; + goto end; } - else - comp = proxy->comp; if (strcmp(args[1], "algo") == 0 || strcmp(args[1], "algo-res") == 0) { struct comp_ctx *ctx;