MINOR: hlua/http-fetch: Use <kip> 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.
This commit is contained in:
Christopher Faulet 2025-09-18 09:00:42 +02:00
parent be1ce400c4
commit f1c659f3ae
2 changed files with 7 additions and 28 deletions

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

View 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;