]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: hlua/http-fetch: Use <kip> instead of HTX extra field to get body size
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 18 Sep 2025 07:00:42 +0000 (09:00 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 8 Oct 2025 09:10:25 +0000 (11:10 +0200)
The known input payload length now contains the information. There is no
reason to still rely on the HTX extra field.

src/hlua.c
src/http_fetch.c

index e52f0a0c3f9cdce7c62328b2c49bcdb1a3643b09..ec2a8ee7bb9608a2a6ea8d98ab626c80cb574a86 100644 (file)
@@ -11293,7 +11293,6 @@ void hlua_applet_http_fct(struct appctx *ctx)
                struct htx_sl *sl;
                struct ist path;
                unsigned long long len = 0;
-               int32_t pos;
                struct http_uri_parser parser;
                int app_idx = 1 - hlua->nargs; /* index of the HTTP applet object in the lua stask */
 
@@ -11363,19 +11362,8 @@ void hlua_applet_http_fct(struct appctx *ctx)
                        lua_settable(hlua->T, app_idx - 3);
                }
 
-               for (pos = htx_get_first(req_htx); pos != -1; pos = htx_get_next(req_htx, pos)) {
-                       struct htx_blk *blk = htx_get_blk(req_htx, pos);
-                       enum htx_blk_type type = htx_get_blk_type(blk);
-
-                       if (type == HTX_BLK_TLR || type == HTX_BLK_EOT)
-                               break;
-                       if (type == HTX_BLK_DATA)
-                               len += htx_get_blksz(blk);
-               }
-               if (req_htx->extra != HTX_UNKOWN_PAYLOAD_LENGTH)
-                       len += req_htx->extra;
-
                /* Stores the request path. */
+               len = ctx->sedesc->kip;
                lua_pushstring(hlua->T, "length");
                lua_pushinteger(hlua->T, len);
                lua_settable(hlua->T, app_idx - 3);
index ebba87519b86462d45eebac69983862666a21e13..b8b6f616c051b4868b33bb578fe217df1853cd54 100644 (file)
@@ -50,6 +50,9 @@ static THREAD_LOCAL char *static_raw_htx_buf;
 #define SMP_REQ_CHN(smp) (smp->strm ? &smp->strm->req : NULL)
 #define SMP_RES_CHN(smp) (smp->strm ? &smp->strm->res : NULL)
 
+#define SMP_REQ_SC(smp) (smp->strm ? smp->strm->scf : NULL)
+#define SMP_RES_SC(smp) (smp->strm ? smp->strm->scb : NULL)
+
 /* This function returns the static htx chunk, where raw connections get
  * converted to HTX as needed for samplxsing.
  */
@@ -694,26 +697,14 @@ static int smp_fetch_body_len(const struct arg *args, struct sample *smp, const
 static int smp_fetch_body_size(const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
        /* possible keywords: req.body_size, res.body_size */
-       struct channel *chn = ((kw[2] == 'q') ? SMP_REQ_CHN(smp) : SMP_RES_CHN(smp));
+       struct stconn *sc = ((kw[2] == 'q') ? SMP_REQ_SC(smp) : SMP_RES_SC(smp));
        struct check *check = ((kw[2] == 's') ? objt_check(smp->sess->origin) : NULL);
-       struct htx *htx = smp_prefetch_htx(smp, chn, check, 1);
-       int32_t pos;
+       struct htx *htx = smp_prefetch_htx(smp, (sc ? sc_ic(sc) : NULL), check, 1);
        unsigned long long len = 0;
 
        if (!htx)
                return 0;
-
-       for (pos = htx_get_first(htx); pos != -1; pos = htx_get_next(htx, pos)) {
-               struct htx_blk *blk = htx_get_blk(htx, pos);
-               enum htx_blk_type type = htx_get_blk_type(blk);
-
-               if (type == HTX_BLK_TLR || type == HTX_BLK_EOT)
-                       break;
-               if (type == HTX_BLK_DATA)
-                       len += htx_get_blksz(blk);
-       }
-       if (htx->extra != HTX_UNKOWN_PAYLOAD_LENGTH)
-               len += htx->extra;
+       len = (sc ? sc->sedesc->kip : check->sc->sedesc->kip);
 
        smp->data.type = SMP_T_SINT;
        smp->data.u.sint = len;