Lance Dockins
August 11, 2021 10:06PM
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.

https://share.wordkeeper.com/AFXzvfi2kO1x024Mc9sm

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@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@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

NJS Questions and/or Bugs

Lance Dockins August 11, 2021 08:44PM

Re: NJS Questions and/or Bugs

Sergey A. Osokin August 11, 2021 09:52PM

Re: NJS Questions and/or Bugs

Lance Dockins August 11, 2021 10:06PM

Re: NJS Questions and/or Bugs

Sergey A. Osokin August 11, 2021 10:22PM

Re: NJS Questions and/or Bugs

Lance Dockins August 11, 2021 10:32PM

Re: NJS Questions and/or Bugs

Lance Dockins August 11, 2021 10:40PM

Re: NJS Questions and/or Bugs

Sergey A. Osokin August 11, 2021 10:44PM

Re: NJS Questions and/or Bugs

Lance Dockins August 11, 2021 10:50PM

Re: NJS Questions and/or Bugs

Sergey A. Osokin August 11, 2021 10:58PM

Re: NJS Questions and/or Bugs

Lance Dockins August 11, 2021 11:02PM

Re: NJS Questions and/or Bugs

Lance Dockins August 11, 2021 11:46PM

Re: NJS Questions and/or Bugs

Lance Dockins August 11, 2021 11:52PM

Re: NJS Questions and/or Bugs

Sergey A. Osokin August 11, 2021 10:42PM

Re: NJS Questions and/or Bugs

Dmitry Volyntsev August 12, 2021 02:16AM

Re: NJS Questions and/or Bugs

Lance Dockins August 12, 2021 08:40AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 283
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready