MINOR: http: add baseq sample fetch

Symetrical to path/pathq, baseq returns the concatenation of
the Host header and the path including the query string.
This commit is contained in:
Yves Lafon 2021-02-11 11:01:28 +01:00 committed by Willy Tarreau
parent 7c0b4d861e
commit b4d3708cb7
2 changed files with 14 additions and 3 deletions

View 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.

View 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 },