使用 nginx lua 进行 body_filter_by_lua_block 过滤

以下代码为 Nginx Lua:

body_filter_by_lua_block {
    function check_access_file(file)
        local fh = io.open(file,'rb')
        if fh then
            fh:close()
            return true
        else
            return false
        end
        return false
    end

    function write_file(file, str)
        local check_access_file = check_access_file(file)
        if check_access_file  then
            local fh = io.open(file, "a")
            fh:write(str, "\n")
            fh:close()
        end
    end
    write_file('/etc/nginx/111', '1234567='..ngx.arg[1])
}

当你运行它一次时,会有两个回复写入文件

1234567 = test
1234567 =

为什么每个请求都会向文件 111 写入两个响应?

点赞