webmcp
annotate framework/env/request/set_cookie.lua @ 28:ea2e8f3a2776
allow webmcp path to be set in cgi script
this allows another script to include the webmcp script when the cwd is not the cgi-bin. the script needs to set the WEBMCP_PATH variable.
this allows another script to include the webmcp script when the cwd is not the cgi-bin. the script needs to set the WEBMCP_PATH variable.
author | Daniel Poelzleithner <poelzi@poelzi.org> |
---|---|
date | Sun Sep 19 01:36:08 2010 +0200 (2010-09-19) |
parents | 944642a3e488 |
children | 32ec28229bb5 |
rev | line source |
---|---|
jbe/bsw@16 | 1 --[[-- |
jbe/bsw@16 | 2 request.set_cookie{ |
jbe/bsw@16 | 3 name = name, -- name of cookie |
jbe/bsw@16 | 4 value = value, -- value of cookie |
jbe/bsw@16 | 5 domain = domain, -- optional domain domain where cookie is transmitted |
jbe/bsw@16 | 6 path = path, -- optional path where cookie is transmitted, defaults to application base |
jbe/bsw@16 | 7 secure = secure -- optional boolean, indicating if cookie should only be transmitted over HTTPS |
jbe/bsw@16 | 8 } |
jbe/bsw@16 | 9 |
jbe/bsw@16 | 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://". |
jbe/bsw@16 | 11 |
jbe/bsw@16 | 12 --]]-- |
jbe/bsw@16 | 13 |
jbe/bsw@16 | 14 function request.set_cookie(args) |
jbe/bsw@16 | 15 local path = args.path |
jbe/bsw@16 | 16 if not path then |
jbe/bsw@16 | 17 path = string.match( |
jbe/bsw@16 | 18 request.get_absolute_baseurl(), |
jbe/bsw@16 | 19 "://[^/]*(.*)" |
jbe/bsw@16 | 20 ) |
jbe/bsw@16 | 21 if path == nil or path == "" then |
jbe/bsw@16 | 22 path = "/" |
jbe/bsw@16 | 23 end |
jbe/bsw@16 | 24 end |
jbe/bsw@16 | 25 local secure = args.secure |
jbe/bsw@16 | 26 if secure == nil then |
jbe/bsw@16 | 27 if string.find( |
jbe/bsw@16 | 28 string.lower(request.get_absolute_baseurl()), |
jbe/bsw@16 | 29 "^https://" |
jbe/bsw@16 | 30 ) then |
jbe/bsw@16 | 31 secure = true |
jbe/bsw@16 | 32 else |
jbe/bsw@16 | 33 secure = false |
jbe/bsw@16 | 34 end |
jbe/bsw@16 | 35 end |
jbe/bsw@16 | 36 cgi.set_cookie{ |
jbe/bsw@16 | 37 name = args.name, |
jbe/bsw@16 | 38 value = args.value, |
jbe/bsw@16 | 39 domain = args.domain, |
jbe/bsw@16 | 40 path = path, |
jbe/bsw@16 | 41 secure = secure |
jbe/bsw@16 | 42 } |
jbe/bsw@16 | 43 end |