From 727db8b4ea196c5d494149102c4ec65e3aadf7cd Mon Sep 17 00:00:00 2001 From: William Lallemand Date: Sat, 20 Apr 2013 17:33:20 +0200 Subject: [PATCH] MINOR: compression: acl "res.comp" and fetch "res.comp_algo" Implements the "res.comp" ACL which is a boolean returning 1 when a response has been compressed by HAProxy or 0 otherwise. Implements the "res.comp_algo" fetch which contains the name of the algorithm HAProxy used to compress the response. --- doc/configuration.txt | 7 +++++++ src/compression.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/doc/configuration.txt b/doc/configuration.txt index 36cf534a1..67c18ecc5 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -9994,6 +9994,13 @@ The list of currently supported pattern fetch functions is the following : req_ver This is an alias for "req.ver". + res.comp Returns the boolean "true" value if the response has been + compressed by HAProxy, otherwise returns boolean "false". + + res.comp_algo + Returns a string containing the name of the algorithm used if + the response was compressed by HAProxy. + res.cook([]) This extracts the last occurrence of the cookie name on a "Set-Cookie" header line from the response, and returns its diff --git a/src/compression.c b/src/compression.c index fd5f7901e..e75f21e38 100644 --- a/src/compression.c +++ b/src/compression.c @@ -30,6 +30,7 @@ #include #include +#include #include #include #include @@ -609,3 +610,45 @@ int deflate_end(struct comp_ctx **comp_ctx) #endif /* USE_ZLIB */ +/* boolean, returns true if compression is used (either gzip or deflate) in the response */ +static int +smp_fetch_res_comp(struct proxy *px, struct session *l4, void *l7, unsigned int opt, + const struct arg *args, struct sample *smp) +{ + smp->type = SMP_T_BOOL; + smp->data.uint = (l4->comp_algo != NULL); + return 1; +} + +/* string, returns algo */ +static int +smp_fetch_res_comp_algo(struct proxy *px, struct session *l4, void *l7, unsigned int opt, + const struct arg *args, struct sample *smp) +{ + if (!l4->comp_algo) + return 0; + + smp->type = SMP_T_STR; + smp->data.str.str = l4->comp_algo->name; + smp->data.str.len = l4->comp_algo->name_len; + return 1; +} + +/* Note: must not be declared as its list will be overwritten */ +static struct acl_kw_list acl_kws = {{ },{ + { "res.comp", NULL, acl_parse_nothing, acl_match_nothing }, +}}; + +/* Note: must not be declared as its list will be overwritten */ +static struct sample_fetch_kw_list sample_fetch_keywords = {{ },{ + { "res.comp", smp_fetch_res_comp, 0, NULL, SMP_T_BOOL, SMP_USE_HRSHP }, + { "res.comp_algo", smp_fetch_res_comp_algo, 0, NULL, SMP_T_STR, SMP_USE_HRSHP }, + { /* END */ }, +}}; + +__attribute__((constructor)) +static void __comp_fetch_init(void) +{ + acl_register_keywords(&acl_kws); + sample_register_fetches(&sample_fetch_keywords); +}