]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: lua: service/applet can have access to the HTTP headers when a POST is received
authorThierry FOURNIER <tfournier@arpalert.org>
Fri, 11 Dec 2015 16:10:09 +0000 (17:10 +0100)
committerWilly Tarreau <w@1wt.eu>
Sun, 20 Dec 2015 22:12:12 +0000 (23:12 +0100)
When a POST is processed by a Lua service, the HTTP header are
potentially gone. So, we cannot retrieve their content using
the standard "hdr" sample fetchs (which will soon become invalid
anyway) from an applet.

This patch add an entry "headers" to the object applet_http. This
entry is an array containing all the headers. It permits to use the
HTTP headers during the processing of the service.

Many thanks to Jan Bruder for reporting this issue with enough
details to reproduce it.

This patch will have to be backported to 1.6 since it will be the
only way to access headers from Lua applets.

doc/lua-api/index.rst
src/hlua.c

index 60c972507ad04579c02564db3706d66f5cff4161..9972c49200623c5b8adbbc5e27ab8c4150d36f05 100644 (file)
@@ -1369,6 +1369,10 @@ AppletHTTP class
   end)
 
 
+.. js:attribute:: AppletHTTP.headers
+
+  Contains an array containing all the request headers.
+
 .. js:function:: AppletHTTP.set_status(code)
 
   This function sets the HTTP status code for the response. The allowed code are
index 17e9b54e02137c886e1b966d9b4345ab85b55dd8..a03b9ddd96175424e1a15491abdf725b585989fc 100644 (file)
@@ -3476,6 +3476,7 @@ __LJMP static struct hlua_appctx *hlua_checkapplet_http(lua_State *L, int ud)
 static int hlua_applet_http_new(lua_State *L, struct appctx *ctx)
 {
        struct hlua_appctx *appctx;
+       struct hlua_txn htxn;
        struct stream_interface *si = ctx->owner;
        struct stream *s = si_strm(si);
        struct proxy *px = s->be;
@@ -3534,6 +3535,17 @@ static int hlua_applet_http_new(lua_State *L, struct appctx *ctx)
        lua_pushlstring(L, txn->req.chn->buf->p + txn->req.sl.rq.v, txn->req.sl.rq.v_l);
        lua_settable(L, -3);
 
+       /* creates an array of headers. hlua_http_get_headers() crates and push
+        * the array on the top of the stack.
+        */
+       lua_pushstring(L, "headers");
+       htxn.s = s;
+       htxn.p = px;
+       htxn.dir = SMP_OPT_DIR_REQ;
+       if (!hlua_http_get_headers(L, &htxn, &htxn.s->txn->req))
+               return 0;
+       lua_settable(L, -3);
+
        /* Get path and qs */
        path = http_get_path(txn);
        end = txn->req.chn->buf->p + txn->req.sl.rq.u + txn->req.sl.rq.u_l;