From 71ca51c1a6d7a36e1944780c51ad3bcd36c29ad0 Mon Sep 17 00:00:00 2001 From: Daniel Gruno Date: Fri, 17 Aug 2012 09:41:46 +0000 Subject: [PATCH] mod_lua: Allow scripts handled by the lua-script handler to set a return code that will be sent to the client, such as 302, 500 etc. This will allow scripts to be able to f.x. redirect a user to another page by returning 302. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1374185 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES | 3 +++ modules/lua/mod_lua.c | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 4b97109fd4..ab566c34f7 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,9 @@ -*- coding: utf-8 -*- Changes with Apache 2.5.0 + *) mod_lua: Allow scripts handled by the lua-script handler to return + a status code to the client (such as a 302 or a 500) [Daniel Gruno] + *) mod_proxy_ajp: Fix crash in packet dump code when logging with LogLevel trace7 or trace8. PR 53730. [Rainer Jung] diff --git a/modules/lua/mod_lua.c b/modules/lua/mod_lua.c index 23aaf1a774..4aa2aa87bf 100644 --- a/modules/lua/mod_lua.c +++ b/modules/lua/mod_lua.c @@ -233,6 +233,7 @@ static const char* ap_lua_interpolate_string(apr_pool_t* pool, const char* strin */ static int lua_handler(request_rec *r) { + int rc = OK; if (strcmp(r->handler, "lua-script")) { return DECLINED; } @@ -275,12 +276,15 @@ static int lua_handler(request_rec *r) return HTTP_INTERNAL_SERVER_ERROR; } ap_lua_run_lua_request(L, r); - if (lua_pcall(L, 1, 0, 0)) { + if (lua_pcall(L, 1, 1, 0)) { report_lua_error(L, r); } + if (lua_isnumber(L, -1)) { + rc = lua_tointeger(L, -1); + } ap_lua_release_state(L, spec, r); } - return OK; + return rc; } -- 2.40.0