]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: http-fetch: Use integer value when possible in "method" sample fetch
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 22 Jun 2022 15:16:41 +0000 (17:16 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 22 Jun 2022 15:50:54 +0000 (17:50 +0200)
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

index c3e8599cf0122b1be2463935a4197db23ee8c643..1c331e0aede2c911f3cd9b19f278ffe6b4bcd78c 100644 (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);