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