webmcp
diff framework/env/request/set_cookie.lua @ 16:944642a3e488
New set_cookie functions; Added inline documentation; Make set_allowed_json_request_slots work in interactive shell
author | jbe/bsw |
---|---|
date | Thu Mar 25 17:37:03 2010 +0100 (2010-03-25) |
parents | |
children | 32ec28229bb5 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/framework/env/request/set_cookie.lua Thu Mar 25 17:37:03 2010 +0100 1.3 @@ -0,0 +1,43 @@ 1.4 +--[[-- 1.5 +request.set_cookie{ 1.6 + name = name, -- name of cookie 1.7 + value = value, -- value of cookie 1.8 + domain = domain, -- optional domain domain where cookie is transmitted 1.9 + path = path, -- optional path where cookie is transmitted, defaults to application base 1.10 + secure = secure -- optional boolean, indicating if cookie should only be transmitted over HTTPS 1.11 +} 1.12 + 1.13 +This function is similar to rocketwiki.set_cookie{...}, except that it automatically sets the path to the application base. It also sets secure=true, if the secure option is unset and the application base URL starts with "https://". 1.14 + 1.15 +--]]-- 1.16 + 1.17 +function request.set_cookie(args) 1.18 + local path = args.path 1.19 + if not path then 1.20 + path = string.match( 1.21 + request.get_absolute_baseurl(), 1.22 + "://[^/]*(.*)" 1.23 + ) 1.24 + if path == nil or path == "" then 1.25 + path = "/" 1.26 + end 1.27 + end 1.28 + local secure = args.secure 1.29 + if secure == nil then 1.30 + if string.find( 1.31 + string.lower(request.get_absolute_baseurl()), 1.32 + "^https://" 1.33 + ) then 1.34 + secure = true 1.35 + else 1.36 + secure = false 1.37 + end 1.38 + end 1.39 + cgi.set_cookie{ 1.40 + name = args.name, 1.41 + value = args.value, 1.42 + domain = args.domain, 1.43 + path = path, 1.44 + secure = secure 1.45 + } 1.46 +end