通过lua nginx捕获头部信息

我想要捕获只包含单词“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('已捕获包含Foo的头部信息');
        }

    }

但是不幸的是它没有起作用。 抱歉,我是lua和nginx的新手。感谢任何帮助

原文链接 https://stackoverflow.com/questions/71253868

点赞
stackoverflow用户7504558
stackoverflow用户7504558
可能需要查看值:
    local h = ngx.req.get_headers()
    for k, v in pairs(h) do
        if v:find("foo") then -- 等效于 v:match("foo")
            ngx.header[k] = v
        end
    end

```

或者你有你自己的键: if k:find("foo") then

2022-02-24 15:08:22