MINOR: http-fetch: Add a sample to get the transaction status code
It was possible get the status code in the HTTP response and the one received from the server. Thanks to 'txn.status', it is now possible to get the transaction status code. It is equivalent to '%ST' in log-format. Most of time, it is the same than 'status', except if the status code of the HTTP reply does not match the one used to interrupt the transaction. For instance, an error file use mapped on 400 containing a 404.
This commit is contained in:
parent
5d9c25bbea
commit
2de9e3ae24
|
@ -22844,6 +22844,10 @@ status : integer
|
|||
|
||||
It may be used in tcp-check based expect rules.
|
||||
|
||||
txn.status : integer
|
||||
Return an integer containing the HTTP status code of the transaction, as
|
||||
reported in the log.
|
||||
|
||||
txn.timer.total : integer
|
||||
Total active time for the HTTP request, between the moment the proxy received
|
||||
the first byte of the request header and the emission of the last byte of the
|
||||
|
@ -23967,6 +23971,7 @@ Please refer to the table below for currently defined variables :
|
|||
| | %ID | unique-id | string |
|
||||
+---+------+------------------------------------------------------+---------+
|
||||
| | %ST | status_code | numeric |
|
||||
| | | %[txn.status] | |
|
||||
+---+------+------------------------------------------------------+---------+
|
||||
| | %U | bytes_uploaded (from client to server) | numeric |
|
||||
| | | %[bytes_in] | |
|
||||
|
|
|
@ -445,25 +445,31 @@ static int smp_fetch_stcode(const struct arg *args, struct sample *smp, const ch
|
|||
return 1;
|
||||
}
|
||||
|
||||
/* It returns the server status code */
|
||||
/* It returns the server or the txn status code, depending on the keyword */
|
||||
static int smp_fetch_srv_status(const struct arg *args, struct sample *smp, const char *kw, void *private)
|
||||
{
|
||||
struct http_txn *txn;
|
||||
short status;
|
||||
|
||||
txn = (smp->strm ? smp->strm->txn : NULL);
|
||||
if (!txn)
|
||||
return 0;
|
||||
|
||||
if (txn->server_status == -1) {
|
||||
status = (kw[0] == 't' ? txn->status : txn->server_status);
|
||||
if (status == -1) {
|
||||
struct channel *chn = SMP_RES_CHN(smp);
|
||||
struct htx *htx = smp_prefetch_htx(smp, chn, NULL, 1);
|
||||
|
||||
if (!htx)
|
||||
return 0;
|
||||
|
||||
status = (kw[0] == 't' ? txn->status : txn->server_status);
|
||||
}
|
||||
|
||||
if (kw[0] != 't')
|
||||
smp->flags = SMP_F_VOL_1ST;
|
||||
smp->data.type = SMP_T_SINT;
|
||||
smp->data.u.sint = txn->server_status;
|
||||
smp->data.u.sint = status;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -2338,6 +2344,7 @@ static struct sample_fetch_kw_list sample_fetch_keywords = {ILH, {
|
|||
{ "shdr_val", smp_fetch_hdr_val, ARG2(0,STR,SINT), val_hdr, SMP_T_SINT, SMP_USE_HRSHV },
|
||||
|
||||
{ "status", smp_fetch_stcode, 0, NULL, SMP_T_SINT, SMP_USE_HRSHP },
|
||||
{ "txn.status", smp_fetch_srv_status, 0, NULL, SMP_T_SINT, SMP_USE_HRSHP },
|
||||
{ "unique-id", smp_fetch_uniqueid, 0, NULL, SMP_T_STR, SMP_SRC_L4SRV },
|
||||
{ "url", smp_fetch_url, 0, NULL, SMP_T_STR, SMP_USE_HRQHV },
|
||||
{ "url32", smp_fetch_url32, 0, NULL, SMP_T_SINT, SMP_USE_HRQHV },
|
||||
|
|
Loading…
Reference in New Issue