Skip to content

Commit

Permalink
Merge pull request #126 from lpereira/cookie-lwan
Browse files Browse the repository at this point in the history
Add support for cookies when using Sailor with Lwan
  • Loading branch information
Etiene committed Aug 1, 2016
2 parents a8e470b + c4c86e2 commit 734ab36
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/sailor/cookie.lua
Expand Up @@ -15,15 +15,18 @@ function cookie.set(r, key, value, path)
local ck = require "cgilua.cookies"
return ck.set(key,value,{path=path})
end
r.headers_out['Set-Cookie'] = ("%s=%s;Path=%s;"):format(key, value, path)
r.headers_out['Set-Cookie'] = ("%s=%s;Path=%s;"):format(key, value, path)
end

function cookie.get(r, key)
if remy.detect(r) == remy.MODE_CGILUA then
local remy_mode = remy.detect(r)
if remy_mode == remy.MODE_CGILUA then
local ck = require "cgilua.cookies"
return ck.get(key)
elseif remy_mode == remy.MODE_LWAN then
return r.native_request:cookie(key)
end
return (r.headers_in['Cookie'] or ""):match(key .. "=([^;]+)") or ""
return (r.headers_in['Cookie'] or ""):match(key .. "=([^;]+)") or ""
end

return cookie
return cookie

0 comments on commit 734ab36

Please sign in to comment.