Want to subscribe to topics you're interested in?
Become a Member

Nginx [nginx-announce] njs-0.5.1

Discussion in 'Nginx and PHP-FPM news & discussions' started by eva2000, Feb 17, 2021.

  1. eva2000

    eva2000 Administrator Staff Member

    May 24, 2014
    Brisbane, Australia
    Local Time:
    8:29 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 on extending the modules functionality.

    Notable new features:
    - ngx.fetch() method implements a generic HTTP client which
    does not depend on subrequests:
    : example.js:
    : function fetch(r) {
    : ngx.fetch('http://nginx.org/')
    : .then(reply => reply.text())
    : .then(body => r.return(200, body))
    : .catch(e => r.return(501, e.message));
    : }

    - js_header_filter directive. The directive allows changing arbitrary
    header fields of a response header.
    : nginx.conf:
    : js_import foo.js;
    : location / {
    : js_header_filter foo.filter;
    : proxy_passhttp://;
    : }
    : foo.js:
    : function filter(r) {
    : var cookies = r.headersOut['Set-Cookie'];
    : var len = r.args.len ? Number(r.args.len) : 0;
    : r.headersOut['Set-Cookie'] = cookies.filter(v=>v.length > len);
    : }
    : export default {filter};

    You can learn more about njs:

    - Overview and introduction:http://nginx.org/en/docs/njs/
    - Presentation:https://youtu.be/Jc_L6UffFOs
    - 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.1 16 Feb 2021

    nginx modules:

    *) Feature: introduced ngx.fetch() method implementing Fetch API.
    The following init options are supported:
    body, headers, buffer_size (nginx specific),
    max_response_body_size (nginx specific), method.

    The following properties and methods of Response object are
    implemented: arrayBuffer(), bodyUsed, json(), headers, ok,
    redirect, status, statusText, text(), type, url.

    The following properties and methods of Header object are
    implemented: get(), getAll(), has().

    Notable limitations: only the http:// scheme is supported,
    redirects are not handled.

    In collaboration with 洪志道 (Hong Zhi Dao).

    *) Feature: added the "js_header_filter" directive.

    *) Bugfix: fixed processing buffered data in body filter
    in stream module.


    *) Bugfix: fixed safe mode bypass in Function constructor.

    *) Bugfix: fixed Date.prototype.toISOString() with invalid date

    nginx-announce mailing list

    Continue reading...