Learn about Centmin Mod LEMP Stack today
Become a Member

Nginx [nginx-announce] njs-0.5.0

Discussion in 'Nginx and PHP-FPM news & discussions' started by eva2000, Dec 2, 2020.

  1. eva2000

    eva2000 Administrator Staff Member

    May 24, 2014
    Brisbane, Australia
    Local Time:
    10:00 PM
    Nginx 1.19.x
    MariaDB 5.5/10.x

    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:
    : 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:

    - 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
    - Using node modules with njs:
    - Writing njs code using TypeScript definition files:

    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:

    *) 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.


    *) Feature: added TypeScript definitions for builtin
    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

    *) Bugfix: fixed heap-buffer-overflow for

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

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

    *) Bugfix: fixed the catch handler for

    *) Bugfix: fixed querystring.parse().

    nginx-announce mailing list

    Continue reading...