Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How use nginx variable $cookie with point cookie, like "foo.bar"

How use Nginx variable $cookie_ with dot (point) cookie, like "foo.bar" If i write "$cookie_foo.bar" in access log file i have "-.bar"

like image 704
Hybrid Avatar asked Nov 06 '25 21:11

Hybrid


1 Answers

The WONTFIX comment on @aorth's bug's resolution is supremely unhelpful, and I'm still flabbergasted that Nginx just refuses to accommodate perfectly legal characters in cookie names. They could just replace the "magic" nginx chars in cookie names with underscores, or make you escape "magic" chars, or any number of other ways people have already solved similar problems.

It's not rocket surgery, Nginx.

Anyhow, this is how I wound up extracting the value for a cookie named foo.lang that my devs put in a critical app:

map $http_cookie $foo_lang_cookie {
    default "";
    "~foo\.lang=(?<foo_lang>[^;]+)" $foo_lang;
}

Hopefully my hours of fruitless Googling and beating my head against the wall can benefit other lost souls who find their way here.

like image 191
Sammitch Avatar answered Nov 09 '25 01:11

Sammitch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!