mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-04-27 05:18:00 +00:00
MINOR: compression: Store algo and type for both request and response
Make provision for being able to store both compression algorithms and content-types to compress for both requests and responses. For now only the responses one are used.
This commit is contained in:
parent
dfc11da561
commit
db573e9c58
@ -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;
|
||||
};
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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 <algo> 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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user