From f1c659f3aebb397405851bfbb056249ea0a7676c Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Thu, 18 Sep 2025 09:00:42 +0200 Subject: [PATCH] MINOR: hlua/http-fetch: Use instead of HTX extra field to get body size The known input payload length now contains the information. There is no reason to still rely on the HTX extra field. --- src/hlua.c | 14 +------------- src/http_fetch.c | 21 ++++++--------------- 2 files changed, 7 insertions(+), 28 deletions(-) diff --git a/src/hlua.c b/src/hlua.c index e52f0a0c3..ec2a8ee7b 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -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); diff --git a/src/http_fetch.c b/src/http_fetch.c index ebba87519..b8b6f616c 100644 --- a/src/http_fetch.c +++ b/src/http_fetch.c @@ -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;