jbe/bsw@16: --[[-- jbe/bsw@16: request.set_cookie{ jbe/bsw@16: name = name, -- name of cookie jbe/bsw@16: value = value, -- value of cookie jbe/bsw@16: domain = domain, -- optional domain domain where cookie is transmitted jbe/bsw@16: path = path, -- optional path where cookie is transmitted, defaults to application base jbe/bsw@16: secure = secure -- optional boolean, indicating if cookie should only be transmitted over HTTPS jbe/bsw@16: } jbe/bsw@16: jbe/bsw@16: 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: jbe/bsw@16: --]]-- jbe/bsw@16: jbe/bsw@16: function request.set_cookie(args) jbe/bsw@16: local path = args.path jbe/bsw@16: if not path then jbe/bsw@16: path = string.match( jbe/bsw@16: request.get_absolute_baseurl(), jbe/bsw@16: "://[^/]*(.*)" jbe/bsw@16: ) jbe/bsw@16: if path == nil or path == "" then jbe/bsw@16: path = "/" jbe/bsw@16: end jbe/bsw@16: end jbe/bsw@16: local secure = args.secure jbe/bsw@16: if secure == nil then jbe/bsw@16: if string.find( jbe/bsw@16: string.lower(request.get_absolute_baseurl()), jbe/bsw@16: "^https://" jbe/bsw@16: ) then jbe/bsw@16: secure = true jbe/bsw@16: else jbe/bsw@16: secure = false jbe/bsw@16: end jbe/bsw@16: end jbe/bsw@16: cgi.set_cookie{ jbe/bsw@16: name = args.name, jbe/bsw@16: value = args.value, jbe/bsw@16: domain = args.domain, jbe/bsw@16: path = path, jbe/bsw@16: secure = secure jbe/bsw@16: } jbe/bsw@16: end