Welcome! Log In Create A New Profile


[nginx-announce] njs-0.5.1

Posted by Dmitry Volyntsev 
Dmitry Volyntsev
[nginx-announce] njs-0.5.1
February 16, 2021 01:10PM

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
Sorry, you do not have permission to post/reply in this forum.

Online Users

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