]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: http-fetch: Add pathq sample fetch
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 2 Sep 2020 15:25:18 +0000 (17:25 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 4 Sep 2020 09:41:47 +0000 (11:41 +0200)
The pathq sample fetch extract the relative URI of a request, i.e the path with
the query-string, excluding the scheme and the authority, if any. It is pretty
handy to always get a relative URI independently on the HTTP version. Indeed,
while relative URIs are common in HTTP/1.1, in HTTP/2, most of time clients use
absolute URIs.

This patch may be backported to 2.2.

doc/configuration.txt
src/http_fetch.c

index 5993536e5b5b375aac6d09467de8469f7297e609..a8242793a636a9da46da0075637c6219edd0a1b5 100644 (file)
@@ -18116,6 +18116,14 @@ path : string
     path_reg : regex match
     path_sub : substring match
 
+pathq : string
+  This extracts the request's URL path with the query-string, which starts at
+  the first slash. This sample fetch is pretty handy to always retrieve a
+  relative URI, excluding the scheme and the authority part, if any. Indeed,
+  while it is the common representation for an HTTP/1.1 request target, in
+  HTTP/2, an absolute URI is often used. This sample fetch will return the same
+  result in both cases.
+
 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
index 2149b7fa2f81f16b363ab624e2c9dd32ed77eb73..0a29c810aed2812dfbe6ff7fdc02b410f9b875df 100644 (file)
@@ -1025,8 +1025,9 @@ static int smp_fetch_hdr_ip(const struct arg *args, struct sample *smp, const ch
        return ret;
 }
 
-/* 8. Check on URI PATH. A pointer to the PATH is stored. The path starts at
- * the first '/' after the possible hostname, and ends before the possible '?'.
+/* 8. Check on URI PATH. A pointer to the PATH is stored. The path starts at the
+ * first '/' after the possible hostname. It ends before the possible '?' except
+ * for 'pathq' keyword.
  */
 static int smp_fetch_path(const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
@@ -1039,7 +1040,13 @@ static int smp_fetch_path(const struct arg *args, struct sample *smp, const char
                return 0;
 
        sl = http_get_stline(htx);
-       path = iststop(http_get_path(htx_sl_req_uri(sl)), '?');
+       path = http_get_path(htx_sl_req_uri(sl));
+
+       if (kw[0] == 'p' && kw[4] == 'q') // pathq
+               path = http_get_path(htx_sl_req_uri(sl));
+       else
+               path = iststop(http_get_path(htx_sl_req_uri(sl)), '?');
+
        if (!isttest(path))
                return 0;
 
@@ -2071,6 +2078,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 },
+       { "pathq",              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 */