webmcp
view framework/env/request/set_cookie.lua @ 30:6e08067e66c1
allow disabled records in select widget
this allows the use record entries as seperators
this allows the use record entries as seperators
| author | Daniel Poelzleithner <poelzi@poelzi.org> | 
|---|---|
| date | Mon Sep 20 20:11:29 2010 +0200 (2010-09-20) | 
| parents | 944642a3e488 | 
| 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
