Welcome! Log In Create A New Profile

Advanced

Bug with keyvals and Javascript?

Posted by j94305 
Bug with keyvals and Javascript?
August 25, 2019 09:56AM
When I define a map in NGINX like

keyval_zone zone=session:2m timeout=1d sync state=/var/run/nginx/state/session.json;
keyval $user_id $map_session zone=session;

I can read entries in Javascript functions, provided $user_id is set, like this:

var value = r.variables.map_session;

and assign new values:

r.variables.map_session = newValue;

However, while usually one can also write variable references r.variables.foo as r.variables["foo"], this does not work for references handled by keyval mappings.

I am not sure whether this is a bug or intentional, but if you want to create a function that takes the name of a map and updates its entries (e.g., from a file or a sub-request), it would certainly come handy to be able to refer to an entry by specifying

var key = "map_" + mappingName;
r.variables[key] = newValue;

This does not work in nginx/1.15.10 (nginx-plus-r18-p1).

Cheers,
--j.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 62
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready