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.
This commit is contained in:
William Lallemand 2013-04-20 17:33:20 +02:00 committed by Willy Tarreau
parent 913195715d
commit 727db8b4ea
2 changed files with 50 additions and 0 deletions

View File

@ -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([<name>])
This extracts the last occurrence of the cookie name <name> on a
"Set-Cookie" header line from the response, and returns its

View File

@ -30,6 +30,7 @@
#include <types/global.h>
#include <types/compression.h>
#include <proto/acl.h>
#include <proto/compression.h>
#include <proto/freq_ctr.h>
#include <proto/proto_http.h>
@ -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 <const> 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 <const> 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);
}