我只想捕獲一些包含單詞“foo”的標題。我用它lua nginx 模塊 我的代碼
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');
}
}
但不幸的是,它不起作用。對不起,我是 Lua 和 nginx 的新手。謝謝你的幫助
uj5u.com熱心網友回復:
可能需要查看值:
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
或者你有自己的鑰匙:if k:find("foo") then
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/432647.html
