]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: http: add baseq sample fetch
authorYves Lafon <ylafon@w3.org>
Thu, 11 Feb 2021 10:01:28 +0000 (11:01 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 12 Feb 2021 15:38:50 +0000 (16:38 +0100)
Symetrical to path/pathq, baseq returns the concatenation of
the Host header and the path including the query string.

doc/configuration.txt
src/http_fetch.c

index 00981cc5e35e2633cc741ed25181065b88d298fd..a5ab65940194e3e2c33c239c728c88cd3df3a846 100644 (file)
@@ -18476,6 +18476,12 @@ base32+src : binary
   depending on the source address family. This can be used to track per-IP,
   per-URL counters.
 
+baseq : string
+  This returns the concatenation of the first Host header and the path part of
+  the request with the query-string, which starts at the first slash. Using this
+  instead of "base" allows one to properly identify the target resource, for
+  statistics or caching use cases. See also "path", "pathq" and "base".
+
 capture.req.hdr(<idx>) : string
   This extracts the content of the header captured by the "capture request
   header", idx is the position of the capture keyword in the configuration.
index 6913d0620c8dc0eda6d6819c056aaadc01b4131b..8e74765f86e2988ce902cb5a6d433347b463baab 100644 (file)
@@ -1040,7 +1040,7 @@ static int smp_fetch_path(const struct arg *args, struct sample *smp, const char
        sl = http_get_stline(htx);
        path = http_get_path(htx_sl_req_uri(sl));
 
-       if (kw[0] == 'p' && kw[4] == 'q') // pathq
+       if (kw[4] == 'q' && (kw[0] == 'p' || kw[0] == 'b')) // pathq or baseq
                path = http_get_path(htx_sl_req_uri(sl));
        else
                path = iststop(http_get_path(htx_sl_req_uri(sl)), '?');
@@ -1089,8 +1089,12 @@ static int smp_fetch_base(const struct arg *args, struct sample *smp, const char
        if (isttest(path)) {
                size_t len;
 
-               for (len = 0; len < path.len && *(path.ptr + len) != '?'; len++)
-                       ;
+               if (kw[4] == 'q' && kw[0] == 'b') { // baseq
+                       len = path.len;
+               } else {
+                       for (len = 0; len < path.len && *(path.ptr + len) != '?'; len++)
+                               ;
+               }
 
                if (len && *(path.ptr) == '/')
                        chunk_memcat(temp, path.ptr, len);
@@ -2044,6 +2048,7 @@ static struct sample_fetch_kw_list sample_fetch_keywords = {ILH, {
        { "base",               smp_fetch_base,               0,                NULL,   SMP_T_STR,  SMP_USE_HRQHV },
        { "base32",             smp_fetch_base32,             0,                NULL,   SMP_T_SINT, SMP_USE_HRQHV },
        { "base32+src",         smp_fetch_base32_src,         0,                NULL,   SMP_T_BIN,  SMP_USE_HRQHV },
+       { "baseq",              smp_fetch_base,               0,                NULL,   SMP_T_STR,  SMP_USE_HRQHV },
 
        /* capture are allocated and are permanent in the stream */
        { "capture.req.hdr",    smp_fetch_capture_req_hdr,    ARG1(1,SINT),     NULL,   SMP_T_STR,  SMP_USE_HRQHP },