Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve cookie baking performance #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 37 additions & 9 deletions lib/resty/cookie.lua
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,43 @@ local function bake(cookie)
end
end

local str = cookie.key .. "=" .. cookie.value
.. (cookie.expires and "; Expires=" .. cookie.expires or "")
.. (cookie.max_age and "; Max-Age=" .. cookie.max_age or "")
.. (cookie.domain and "; Domain=" .. cookie.domain or "")
.. (cookie.path and "; Path=" .. cookie.path or "")
.. (cookie.secure and "; Secure" or "")
.. (cookie.httponly and "; HttpOnly" or "")
.. (cookie.samesite and "; SameSite=" .. cookie.samesite or "")
.. (cookie.extension and "; " .. cookie.extension or "")
local cookie_parts = new_tab(19, 0)
cookie_parts[#cookie_parts+1] = cookie.key
cookie_parts[#cookie_parts+1] = "="
cookie_parts[#cookie_parts+1] = cookie.value
if cookie.expires then
cookie_parts[#cookie_parts+1] = "; Expires="
cookie_parts[#cookie_parts+1] = cookie.expires
end
if cookie.max_age then
cookie_parts[#cookie_parts+1] = "; Max-Age="
cookie_parts[#cookie_parts+1] = cookie.max_age
end
if cookie.domain then
cookie_parts[#cookie_parts+1] = "; Domain="
cookie_parts[#cookie_parts+1] = cookie.domain
end
if cookie.path then
cookie_parts[#cookie_parts+1] = "; Path="
cookie_parts[#cookie_parts+1] = cookie.path
end
if cookie.secure then
cookie_parts[#cookie_parts+1] = "; Secure="
cookie_parts[#cookie_parts+1] = cookie.secure
end
if cookie.httponly then
cookie_parts[#cookie_parts+1] = "; HttpOnly="
cookie_parts[#cookie_parts+1] = cookie.httponly
end
if cookie.samesite then
cookie_parts[#cookie_parts+1] = "; SameSite="
cookie_parts[#cookie_parts+1] = cookie.samesite
end
if cookie.extension then
cookie_parts[#cookie_parts+1] = "; "
cookie_parts[#cookie_parts+1] = cookie.extension
end
local str = table.concat(cookie_parts, "")
return str
end

Expand Down