]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: compression: acl "res.comp" and fetch "res.comp_algo"
authorWilliam Lallemand <wlallemand@exceliance.fr>
Sat, 20 Apr 2013 15:33:20 +0000 (17:33 +0200)
committerWilly Tarreau <w@1wt.eu>
Sat, 20 Apr 2013 21:53:33 +0000 (23:53 +0200)
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
src/compression.c

index 36cf534a1e1408f304d3466466ac22fb52898ba8..67c18ecc57762141b7f9f559cce605111305dc21 100644 (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
index fd5f7901efc412928ad7cd0268e49b0411d342eb..e75f21e38ce7a320e30161a4279705d8f3e4844e 100644 (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);
+}