set $cookie_abc "$cookie_abc";

agentzh agentzh at
Mon Feb 11 19:47:37 UTC 2013


On Mon, Feb 11, 2013 at 1:49 AM, amodpandey wrote:
> I have some lua code where I play with the value of ngx.var.cookie_abc. The
> variable must exist if some assignment is done on it.
> To achieve this I did
> set $cookie_abc "$cookie_abc";
> The above line clears the value of $cookie_abc, where in I assumed it to be
> defaulted if the value already exists.

Are you sure? Which version of ngx_lua and Nginx are you using?

I've tried the following minimal example on my side with Nginx 1.2.6 +
ngx_lua 0.7.14 and it works as expected:

    location = /t {
        content_by_lua '
            ngx.say("cookie abc: ", ngx.var.cookie_abc)

And let's use curl to access location = /t (assuming the Nginx is
listening on the local port 8080):

    $ curl -H 'Cookie: abc=32' localhost:8080/t
    cookie abc: 32

    $ curl localhost:8080/t
    cookie abc: nil

Please note that your request must actually take a Cookie request
header, otherwise the value of $cookie_abc will surely be empty (or
nil, to be more accurate).

Best regards,

More information about the nginx mailing list