set $cookie_abc "$cookie_abc";

Ruslan Ermilov ru at nginx.com
Mon Feb 11 10:12:56 UTC 2013


On Mon, Feb 11, 2013 at 04:49:46AM -0500, 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.
> 
> i.e. if request has cookie abc="test" set, the $cookie_abc will have value
> test. But after executing the above expression the value is set to blank "".
> Where in it should have been "test". If the cookie value is not present in
> the request then obviously the value should be blank.
> 
> Is there a way around it? If not, can it be fixed.
> 
> Note even this won't work
> 
> set $tmp_abc "$cookie_abc";
> set $cookie_abc "$tmp_abc";
> 
> There variable values are referential so even $tmp_abc become blank.

map $cookie_abc $abc {
    '' default;
    default $cookie_abc;
}

will set $abc to the value of $cookie_abc if not empty, or to
"default" if cookie is unset or empty.

http://nginx.org/r/map



More information about the nginx mailing list