mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-11-28 14:21:00 +01:00
MINOR: http: add capture.req.ver and capture.res.ver
These ones report a string as "HTTP/1.0" or "HTTP/1.1" depending on the version of the request message or the response message, respectively. The purpose is to be able to emit custom log lines reporting this version in a persistent way.
This commit is contained in:
parent
8b8995f0f4
commit
3c1b5ec29c
@ -10698,12 +10698,22 @@ capture.req.uri : string
|
||||
and "url", it can be used in both request and response because it's
|
||||
allocated.
|
||||
|
||||
capture.req.ver : string
|
||||
This extracts the request's HTTP version and returns either "HTTP/1.0" or
|
||||
"HTTP/1.1". Unlike "req.ver", it can be used in both request, response, and
|
||||
logs because it relies on a persistent flag.
|
||||
|
||||
capture.res.hdr(<idx>) : string
|
||||
This extracts the content of the header captured by the "capture response
|
||||
header", idx is the position of the capture keyword in the configuration.
|
||||
The first entry is an index of 0.
|
||||
See also: "capture response header"
|
||||
|
||||
capture.res.ver : string
|
||||
This extracts the response's HTTP version and returns either "HTTP/1.0" or
|
||||
"HTTP/1.1". Unlike "res.ver", it can be used in logs because it relies on a
|
||||
persistent flag.
|
||||
|
||||
req.cook([<name>]) : string
|
||||
cook([<name>]) : string (deprecated)
|
||||
This extracts the last occurrence of the cookie name <name> on a "Cookie"
|
||||
|
||||
@ -10033,6 +10033,54 @@ smp_fetch_capture_req_uri(struct proxy *px, struct session *l4, void *l7, unsign
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Retrieves the HTTP version from the request (either 1.0 or 1.1) and emits it
|
||||
* as a string (either "HTTP/1.0" or "HTTP/1.1").
|
||||
*/
|
||||
static int
|
||||
smp_fetch_capture_req_ver(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;
|
||||
|
||||
if (txn->req.msg_state < HTTP_MSG_HDR_FIRST)
|
||||
return 0;
|
||||
|
||||
if (txn->req.flags & HTTP_MSGF_VER_11)
|
||||
smp->data.str.str = "HTTP/1.1";
|
||||
else
|
||||
smp->data.str.str = "HTTP/1.0";
|
||||
|
||||
smp->data.str.len = 8;
|
||||
smp->type = SMP_T_STR;
|
||||
smp->flags = SMP_F_CONST;
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
/* Retrieves the HTTP version from the response (either 1.0 or 1.1) and emits it
|
||||
* as a string (either "HTTP/1.0" or "HTTP/1.1").
|
||||
*/
|
||||
static int
|
||||
smp_fetch_capture_res_ver(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;
|
||||
|
||||
if (txn->rsp.msg_state < HTTP_MSG_HDR_FIRST)
|
||||
return 0;
|
||||
|
||||
if (txn->rsp.flags & HTTP_MSGF_VER_11)
|
||||
smp->data.str.str = "HTTP/1.1";
|
||||
else
|
||||
smp->data.str.str = "HTTP/1.0";
|
||||
|
||||
smp->data.str.len = 8;
|
||||
smp->type = SMP_T_STR;
|
||||
smp->flags = SMP_F_CONST;
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* Iterate over all cookies present in a message. The context is stored in
|
||||
* smp->ctx.a[0] for the in-header position, smp->ctx.a[1] for the
|
||||
@ -10771,12 +10819,16 @@ static struct sample_fetch_kw_list sample_fetch_keywords = {ILH, {
|
||||
{ "base32", smp_fetch_base32, 0, NULL, SMP_T_UINT, SMP_USE_HRQHV },
|
||||
{ "base32+src", smp_fetch_base32_src, 0, NULL, SMP_T_BIN, SMP_USE_HRQHV },
|
||||
|
||||
{ "capture.req.uri", smp_fetch_capture_req_uri, 0, NULL, SMP_T_STR, SMP_USE_HRQHP },
|
||||
{ "capture.req.method", smp_fetch_capture_req_method, 0, NULL, SMP_T_STR, SMP_USE_HRQHP },
|
||||
|
||||
/* capture are allocated and are permanent in the session */
|
||||
{ "capture.req.hdr", smp_fetch_capture_header_req, ARG1(1, UINT), NULL, SMP_T_STR, SMP_USE_HRQHP },
|
||||
|
||||
/* retrieve these captures from the HTTP logs */
|
||||
{ "capture.req.method", smp_fetch_capture_req_method, 0, NULL, SMP_T_STR, SMP_USE_HRQHP },
|
||||
{ "capture.req.uri", smp_fetch_capture_req_uri, 0, NULL, SMP_T_STR, SMP_USE_HRQHP },
|
||||
{ "capture.req.ver", smp_fetch_capture_req_ver, 0, NULL, SMP_T_STR, SMP_USE_HRQHP },
|
||||
|
||||
{ "capture.res.hdr", smp_fetch_capture_header_res, ARG1(1, UINT), NULL, SMP_T_STR, SMP_USE_HRSHP },
|
||||
{ "capture.res.ver", smp_fetch_capture_res_ver, 0, NULL, SMP_T_STR, SMP_USE_HRQHP },
|
||||
|
||||
/* cookie is valid in both directions (eg: for "stick ...") but cook*
|
||||
* are only here to match the ACL's name, are request-only and are used
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user