Welcome! Log In Create A New Profile

Advanced

[nginx-announce] njs-0.5.0

Posted by Dmitry Volyntsev 
Dmitry Volyntsev
[nginx-announce] njs-0.5.0
December 02, 2020 05:56AM
Hello,

I'm glad to announce a new release of NGINX JavaScript module (njs).

This release focuses mostly on adding Buffer support in nginx modules.

Buffer is a better alternative to string when working with arbitrary data
and especially with binary protocols, because JavaScript strings operate
on characters, not bytes. A character may take up to 4 bytes in UTF-8.
The new Buffer properties are not designed to replace the string ones,
but to be a better alternative for binary use cases.

Notable new features:
- r.rawVariables (nginx variables as a Buffer):
: function is_local(r) {
:    return r.rawVariables.binary_remote_addr
:           .equals(Buffer.from([127,0,0,1]));
: }

- r.requestBuffer (request body as a Buffer):
For a request with the following request body:
    '{"a":{"b":"BAR"}}'
: function get_slice_of_req_body(r) {
:     var body = r.requestBuffer;
:     var view = new DataView(body.buffer, 5, 11);
:     r.return(200, view);
: }
The response body will be:
    '{"b":"BAR"}'

- s.on() events now support new callbacks which receive
data chuck as Buffer, this is especially useful for
binary protocols.

You can learn more about njs:

- Overview and introduction: http://nginx.org/en/docs/njs/
- Using Babel to transpile JS code >= ES6 for njs
https://github.com/jirutka/babel-preset-njs
- Using node modules with njs:
http://nginx.org/en/docs/njs/node_modules.html
- Writing njs code using TypeScript definition files:
   http://nginx.org/en/docs/njs/typescript.html

Feel free to try it and give us feedback on:

- Github: https://github.com/nginx/njs/issues
- Mailing list: http://mailman.nginx.org/mailman/listinfo/nginx-devel


Changes with njs 0.5.0                                         01 Dec 2020

    nginx modules:

    *) Feature: introduced global "ngx" object.
       The following methods were added:
         ngx.log(level, msg)

       The following properties were added:
         ngx.INFO,
         ngx.WARN,
         ngx.ERR.

    *) Feature: added support for Buffer object where string
       is expected.

    *) Feature: added Buffer version of existing properties.
       The following properties were added:
       r.requestBuffer (r.requestBody),
       r.responseBuffer (r.responseBody),
       r.rawVariables (r.variables),
       s.rawVariables (s.variables).

       The following events were added in stream module:
       upstream (upload),
       downstream (download).

    *) Improvement: added aliases to existing properties.
       The following properties were added:
       r.requestText (r.requestBody),
       r.responseText (r.responseBody).

    *) Improvement: throwing an exception in r.internalRedirect()
       for a subrequest.

    *) Bugfix: fixed promise r.subrequest() with error_page redirect.

    *) Bugfix: fixed promise events handling.

    Core:

    *) Feature: added TypeScript definitions for builtin
       modules.
       Thanks to Jakub Jirutka.

    *) Feature: tracking unhandled promise rejection.

    *) Feature: added initial iterator support.
       Thanks to Artem S. Povalyukhin.

    *) Improvement: TypeScript definitions are refactored.
       Thanks to Jakub Jirutka.

    *) Improvement: added forgotten support for
       Object.prototype.valueOf() in Buffer.from().

    *) Bugfix: fixed heap-use-after-free in JSON.parse().

    *) Bugfix: fixed heap-use-after-free in JSON.stringify().

    *) Bugfix: fixed JSON.stringify() for arrays resizable via
       getters.

    *) Bugfix: fixed heap-buffer-overflow for
       RegExp.prototype[Symbol.replace].

    *) Bugfix: fixed returned value for Buffer.prototype.write*
       functions.

    *) Bugfix: fixed querystring.stringify().
       Thanks to Artem S. Povalyukhin.

    *) Bugfix: fixed the catch handler for
       Promise.prototype.finally().

    *) Bugfix: fixed querystring.parse().

_______________________________________________
nginx-announce mailing list
nginx-announce@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-announce
Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 122
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready