MINOR: http-fetch: Add pathq sample fetch
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.
diff --git a/doc/configuration.txt b/doc/configuration.txt
index 5993536..a824279 100644
--- a/doc/configuration.txt
+++ b/doc/configuration.txt
@@ -18116,6 +18116,14 @@
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
diff --git a/src/http_fetch.c b/src/http_fetch.c
index 2149b7f..0a29c81 100644
--- a/src/http_fetch.c
+++ b/src/http_fetch.c
@@ -1025,8 +1025,9 @@
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 @@
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 @@
{ "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 */