NJS Questions and/or Bugs

Dmitry Volyntsev xeioex at nginx.com
Thu Aug 12 06:14:42 UTC 2021

Hi Lance,

Thanks for your detailed feedback.

 >What exactly should r.variables and r.rawVariables contain?  ...

r.variables and r.rawVariables are special objects, because they are 
created on the fly. There is no way to get all the possible variable 
names from nginx. So Object.keys(r.variables) is empty list. Therefore 
dumping and iterating over r.variables returns nothing. But, if you have 
a $foo variable, r.variables.foo would return the $foo content as a string.

 > That might also be a fallacy of our testing methodology since we’re 
using JSON.stringify to visualize the output in the browser.

The JSON.stringify() is no the best, use njs.dump(). 

 >Is there already an NJS object or are there plans for an object that 
parses and maps POST key/value pairs into a JSON object?

Take a look at https://github.com/nginx/njs/issues/48#issuecomment-415745451

 >Filters for the different phase of the Nginx request

We are thinking about the adding phases handlers.

 >Direct variable access to the Nginx variables (either read only or 
writable depending on the context within which they were created)

this is already in place

 >Array like access to the request arguments (e.g. cookies, post args, 
query string args, etc).  Right now the only version of this that we’ve 
found reliably working in the js_content phase is query string related 
stuff (in the args array)

Feel free to add a feature request here https://github.com/nginx/njs
Although this is not a feature requested often (for some reason).

More information about the nginx mailing list