webmcp

view 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 source
1 --[[--
2 request.set_cookie{
3 name = name, -- name of cookie
4 value = value, -- value of cookie
5 domain = domain, -- optional domain domain where cookie is transmitted
6 path = path, -- optional path where cookie is transmitted, defaults to application base
7 secure = secure -- optional boolean, indicating if cookie should only be transmitted over HTTPS
8 }
10 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://".
12 --]]--
14 function request.set_cookie(args)
15 local path = args.path
16 if not path then
17 path = string.match(
18 request.get_absolute_baseurl(),
19 "://[^/]*(.*)"
20 )
21 if path == nil or path == "" then
22 path = "/"
23 end
24 end
25 local secure = args.secure
26 if secure == nil then
27 if string.find(
28 string.lower(request.get_absolute_baseurl()),
29 "^https://"
30 ) then
31 secure = true
32 else
33 secure = false
34 end
35 end
36 cgi.set_cookie{
37 name = args.name,
38 value = args.value,
39 domain = args.domain,
40 path = path,
41 secure = secure
42 }
43 end

Impressum / About Us