NJS Questions and/or Bugs

Lance Dockins lance at wordkeeper.com
Thu Aug 12 12:38:25 UTC 2021


Thank you Dmitry.  This helps a ton. I will note that the post key/value pair solution only works for URL encoded post values.  If the enctype is set to multipart/form-data, you get get the data without writing your own data parser.  I already wrote one for URL encoded types and was working on one for multipart form data at the time that I wrote this.  Parsing the data with JS is just not the most elegant solution - particularly since some sort of parsing is going on already.  Maybe I am also just spoiled from using fastcgi to PHP where all of that is pre-parsed.   But it seems like a fairly straightforward request data access feature.  I guess I will just have to make due for now.


--
Lance Dockins
On Aug 12, 2021, 1:14 AM -0500, Dmitry Volyntsev <xeioex at nginx.com>, wrote:
> 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().
> http://nginx.org/en/docs/njs/reference.html#njs
>
> > 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).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20210812/1ab00208/attachment.htm>


More information about the nginx mailing list