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.
This commit is contained in:
Christopher Faulet 2022-06-22 17:16:41 +02:00
parent 5eb67f5d74
commit dbbdb25f1c
1 changed files with 7 additions and 10 deletions

View File

@ -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);