From ef12aaf13c6e303706649abf112ffa977523f7c0 Mon Sep 17 00:00:00 2001 From: Bruno Deferrari Date: Thu, 24 Apr 2014 17:15:55 -0300 Subject: [PATCH] Support for repeated headers in responses in the Lua plugin This is needed for WSAPI conformance, and important for having good support of Set-Cookie. --- plugins/lua/lua_plugin.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/plugins/lua/lua_plugin.c b/plugins/lua/lua_plugin.c index 160b1741..fe810457 100644 --- a/plugins/lua/lua_plugin.c +++ b/plugins/lua/lua_plugin.c @@ -811,8 +811,25 @@ static int uwsgi_lua_request(struct wsgi_request *wsgi_req) { lua_pushnil(L); while(lua_next(L, -3) != 0) { http = lua_tolstring(L, -2, &slen); - http2 = lua_tolstring(L, -1, &slen2); - uwsgi_response_add_header(wsgi_req, (char *) http, slen, (char *) http2, slen2); + + if (lua_type(L, -1) == LUA_TTABLE) { + for (i = 1; /*empty*/ ; ++i) { + lua_rawgeti(L, -1, i); + + if (lua_isnil(L, -1)) { + lua_pop(L, 1); + break; + } + + http2 = lua_tolstring(L, -1, &slen2); + uwsgi_response_add_header(wsgi_req, (char *) http, slen, (char *) http2, slen2); + lua_pop(L, 1); + } + } + else { + http2 = lua_tolstring(L, -1, &slen2); + uwsgi_response_add_header(wsgi_req, (char *) http, slen, (char *) http2, slen2); + } lua_pop(L, 1); }