NJS Questions and/or Bugs

Sergey A. Osokin osa at freebsd.org.ru
Thu Aug 12 01:49:24 UTC 2021


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


More information about the nginx mailing list