diff --git a/doc/configuration.txt b/doc/configuration.txt index b4827e00f..10ccf2f3a 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -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] | | diff --git a/src/http_fetch.c b/src/http_fetch.c index 38b1e0b08..1f3e4a05d 100644 --- a/src/http_fetch.c +++ b/src/http_fetch.c @@ -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 },