From a40022de1ef09495d010facfc4ab7fc4774e0978 Mon Sep 17 00:00:00 2001 From: Olivier Houchard Date: Thu, 19 Nov 2026 16:44:09 +0100 Subject: [PATCH] BUG/MINOR: hlua: reject interim responses in HTTP applets A Lua HTTP service may set a 1xx status. But it can only send one response, so once the service returns, the interim response is ended with the EOM flag, which the H1 and H2 muxes never do on a 1xx. The stream forwards it as an interim response and, the applet being done, produces a 502 while the interim response is still in the buffer. Since commit 5fb43f017 ("MEDIUM: htx: Harden HTX API to avoid invalid uses when EOM was reached") in 3.5-dev8, it crashes on BUG_ON(htx_msg_ended(dst)). Before, the client got the interim response followed by the 502. Let's make start_response() raise a Lua error for interim responses other than 101, so the service fails with a 500 as for any other error. The documentation of set_status() was updated accordingly. No backport needed. --- doc/lua-api/index.rst | 3 ++- src/hlua.c | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/doc/lua-api/index.rst b/doc/lua-api/index.rst index ffe638429..1bd9be23c 100644 --- a/doc/lua-api/index.rst +++ b/doc/lua-api/index.rst @@ -3842,7 +3842,8 @@ AppletHTTP class .. js:function:: AppletHTTP.set_status(applet, code [, reason]) This function sets the HTTP status code for the response. The allowed code are - from 100 to 599. + from 100 to 599. Interim responses (1xx except 101) are rejected by + *AppletHTTP:start_response()* since no final response could follow. :param class_AppletHTTP applet: An :ref:`applethttp_class` :param integer code: the status code returned to the client. diff --git a/src/hlua.c b/src/hlua.c index 1f227d354..18471cb75 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -6210,6 +6210,13 @@ __LJMP static int hlua_applet_http_send_response(lua_State *L) htx = htx_from_buf(outbuf); h1m_init_res(&h1m); + /* no final response can follow an interim one */ + if (http_ctx->status < 200 && http_ctx->status != 101) { + hlua_pusherror(L, "Lua applet http '%s': interim responses are not supported.\n", + luactx->appctx->applet->name); + WILL_LJMP(lua_error(L)); + } + /* Use the same http version than the request. */ status = ultoa_r(http_ctx->status, trash.area, trash.size); reason = http_ctx->reason; -- 2.47.3