Skip to content

Accessing testcookie_ok variable from log_by_lua_block #67

@tokumeo

Description

@tokumeo

I have a use case for setting another variable depending on the value of testcookie_ok variable. I'm trying to achieve this with lua-nginx-module by using log_by_lua_block directive. Unfortunately, when reading testcookie_ok from lua using ngx.var API from log_by_lua_block, the value of testcookie_ok is always nil. But when adding testcookie_ok to access log, the value is either "0" or "1" depending on the results of the validation. Could you please provide some insight on why testcookie_ok might be nil when reading it from log_by_lua_block?

   testcookie_name YouShallNotPass;
   testcookie_session $remote_addr;
   testcookie on;

    log_by_lua_block {
        ngx.log(ngx.DEBUG, "testcookie_ok=", ngx.var.testcookie_ok)
    }

Here are the logs:

# no cookie
2018/12/19 14:17:13 [debug] 19639#19639: *19409 [lua] log_by_lua(default.conf:33):3: testcookie_ok=nil
192.168.122.1 - - [19/Dec/2018:14:17:13 +0300] "GET / HTTP/1.1" 307 171 "-" "curl/7.47.0" "-" testcookie_ok=0

# correct cookie
2018/12/19 14:17:53 [debug] 19639#19639: *19490 [lua] log_by_lua(default.conf:33):3: testcookie_ok=nil
192.168.122.1 - - [19/Dec/2018:14:17:53 +0300] "GET / HTTP/1.1" 200 0 "-" "curl/7.47.0" "-" testcookie_ok=1

I've tried compiling nginx with different order of testcookie and lua-nginx modules, but the situation doesn't change.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions