Return-Path: X-Original-To: apmail-httpd-cvs-archive@www.apache.org Delivered-To: apmail-httpd-cvs-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 457B910FAA for ; Thu, 20 Feb 2014 11:54:53 +0000 (UTC) Received: (qmail 97704 invoked by uid 500); 20 Feb 2014 11:54:51 -0000 Delivered-To: apmail-httpd-cvs-archive@httpd.apache.org Received: (qmail 97626 invoked by uid 500); 20 Feb 2014 11:54:50 -0000 Mailing-List: contact cvs-help@httpd.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@httpd.apache.org list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list cvs@httpd.apache.org Received: (qmail 97614 invoked by uid 99); 20 Feb 2014 11:54:49 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 20 Feb 2014 11:54:49 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 20 Feb 2014 11:54:48 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 689A52388860; Thu, 20 Feb 2014 11:54:28 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1570162 - in /httpd/httpd/branches/2.4.x: CHANGES docs/manual/mod/mod_lua.xml modules/lua/lua_request.c Date: Thu, 20 Feb 2014 11:54:28 -0000 To: cvs@httpd.apache.org From: humbedooh@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140220115428.689A52388860@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: humbedooh Date: Thu Feb 20 11:54:27 2014 New Revision: 1570162 URL: http://svn.apache.org/r1570162 Log: mod_lua: Backport setcookie changes. PR 56128 Modified: httpd/httpd/branches/2.4.x/CHANGES httpd/httpd/branches/2.4.x/docs/manual/mod/mod_lua.xml httpd/httpd/branches/2.4.x/modules/lua/lua_request.c Modified: httpd/httpd/branches/2.4.x/CHANGES URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/CHANGES?rev=1570162&r1=1570161&r2=1570162&view=diff ============================================================================== --- httpd/httpd/branches/2.4.x/CHANGES [utf-8] (original) +++ httpd/httpd/branches/2.4.x/CHANGES [utf-8] Thu Feb 20 11:54:27 2014 @@ -11,6 +11,10 @@ Changes with Apache 2.4.8 *) mod_remoteip: Use the correct IP addresses to populate the proxy_ips field. PR 55972. [Mike Rumph] + *) mod_lua: Update r:setcookie() to accept a table of options and add domain, + path and httponly to the list of options available to set. + PR 56128 [Edward Lu , Daniel Gruno] + *) mod_lua: Fix r:setcookie() to add, rather than replace, the Set-Cookie header. PR56105 [Kevin J Walters , Edward Lu ] Modified: httpd/httpd/branches/2.4.x/docs/manual/mod/mod_lua.xml URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/docs/manual/mod/mod_lua.xml?rev=1570162&r1=1570161&r2=1570162&view=diff ============================================================================== --- httpd/httpd/branches/2.4.x/docs/manual/mod/mod_lua.xml (original) +++ httpd/httpd/branches/2.4.x/docs/manual/mod/mod_lua.xml Thu Feb 20 11:54:27 2014 @@ -972,8 +972,22 @@ r:getcookie(key) -- Gets a HTTP cookie -r:setcookie(key, value, secure, expires) -- Sets a HTTP cookie, for instance: -r:setcookie("foo", "bar and stuff", false, os.time() + 86400) +r:setcookie{ + key = [key], + value = [value], + expires = [expiry], + secure = [boolean], + httponly = [boolean], + path = [path], + domain = [domain] +} -- Sets a HTTP cookie, for instance: + +r:setcookie{ + key = "cookie1", + value = "HDHfa9eyffh396rt", + expires = os.time() + 86400, + secure = true +} Modified: httpd/httpd/branches/2.4.x/modules/lua/lua_request.c URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/modules/lua/lua_request.c?rev=1570162&r1=1570161&r2=1570162&view=diff ============================================================================== --- httpd/httpd/branches/2.4.x/modules/lua/lua_request.c (original) +++ httpd/httpd/branches/2.4.x/modules/lua/lua_request.c Thu Feb 20 11:54:27 2014 @@ -1963,27 +1963,101 @@ static int lua_get_cookie(lua_State *L) static int lua_set_cookie(lua_State *L) { - const char *key, *value, *out, *strexpires; - int secure, expires; + const char *key, *value, *out, *path = "", *domain = ""; + const char *strexpires = "", *strdomain = "", *strpath = ""; + int secure = 0, expires = 0, httponly = 0; char cdate[APR_RFC822_DATE_LEN+1]; apr_status_t rv; request_rec *r = ap_lua_check_request_rec(L, 1); - key = luaL_checkstring(L, 2); - value = luaL_checkstring(L, 3); - secure = 0; - if (lua_isboolean(L, 4)) { - secure = lua_toboolean(L, 4); + + /* New >= 2.4.8 method: */ + if (lua_istable(L, 2)) { + + /* key */ + lua_pushstring(L, "key"); + lua_gettable(L, -2); + key = luaL_checkstring(L, -1); + lua_pop(L, 1); + + /* value */ + lua_pushstring(L, "value"); + lua_gettable(L, -2); + value = luaL_checkstring(L, -1); + lua_pop(L, 1); + + /* expiry */ + lua_pushstring(L, "expires"); + lua_gettable(L, -2); + expires = luaL_optint(L, -1, 0); + lua_pop(L, 1); + + /* secure */ + lua_pushstring(L, "secure"); + lua_gettable(L, -2); + if (lua_isboolean(L, -1)) { + secure = lua_toboolean(L, -1); + } + lua_pop(L, 1); + + /* httponly */ + lua_pushstring(L, "httponly"); + lua_gettable(L, -2); + if (lua_isboolean(L, -1)) { + httponly = lua_toboolean(L, -1); + } + lua_pop(L, 1); + + /* path */ + lua_pushstring(L, "path"); + lua_gettable(L, -2); + path = luaL_optstring(L, -1, "/"); + lua_pop(L, 1); + + /* domain */ + lua_pushstring(L, "domain"); + lua_gettable(L, -2); + domain = luaL_optstring(L, -1, ""); + lua_pop(L, 1); } - expires = luaL_optinteger(L, 5, 0); - strexpires = ""; + /* Old <= 2.4.7 method: */ + else { + key = luaL_checkstring(L, 2); + value = luaL_checkstring(L, 3); + secure = 0; + if (lua_isboolean(L, 4)) { + secure = lua_toboolean(L, 4); + } + expires = luaL_optinteger(L, 5, 0); + } + + /* Calculate expiry if set */ if (expires > 0) { rv = apr_rfc822_date(cdate, apr_time_from_sec(expires)); if (rv == APR_SUCCESS) { - strexpires = apr_psprintf(r->pool, "Expires=%s", cdate); + strexpires = apr_psprintf(r->pool, "Expires=\"%s\";", cdate); } } - out = apr_psprintf(r->pool, "%s=%s; %s %s", key, value, secure ? "Secure;" : "", expires ? strexpires : ""); - apr_table_add(r->headers_out, "Set-Cookie", out); + + /* Create path segment */ + if (path != NULL && strlen(path) > 0) { + strpath = apr_psprintf(r->pool, "Path=\"%s\";", path); + } + + /* Create domain segment */ + if (domain != NULL && strlen(domain) > 0) { + /* Domain does NOT like quotes in most browsers, so let's avoid that */ + strdomain = apr_psprintf(r->pool, "Domain=%s;", domain); + } + + /* Create the header */ + out = apr_psprintf(r->pool, "%s=%s; %s %s %s %s %s", key, value, + secure ? "Secure;" : "", + expires ? strexpires : "", + httponly ? "HttpOnly;" : "", + strlen(strdomain) ? strdomain : "", + strlen(strpath) ? strpath : ""); + + apr_table_add(r->err_headers_out, "Set-Cookie", out); return 0; }