BUG/MINOR: lua: Lua applets must not use http_txn
In certain circumstances (eg: Lua HTTP applet called from a
TCP ruleset before http_process_request()), the HTTP TXN is not
yet fully initialized so some information it contains cannot be
relied on. Such information include the HTTP version, the state
of the expect: 100-continue header, the connection header and
the transfer-encoding header.
Here the bug only turns something which already doesn't work
into something wrong, but better avoid any references to the
http_txn from the Lua code to avoid future mistakes.
This patch should be backported into 1.6 for code consistency.
diff --git a/src/hlua.c b/src/hlua.c
index ae49caa..b399b26 100644
--- a/src/hlua.c
+++ b/src/hlua.c
@@ -115,6 +115,7 @@
#define APPLET_HDR_SENT 0x04 /* Response header sent. */
#define APPLET_CHUNKED 0x08 /* Use transfer encoding chunked. */
#define APPLET_LAST_CHK 0x10 /* Last chunk sent. */
+#define APPLET_HTTP11 0x20 /* Last chunk sent. */
#define HTTP_100C "HTTP/1.1 100 Continue\r\n\r\n"
@@ -3969,9 +3970,6 @@
{
struct chunk *tmp = get_trash_chunk();
struct hlua_appctx *appctx = MAY_LJMP(hlua_checkapplet_http(L, 1));
- struct stream_interface *si = appctx->appctx->owner;
- struct stream *s = si_strm(si);
- struct http_txn *txn = s->txn;
const char *name;
const char *value;
int id;
@@ -3981,7 +3979,7 @@
/* Use the same http version than the request. */
chunk_appendf(tmp, "HTTP/1.%c %d %s\r\n",
- txn->req.flags & HTTP_MSGF_VER_11 ? '1' : '0',
+ appctx->appctx->ctx.hlua_apphttp.flags & APPLET_HTTP11 ? '1' : '0',
appctx->appctx->ctx.hlua_apphttp.status,
get_reason(appctx->appctx->ctx.hlua_apphttp.status));
@@ -4077,7 +4075,7 @@
* respected by haproxy. HAProcy considers that the application cloe the connection
* and it keep the connection from the client open.
*/
- if (txn->req.flags & HTTP_MSGF_VER_11 && !hdr_connection)
+ if (appctx->appctx->ctx.hlua_apphttp.flags & APPLET_HTTP11 && !hdr_connection)
chunk_appendf(tmp, "Connection: close\r\n");
/* If we dont have a content-length set, we must announce a transfer enconding
@@ -5789,6 +5787,9 @@
ctx->ctx.hlua_apphttp.left_bytes = -1;
ctx->ctx.hlua_apphttp.flags = 0;
+ if (txn->req.flags & HTTP_MSGF_VER_11)
+ ctx->ctx.hlua_apphttp.flags |= APPLET_HTTP11;
+
/* Create task used by signal to wakeup applets. */
task = task_new();
if (!task) {