<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<pre style="color: rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; overflow-wrap: break-word; white-space: pre-wrap;">Hello,
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('<a class="moz-txt-link-freetext" href="http://nginx.org/">http://nginx.org/</a>')
: .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_pass <a class="moz-txt-link-freetext" href="http://127.0.0.1:8081/">http://127.0.0.1:8081/</a>;
: }
:
: 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: <a class="moz-txt-link-freetext" href="http://nginx.org/en/docs/njs/">http://nginx.org/en/docs/njs/</a>
- Presentation: <a class="moz-txt-link-freetext" href="https://youtu.be/Jc_L6UffFOs">https://youtu.be/Jc_L6UffFOs</a>
- Using node modules with njs:
<a class="moz-txt-link-freetext" href="http://nginx.org/en/docs/njs/node_modules.html">http://nginx.org/en/docs/njs/node_modules.html</a>
- Writing njs code using TypeScript definition files:
<a class="moz-txt-link-freetext" href="http://nginx.org/en/docs/njs/typescript.html">http://nginx.org/en/docs/njs/typescript.html</a>
Feel free to try it and give us feedback on:
- Github: <a class="moz-txt-link-freetext" href="https://github.com/nginx/njs/issues">https://github.com/nginx/njs/issues</a>
- Mailing list: <a class="moz-txt-link-freetext" href="http://mailman.nginx.org/mailman/listinfo/nginx-devel">http://mailman.nginx.org/mailman/listinfo/nginx-devel</a>
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.
Core:
*) Bugfix: fixed safe mode bypass in Function constructor.
*) Bugfix: fixed Date.prototype.toISOString() with invalid date
values.</pre>
</body>
</html>