I want to capture only some headers which contains word "foo". I used for it lua nginx module My code
location /lua_test {
content_by_lua_block {
local h = ngx.req.get_headers()
for k, v in pairs(h) do
if k == k:match("([%w].Foo.*):(. )") then
ngx.header[k] = v
end
end
ngx.say('headers with Foo are captured');
}
}
But unfortunately it doesn't work. Sorry, I'm newbie to Lua and nginx. Thanks for any help
CodePudding user response:
may be need to look in the values:
local h = ngx.req.get_headers()
for k, v in pairs(h) do
if v:find("foo") then -- equivalent v:match("foo")
ngx.header[k] = v
end
end
or do you have your own keys: if k:find("foo") then