NJS Questions and/or Bugs

Lance Dockins lance at wordkeeper.com
Thu Aug 12 02:05:32 UTC 2021

Hi Sergey,

Thank you.  Perhaps something is going wrong with the implementation of r.args that we’re using.  I’m just getting an empty JS object for POST vars.  Args only seems to work for query string vars for me.

Here’s the key config info.

In the location block for the route that I’m testing:

add_header Content-Type text/plain;
js_content dbadmin.access;

The dbadmin.access function just has this at the top of the function right now:
r.return(200, JSON.stringify(r.args));

And here is a screenshot of a POST to the location route that I’m using.  Assuming that the POST vars were organized into a JSON object, I would assume an output in JSON in key/value pairs.  But what I’m getting is an empty object.


I’m using the latest version of NJS 0.6.1 and the latest version of Nginx 1.21.1.  Is this an indication that there is a bug somewhere in NJS or does this seem more like I’m misunderstanding or misconfguring things?

As I mentioned, I can get the post args into an array by implementing my own JS functions for parsing the POST body via r.requestText and something similar for parsing/processing cookies.  It just seemed like this should be working better - in regards to the POST especially.

Lance Dockins
On Aug 11, 2021, 8:50 PM -0500, Sergey A. Osokin <osa at freebsd.org.ru>, wrote:
> Hi Lance,
> hope you're doing well.
> On Wed, Aug 11, 2021 at 07:43:12PM -0500, Lance Dockins wrote:
> > We’ve been experimenting with NJS in its current form (as compared
> > with the more established LuaJIT integration provided by OpenResty)
> > and it’s surfaced a series of questions about objects and features
> > in NJS that the documentation, examples, recordings, and 3rd party
> > examples don’t seem to answer very well.  I’m not sure if those
> > should be asked here or in another division of Nginx but I wanted
> > to lay them out.
> >
> > Request Data
> >
> > • 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?
> It's already implemented, here's an example of code:
> var jObj = JSON.stringify(r.args);
> > • Is there already an NJS object or are there plans for an object
> > that parses out the cookies into key/value pairs of a JSON object?
> Incoming headers of a request are represented in r.headersIn read-only
> object, so it's possible to implement some additional logic, like the
> following one:
> for (var h in r.headersIn) {
> // where:
> // h is the header's name of a request
> // r.headersIn[h] is the header's value
> }
> Hope that helps.
> --
> Sergey Osokin
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20210811/fc2234e1/attachment-0001.htm>

More information about the nginx mailing list