diff --git a/include/haproxy/compression-t.h b/include/haproxy/compression-t.h index 685110331..346cf2e51 100644 --- a/include/haproxy/compression-t.h +++ b/include/haproxy/compression-t.h @@ -43,8 +43,10 @@ #define COMP_FL_OFFLOAD 0x00000001 /* Compression offload */ struct comp { - struct comp_algo *algos; - struct comp_type *types; + struct comp_algo *algos_res; /* Algos available for response */ + struct comp_algo *algo_req; /* Algo to use for request */ + struct comp_type *types_req; /* Types to be compressed for requests */ + struct comp_type *types_res; /* Types to be compressed for responses */ unsigned int flags; }; diff --git a/include/haproxy/compression.h b/include/haproxy/compression.h index ba2bdab7c..851ea2393 100644 --- a/include/haproxy/compression.h +++ b/include/haproxy/compression.h @@ -27,8 +27,8 @@ extern unsigned int compress_min_idle; -int comp_append_type(struct comp *comp, const char *type); -int comp_append_algo(struct comp *comp, const char *algo); +int comp_append_type(struct comp_type **types, const char *type); +int comp_append_algo(struct comp_algo **algos, const char *algo); #ifdef USE_ZLIB extern long zlib_used_memory; diff --git a/src/compression.c b/src/compression.c index 3ce2a6005..7a8a21912 100644 --- a/src/compression.c +++ b/src/compression.c @@ -110,7 +110,7 @@ const struct comp_algo comp_algos[] = * Add a content-type in the configuration * Returns 0 in case of success, 1 in case of allocation failure. */ -int comp_append_type(struct comp *comp, const char *type) +int comp_append_type(struct comp_type **types, const char *type) { struct comp_type *comp_type; @@ -119,8 +119,8 @@ int comp_append_type(struct comp *comp, const char *type) return 1; comp_type->name_len = strlen(type); comp_type->name = strdup(type); - comp_type->next = comp->types; - comp->types = comp_type; + comp_type->next = *types; + *types = comp_type; return 0; } @@ -129,7 +129,7 @@ int comp_append_type(struct comp *comp, const char *type) * Returns 0 in case of success, -1 if the is unmanaged, 1 in case of * allocation failure. */ -int comp_append_algo(struct comp *comp, const char *algo) +int comp_append_algo(struct comp_algo **algos, const char *algo) { struct comp_algo *comp_algo; int i; @@ -140,8 +140,8 @@ int comp_append_algo(struct comp *comp, const char *algo) if (!comp_algo) return 1; memmove(comp_algo, &comp_algos[i], sizeof(struct comp_algo)); - comp_algo->next = comp->algos; - comp->algos = comp_algo; + comp_algo->next = *algos; + *algos = comp_algo; return 0; } } diff --git a/src/flt_http_comp.c b/src/flt_http_comp.c index ad2b77c0b..8c56d0a46 100644 --- a/src/flt_http_comp.c +++ b/src/flt_http_comp.c @@ -415,8 +415,8 @@ select_compression_request_header(struct comp_state *st, struct stream *s, struc } /* search for the algo in the backend in priority or the frontend */ - if ((s->be->comp && (comp_algo_back = s->be->comp->algos)) || - (strm_fe(s)->comp && (comp_algo_back = strm_fe(s)->comp->algos))) { + if ((s->be->comp && (comp_algo_back = s->be->comp->algos_res)) || + (strm_fe(s)->comp && (comp_algo_back = strm_fe(s)->comp->algos_res))) { int best_q = 0; ctx.blk = NULL; @@ -485,8 +485,8 @@ select_compression_request_header(struct comp_state *st, struct stream *s, struc } /* identity is implicit does not require headers */ - if ((s->be->comp && (comp_algo_back = s->be->comp->algos)) || - (strm_fe(s)->comp && (comp_algo_back = strm_fe(s)->comp->algos))) { + if ((s->be->comp && (comp_algo_back = s->be->comp->algos_res)) || + (strm_fe(s)->comp && (comp_algo_back = strm_fe(s)->comp->algos_res))) { for (comp_algo = comp_algo_back; comp_algo; comp_algo = comp_algo->next) { if (comp_algo->cfg_name_len == 8 && memcmp(comp_algo->cfg_name, "identity", 8) == 0) { st->comp_algo[COMP_DIR_RES] = comp_algo; @@ -571,8 +571,8 @@ select_compression_response_header(struct comp_state *st, struct stream *s, stru if (ctx.value.len >= 9 && strncasecmp("multipart", ctx.value.ptr, 9) == 0) goto fail; - if ((s->be->comp && (comp_type = s->be->comp->types)) || - (strm_fe(s)->comp && (comp_type = strm_fe(s)->comp->types))) { + if ((s->be->comp && (comp_type = s->be->comp->types_res)) || + (strm_fe(s)->comp && (comp_type = strm_fe(s)->comp->types_res))) { for (; comp_type; comp_type = comp_type->next) { if (ctx.value.len >= comp_type->name_len && strncasecmp(ctx.value.ptr, comp_type->name, comp_type->name_len) == 0) @@ -585,8 +585,8 @@ select_compression_response_header(struct comp_state *st, struct stream *s, stru } } else { /* no content-type header */ - if ((s->be->comp && s->be->comp->types) || - (strm_fe(s)->comp && strm_fe(s)->comp->types)) + if ((s->be->comp && s->be->comp->types_res) || + (strm_fe(s)->comp && strm_fe(s)->comp->types_res)) goto fail; /* a content-type was required */ } @@ -674,7 +674,7 @@ parse_compression_options(char **args, int section, struct proxy *proxy, else comp = proxy->comp; - if (strcmp(args[1], "algo") == 0) { + if (strcmp(args[1], "algo") == 0 || strcmp(args[1], "algo-res") == 0) { struct comp_ctx *ctx; int cur_arg = 2; @@ -685,7 +685,7 @@ parse_compression_options(char **args, int section, struct proxy *proxy, goto end; } while (*(args[cur_arg])) { - int retval = comp_append_algo(comp, args[cur_arg]); + int retval = comp_append_algo(&comp->algos_res, args[cur_arg]); if (retval) { if (retval < 0) memprintf(err, "'%s' : '%s' is not a supported algorithm.", @@ -697,8 +697,8 @@ parse_compression_options(char **args, int section, struct proxy *proxy, goto end; } - if (proxy->comp->algos->init(&ctx, 9) == 0) - proxy->comp->algos->end(&ctx); + if (proxy->comp->algos_res->init(&ctx, 9) == 0) + proxy->comp->algos_res->end(&ctx); else { memprintf(err, "'%s' : Can't init '%s' algorithm.", args[0], args[cur_arg]); @@ -717,7 +717,7 @@ parse_compression_options(char **args, int section, struct proxy *proxy, } comp->flags |= COMP_FL_OFFLOAD; } - else if (strcmp(args[1], "type") == 0) { + else if (strcmp(args[1], "type") == 0 || strcmp(args[1], "type-res") == 0) { int cur_arg = 2; if (!*args[cur_arg]) { @@ -726,7 +726,7 @@ parse_compression_options(char **args, int section, struct proxy *proxy, goto end; } while (*(args[cur_arg])) { - if (comp_append_type(comp, args[cur_arg])) { + if (comp_append_type(&comp->types_res, args[cur_arg])) { memprintf(err, "'%s': out of memory.", args[0]); ret = -1; goto end; diff --git a/src/proxy.c b/src/proxy.c index 8d4de56e3..a025e18e9 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -1901,8 +1901,10 @@ static int proxy_defproxy_cpy(struct proxy *curproxy, const struct proxy *defpro memprintf(errmsg, "proxy '%s': out of memory for default compression options", curproxy->id); return 1; } - curproxy->comp->algos = defproxy->comp->algos; - curproxy->comp->types = defproxy->comp->types; + curproxy->comp->algos_res = defproxy->comp->algos_res; + curproxy->comp->algo_req = defproxy->comp->algo_req; + curproxy->comp->types_res = defproxy->comp->types_res; + curproxy->comp->types_req = defproxy->comp->types_req; } if (defproxy->check_path)