From bd878d2c73b99797a4780777513fdf9eb3d1d43d Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Wed, 28 Apr 2021 10:50:21 +0200 Subject: [PATCH] BUG/MINOR: hlua: Don't consume headers when starting an HTTP lua service When an HTTP lua service is started, headers are consumed before calling the script. When it was initialized, the headers were stored in a lua array, thus they can be removed from the HTX message because the lua service will no longer access them. But it is a problem with bodyless messages because the EOM flag is lost. Indeed, once the headers are consumed, the message is empty and the buffer is reset, included the flags. Now, the headers are not immediately consumed. We will skip them if applet:receive() or applet:getline(). This way, the EOM flag is preserved. At the end, when the script is finished, all output data are consumed, thus this remains safe. It is a 2.4-specific bug. No backport is needed. --- src/hlua.c | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/src/hlua.c b/src/hlua.c index f2276097f..426c917de 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -7419,37 +7419,10 @@ void hlua_applet_http_fct(struct appctx *ctx) /* Set the currently running flag. */ if (!HLUA_IS_RUNNING(hlua) && !(ctx->ctx.hlua_apphttp.flags & APPLET_DONE)) { - struct htx_blk *blk; - size_t count = co_data(req); - - if (!count) { + if (!co_data(req)) { si_cant_get(si); goto out; } - - /* We need to flush the request header. This left the body for - * the Lua. - */ - req_htx = htx_from_buf(&req->buf); - blk = htx_get_first_blk(req_htx); - while (count && blk) { - enum htx_blk_type type = htx_get_blk_type(blk); - uint32_t sz = htx_get_blksz(blk); - - if (sz > count) { - si_cant_get(si); - htx_to_buf(req_htx, &req->buf); - goto out; - } - - count -= sz; - co_set_data(req, co_data(req) - sz); - blk = htx_remove_blk(req_htx, blk); - - if (type == HTX_BLK_EOH) - break; - } - htx_to_buf(req_htx, &req->buf); } /* Executes The applet if it is not done. */