]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: patterns: the hdr() pattern is now of type string
authorWilly Tarreau <w@1wt.eu>
Fri, 16 Dec 2011 20:50:30 +0000 (21:50 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 30 Dec 2011 16:33:27 +0000 (17:33 +0100)
This pattern previously was limited to type IP. With the new header
extraction function, it becomes possible to extract strings, so that
the header can be returned as a string. This will not change anything
to existing configs, as string will automatically be converted to IP
when needed. However, new configs will be able to use IPv6 addresses
from headers in stick-tables, as well as stick on any non-IP header
(eg: host, user-agent, ...).

doc/configuration.txt
src/proto_http.c

index 0066ee9f831bda8e5d015a8d0c5e2e2c41009558..066f935683f25f3a2555268070a4331c9cd2358e 100644 (file)
@@ -8050,10 +8050,9 @@ The list of currently supported pattern fetch functions is the following :
                ports to some clients for a whole application session. It is of
                type integer and only works with such tables.
 
-  hdr(<name>)    This extracts the last occurrence of header <name> in an HTTP
-               request and converts it to an IP address. This IP address is
-               then used to match the table. A typical use is with the
-               x-forwarded-for header.
+  hdr(<name>)  This extracts the last occurrence of header <name> in an HTTP
+               request. A typical use is with the X-Forwarded-For header once
+               converted to IP, associated with an IP stick-table.
 
   payload(<offset>,<length>)
                This extracts a binary block of <length> bytes, and starting
index da785bb4838a2199f8c2039f4f61da072dbe72b6..1906916b309b540de1a7f8b1419f49d7d269a127 100644 (file)
@@ -8489,24 +8489,15 @@ static struct acl_kw_list acl_kws = {{ },{
 /*     The code below is dedicated to pattern fetching and matching     */
 /************************************************************************/
 
-/* extract the IP address from the last occurrence of specified header. Note
- * that we should normally first extract the string then convert it to IP,
- * but right now we have all the functions to do this seemlessly, and we will
- * be able to change that later without touching the configuration.
- */
+/* Returns the last occurrence of specified header. */
 static int
-pattern_fetch_hdr_ip(struct proxy *px, struct session *l4, void *l7, int dir,
-                     const struct pattern_arg *arg_p, int arg_i, union pattern_data *data)
+pattern_fetch_hdr(struct proxy *px, struct session *l4, void *l7, int dir,
+                 const struct pattern_arg *arg_p, int arg_i, union pattern_data *data)
 {
        struct http_txn *txn = l7;
-       const char *vptr;
-       int vlen;
-
-       if (!http_get_hdr(&txn->req, arg_p->data.str.str, arg_p->data.str.len, &txn->hdr_idx, -1, NULL, &vptr, &vlen))
-               return 0;
 
-       data->ip.s_addr = htonl(inetaddr_host_lim(vptr, vptr + vlen));
-       return data->ip.s_addr != 0;
+       return http_get_hdr(&txn->req, arg_p->data.str.str, arg_p->data.str.len, &txn->hdr_idx,
+                           -1, NULL, &data->str.str, &data->str.len);
 }
 
 /*
@@ -8798,7 +8789,7 @@ pattern_fetch_set_cookie(struct proxy *px, struct session *l4, void *l7, int dir
 /************************************************************************/
 /* Note: must not be declared <const> as its list will be overwritten */
 static struct pattern_fetch_kw_list pattern_fetch_keywords = {{ },{
-       { "hdr", pattern_fetch_hdr_ip, pattern_arg_str, PATTERN_TYPE_IP, PATTERN_FETCH_REQ },
+       { "hdr", pattern_fetch_hdr, pattern_arg_str, PATTERN_TYPE_STRING, PATTERN_FETCH_REQ },
        { "url_param", pattern_fetch_url_param, pattern_arg_str, PATTERN_TYPE_STRING, PATTERN_FETCH_REQ },
        { "cookie", pattern_fetch_cookie, pattern_arg_str, PATTERN_TYPE_STRING, PATTERN_FETCH_REQ },
        { "set-cookie", pattern_fetch_set_cookie, pattern_arg_str, PATTERN_TYPE_STRING, PATTERN_FETCH_RTR },