]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: hlua: Don't consume headers when starting an HTTP lua service
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 28 Apr 2021 08:50:21 +0000 (10:50 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 28 Apr 2021 09:05:05 +0000 (11:05 +0200)
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

index f2276097f7fbf22526defdc0689bc34ae721184a..426c917de2eab1b218d74cc39201651535f6028f 100644 (file)
@@ -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. */