]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: http: add a new fetch "query" to extract the request's query string
authorWilly Tarreau <w@1wt.eu>
Mon, 19 Jan 2015 14:06:26 +0000 (15:06 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 20 Jan 2015 18:47:47 +0000 (19:47 +0100)
This fetch extracts the request's query string, which starts after the first
question mark. If no question mark is present, this fetch returns nothing. If
a question mark is present but nothing follows, it returns an empty string.
This means it's possible to easily know whether a query string is present
using the "found" matching method. This fetch is the completemnt of "path"
which stops before the question mark.

doc/configuration.txt
src/proto_http.c

index 17f88604063cd62d804ccbc7dfe5f01b8a05f4cf..48ed813c9ba4fca09760c0b2661918e35f0894d3 100644 (file)
@@ -11907,6 +11907,14 @@ path : string
     path_reg : regex match
     path_sub : substring match
 
+query : string
+  This extracts the request's query string, which starts after the first
+  question mark. If no question mark is present, this fetch returns nothing. If
+  a question mark is present but nothing follows, it returns an empty string.
+  This means it's possible to easily know whether a query string is present
+  using the "found" matching method. This fetch is the completemnt of "path"
+  which stops before the question mark.
+
 req.ver : string
 req_ver : string (deprecated)
   Returns the version string from the HTTP request, for example "1.1". This can
index 6d94b69befc90814b838d54423dae82969037ec4..93259e33eb484ac8c0276b7796e223417234d6ef 100644 (file)
@@ -10457,6 +10457,35 @@ smp_fetch_base32_src(struct proxy *px, struct session *l4, void *l7, unsigned in
        return 1;
 }
 
+/* Extracts the query string, which comes after the question mark '?'. If no
+ * question mark is found, nothing is returned. Otherwise it returns a sample
+ * of type string carrying the whole query string.
+ */
+static int
+smp_fetch_query(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
+               const struct arg *args, struct sample *smp, const char *kw)
+{
+       struct http_txn *txn = l7;
+       char *ptr, *end;
+
+       CHECK_HTTP_MESSAGE_FIRST();
+
+       ptr = txn->req.chn->buf->p + txn->req.sl.rq.u;
+       end = ptr + txn->req.sl.rq.u_l;
+
+       /* look up the '?' */
+       do {
+               if (ptr == end)
+                       return 0;
+       } while (*ptr++ != '?');
+
+       smp->type = SMP_T_STR;
+       smp->data.str.str = ptr;
+       smp->data.str.len = end - ptr;
+       smp->flags = SMP_F_VOL_1ST | SMP_F_CONST;
+       return 1;
+}
+
 static int
 smp_fetch_proto_http(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
                      const struct arg *args, struct sample *smp, const char *kw)
@@ -11608,6 +11637,7 @@ static struct sample_fetch_kw_list sample_fetch_keywords = {ILH, {
        { "http_first_req",  smp_fetch_http_first_req, 0,                NULL,    SMP_T_BOOL, SMP_USE_HRQHP },
        { "method",          smp_fetch_meth,           0,                NULL,    SMP_T_METH, SMP_USE_HRQHP },
        { "path",            smp_fetch_path,           0,                NULL,    SMP_T_STR,  SMP_USE_HRQHV },
+       { "query",           smp_fetch_query,          0,                NULL,    SMP_T_STR,  SMP_USE_HRQHV },
 
        /* HTTP protocol on the request path */
        { "req.proto_http",  smp_fetch_proto_http,     0,                NULL,    SMP_T_BOOL, SMP_USE_HRQHP },