From dbbdb25f1c0a96094c4e357105264053644d9255 Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Wed, 22 Jun 2022 17:16:41 +0200 Subject: [PATCH] BUG/MINOR: http-fetch: Use integer value when possible in "method" sample fetch Because of the previous fix, if the HTTP parsing is performed when the "method" sample fetch is called, we always rely on the string representation of the request method. Indeed, if no parsing was performed when the "method" sample fetch is called, the transaction method is HTTP_METH_OTHER because it was just initialized. However, without this patch, in this case, we always retrieve the method by reading the request start-line. Now, when the method is HTTP_METH_OTHER, we systematically try to parse the request but the method is tested once again after the parsing to be able to use the integer representation when possible. This patch must be backported as far as 2.0. --- src/http_fetch.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/http_fetch.c b/src/http_fetch.c index c3e8599cf0..1c331e0aed 100644 --- a/src/http_fetch.c +++ b/src/http_fetch.c @@ -334,28 +334,25 @@ static int smp_fetch_meth(const struct arg *args, struct sample *smp, const char { struct channel *chn = SMP_REQ_CHN(smp); struct http_txn *txn; + struct htx *htx; int meth; txn = smp->strm->txn; if (!txn) return 0; + if (txn->meth == HTTP_METH_OTHER) { + htx = smp_prefetch_htx(smp, chn, NULL, 1); + if (!htx) + return 0; + } + meth = txn->meth; smp->data.type = SMP_T_METH; smp->data.u.meth.meth = meth; if (meth == HTTP_METH_OTHER) { - struct htx *htx; struct htx_sl *sl; - if ((smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_RES) { - /* ensure the indexes are not affected */ - return 0; - } - - htx = smp_prefetch_htx(smp, chn, NULL, 1); - if (!htx) - return 0; - sl = http_get_stline(htx); smp->flags |= SMP_F_CONST; smp->data.u.meth.str.area = HTX_SL_REQ_MPTR(sl);