项目上需要给cookie设置httponly属性,但是cookie设置的点较多不能每处设置,所以在server处使用
header_filter_by_lua_block指令统一修改response头的set_cookie属性
header_filter_by_lua_block{
local cookies = ngx.header.set_cookie
if cookies then
if type(cookies) == "table" then
local cookie={}
for k,v in pairs(cookies) do
cookie[k]=v..";httponly"
end
ngx.header.set_cookie = cookie
else
ngx.header.set_cookie= cookies..";httponly"
end
end
}