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.
diff --git a/doc/configuration.txt b/doc/configuration.txt
index 36cf534..67c18ec 100644
--- a/doc/configuration.txt
+++ b/doc/configuration.txt
@@ -9994,6 +9994,13 @@
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
diff --git a/src/compression.c b/src/compression.c
index fd5f790..e75f21e 100644
--- a/src/compression.c
+++ b/src/compression.c
@@ -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 @@
#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);
+}