Re: Nginx NJS fs.writeFileSync is atomic writing and race condition prevention ?

2018-10-19 Thread Dmitry Volyntsev



On 19.10.2018 06:33, HENG wrote:

Hello:

I am new to Nginx NJS, and I want to write a website with NJS.

I want to write a simple JSON database with NJS fs.writeFileSync ,just 
like Node.js LowDB.


but I have no idea . Does NJS fs.writeFileSync is atomic writing and 
race condition prevention ?


http://hg.nginx.org/njs/file/tip/njs/njs_fs.c#l649

It simply opens the file, makes several write syscalls into it, and 
closes the file.


So, it is not atomic.

Probably we need here something like

https://www.npmjs.com/package/write-file-atomic



If NJS fs.writeFileSync is NOT atomic writing, it can NOT be treate as a 
normal database file write.


Thank you !

--

Heng
-
--


___
nginx-devel mailing list
nginx-de...@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx

Re: Variable scope in javascript module

2018-10-26 Thread Dmitry Volyntsev


Hi Alex,

Can you, please, share your code?

You can also try to play with njs code in the command line interface.

For example:

njs
interactive njs 0.2.3

v. -> the properties and prototype methods of v.
type console.help() for more information

>>function my(){var g = 'init'; console.log(g); (function() {g = 'anon'})(); 
>>console.log(g) }; my()
'init'
'anon'
undefined

CLI, is also available in docker
docker run -i -t nginx:latest /usr/bin/njs



> On 26 Oct 2018, at 09:16, alweiss  wrote:
> 
> Hi team !,
> Regarding the sample here :
> https://www.nginx.com/blog/batching-api-requests-nginx-plus-javascript-module/
> 
> I have an issue trying to use JS module : variable hoisting and global/local
> scope doesn't behave as expected. When i try to reassign the resp variable
> (as you do after declaring it), the value assigned in the done function is
> not brought outside of the done function to the bacthAPI function.
> So if resp is initialised with 0 and reassign as 1 in the done funtion, at
> the end, resp would = 0.
> I had a look to explanation here
> https://www.sitepoint.com/demystifying-javascript-variable-scope-hoisting/
> and seems to behave differently in nginx implementation of JS.
> 
> Would it be some OS settings outside of NGINX preventing this to work as it
> should normally work with javascript ? Any dependency on an OS package ?
> 
> Thanks !
> BR
> Alex
> 
> Posted at Nginx Forum: 
> https://forum.nginx.org/read.php?2,281699,281699#msg-281699
> 
> ___
> nginx mailing list
> nginx@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx

___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx


Re: large request body in njs

2018-10-30 Thread Dmitry Volyntsev


> On 29 Oct 2018, at 23:44, Jonathan Esterhazy  
> wrote:
> 
> Hello!
> 
> I am trying to use njs (ngx_http_js_module) to modify POSTed request data 
> before sending to an upstream api. Using the req.requestBody function works 
> fine for small requests, but for larger ones causes this error:
> 
> [error] 14#14: *18 js exception: Error: request body is in a file
> 
> If I was using the Lua module, I could use ngx.req.get-body_file function to 
> get this data, but there doesn't seem to be any way to do that in njs. Did I 
> miss something? Is there a way to access the data or find out the filename?


Hi Jonathan!

You have two options here:

1) you can increase the client buffers

According to the documentation:
http://nginx.org/en/docs/njs/reference.html#http 


r.requestBody
returns the client request body if it has not been written to a temporary file. 
To ensure that the client request body is in memory, its size should be limited 
by client_max_body_size, and a sufficient buffer size should be set using 
client_body_buffer_size.

2) you can open the file with the client’s request using request_body_file 
variable 
(http://nginx.org/en/docs/http/ngx_http_core_module.html#var_request_body_file)

var fs = require(‘fs’);
var large_body = fs.readFileSync(r.variables.request_body_file)


> 
> ___
> nginx mailing list
> nginx@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx

___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx

njs 0.2.5 release

2018-10-30 Thread Dmitry Volyntsev

Hello,

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

This release proceeds to extend the coverage of ECMAScript 5.1 
specification.


 - arguments object is added. So, it is possible to write
   functions which can take the arbitrary number of arguments
   as well as wrappers for njs built-in functions.

   function concat(sep) {
   var args = Array.prototype.slice.call(arguments, 1);
   return args.join(sep);
   }

   > concat(' ', 'Hello', 'World', '!')
   'Hello World !'


You can learn more about njs:

 - Overview and introduction: http://nginx.org/en/docs/njs/
 - Presentation: https://youtu.be/Jc_L6UffFOs


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.2.5 30 Oct 2018

nginx modules:

*) Bugfix: fixed counting pending events in stream module.

*) Bugfix: fixed s.off() in stream module.

*) Bugfix: fixed processing of data chunks in js_filter in
   stream module.

*) Bugfix: fixed http status and contentType getter in http module.

*) Bugfix: fixed http response and parent getters in http module.

Core:

*) Feature: arguments object support.

*) Feature: non-integer fractions support.

*) Improvement: handling non-array values in
   Array.prototype.slice().

*) Bugfix: fixed Array.prototype.length setter.

*) Bugfix: fixed njs_array_alloc() for length > 2**31.

*) Bugfix: handling int overflow in njs_array_alloc() on 32bit
   archs.

*) Bugfix: fixed code size mismatch error message.

*) Bugfix: fixed delete operator in a loop.

*) Bugfix: fixed Object.getOwnPropertyDescriptor() for complex
   object (inherited from Array and string values).

*) Bugfix: fixed Object.prototype.hasOwnProperty() for non-object
   properties.

*) Bugfix: miscellaneous additional bugs have been fixed.
___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx


Re: Variable scope in javascript module

2018-10-30 Thread Dmitry Volyntsev




On 30.10.2018 19:58, alweiss wrote:

Here is a sample that works with Java but not with njs :

function my() {
 resp = "Start";
 console.log ('Initial resp is ' + resp);

 function done() {
 resp += "AndContinue";
 console.log('In loop resp is ' + resp)
 }

 done();
}
resp = 'empty'
my();
console.log('End Resp is : ' + resp)

With java :

root@linux3:/etc/nginx# js test.js
Initial resp is Start
In loop resp is StartAndContinue
End Resp is : StartAndContinue


With NJS :

root@linux3:/etc/nginx# njs test.js
ReferenceError: "resp" is not defined in 16


Don't know why it doesn't work the same in both runtime.


Currently, njs requires all the variables to be declared.
Adding 'var resp;' at the beginning of the file helps.

docker run -i -t nginx:latest /usr/bin/njs
interactive njs 0.2.4

v. -> the properties and prototype methods of v.
type console.help() for more information

>> var resp; function my() { resp = "Start"; console.log ('Initial resp 
is ' + resp); function done() { resp += "AndContinue"; console.log('In 
loop resp is ' + resp)}; done()}; resp = 'empty'; my(); console.log('End 
Resp is : ' + resp)

'Initial resp is Start'
'In loop resp is StartAndContinue'
'End Resp is : StartAndContinue'
undefined
>>







Thanks

Posted at Nginx Forum: 
https://forum.nginx.org/read.php?2,281699,281747#msg-281747

___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx


___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx


Re: njs and subrequests

2018-11-19 Thread Dmitry Volyntsev



Hi Antoine,

>Is there any plan to have subrequest from ngx_http_js_module support
> external URLs ?

Nothing prevents you from making subrequests to external URLs.

https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass
https://nginx.org/en/docs/http/ngx_http_core_module.html#resolver

>The address can be specified as a domain name or IP address
..
>In this case, if an address is specified as a domain name, the name is 
searched among the described server groups, and, if not found, is 
determined using a resolver.


You still need a location to make a proxy_pass for you (what you already 
have).


As Valentine said, there is nothing special in ngx_http_js_module about 
subrequests. The module simply uses internal NGINX API for subrequests 
(http://hg.nginx.org/njs/file/tip/nginx/ngx_http_js_module.c#l2099).


You, can find a more complex example of using njs subrequests here: 
https://github.com/nginxinc/nginx-openid-connect


___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx


njs-0.2.6

2018-11-27 Thread Dmitry Volyntsev

Hello,

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

This release proceeds to extend the coverage of ECMAScript 5.1 
specification.


 - Added initial support for extending the existing prototypes. So,
 generic functions can be added to extend functionality of built-in
 types.

  : > String.prototype.myUpper = function() {return this.toUpperCase()}
  :   [Function]
  : > 'abc'.myUpper()
  :   'ABC'

You can learn more about njs:

 - Overview and introduction: http://nginx.org/en/docs/njs/
 - Presentation: https://youtu.be/Jc_L6UffFOs

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.2.6 27 Nov 2018

Core:

*) Feature: making built-in prototypes mutable.

*) Feature: making global object mutable.

*) Feature: console.time() and console.timeEnd() methods.

*) Feature: allowing variables and functions to be redeclared.

*) Feature: extending Object.defineProperty() spec conformance.

*) Feature: introduced quiet mode for CLI to handle simple
   expressions from stdin (echo "2**3" | njs -q -> 8).

*) Feature: introduced compact form of backtraces to handle stack
   overflows.

*) Improvement: improved wording for various exceptions.

*) Bugfix: fixed closure values handling.

*) Bugfix: fixed equality operator for various value types.

*) Bugfix: fixed handling of "this" keyword in various scopes.

*) Bugfix: fixed handling non-object values in Object.keys().

*) Bugfix: fixed parsing of throw statement inside if statement.

*) Bugfix: fixed parsing of newline after throw statement.

*) Bugfix: fixed parsing of statements in if statement without
   newline.

*) Bugfix: fixed size uint32_t overflow in njs_array_expand().

*) Bugfix: fixed typeof operator for object_value type.

*) Bugfix: miscellaneous additional bugs have been fixed.
___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx


Re: Nginscript

2018-11-28 Thread Dmitry Volyntsev




On 28.11.2018 3:21, chadhasumit13 wrote:

Hi, I intend to generate a unique id (by making use of npm uuid ) and make
an external call to an HTTP end-point, whenever a new call is received by
NGINX.

Is it possible to use nginscript for this purpose?

If yes, could you please route me to a good example by means of which I can
fulfil the above-mentioned requirement.


Hi chadhasumit13,

Could you please clarify more what are you trying to do?


1) In general, if you simply need a unique id (not necessarily uuid), it 
is better and easier to use request_id variable 
(https://nginx.org/en/docs/http/ngx_http_core_module.html#var_request_id)


you can access $request_id variable by

r.variables.request_id


external call to an HTTP end-point


2) You can use subrequest method 
(http://nginx.org/en/docs/njs/reference.html#http).


You can find some examples with it here:
https://github.com/xeioex/njs-examples#subrequests-join

___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx


njs-0.2.7

2018-12-25 Thread Dmitry Volyntsev
Hello,

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

This release proceeds to extend the coverage of ECMAScript specifications.

- Added support for ES6 rest parameters syntax.
  Thanks to Alexander Pyshchev.

 : > var add = function(prev, curr) { return prev + curr }
 :   undefined
 : > function sum(...args) { return args.reduce(add) }
 :   undefined
 : > sum(1,2,3)
 :   6
 : > sum(1,2,3,4)
 :   10

- Added ES8 Object.values() and Object.entries() methods.

You can learn more about njs:

- Overview and introduction: http://nginx.org/en/docs/njs/
- Presentation: https://youtu.be/Jc_L6UffFOs

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.2.7   25 Dec 2018

Core:

*) Feature: rest parameters syntax (destructuring is not supported).
   Thanks to Alexander Pyshchev.

*) Feature: added Object.entries() method.

*) Feature: added Object.values() method.

*) Improvement: code generator refactored and simplified.

*) Bugfix: fixed automatic semicolon insertion.

*) Bugfix: fixed assignment expression from compound assignment.

*) Bugfix: fixed comparison of Byte and UTF8 strings.

*) Bugfix: fixed type of iteration variable in for-in with array 
   values.

*) Bugfix: fixed building on paltforms without librt.

*) Bugfix: miscellaneous additional bugs have been fixed.

___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx

njs-0.2.8

2019-02-26 Thread Dmitry Volyntsev

Hello,

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

This release proceeds to extend the coverage of ECMAScript 
specifications and modules functionality.


- Added support for setting nginx variables.

- Added support for delete operation in r.headersOut.

- Properties of HTTP request deprecated in 0.2.2 were removed.

- Added labels support.

- Added support for shorthand property names for Object literals.
: > var a = 1, b = 2
: undefined
: > ({a, b})
: {
: a: 1,
: b: 2
: }

You can learn more about njs:

- Overview and introduction: http://nginx.org/en/docs/njs/
- Presentation: https://youtu.be/Jc_L6UffFOs

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.2.826 Feb 2019

nginx modules:

*) Change: properties of HTTP request deprecated in 0.2.2 are
   removed.

*) Feature: added support for delete operation in r.headersOut.

*) Feature: added support for setting nginx variables.

*) Bugfix: fixed r.subrequest() for empty body value.

*) Improvement: setting special response headers in r.headersOut.

Core:

*) Feature: added labels support.

*) Feature: added setImmediate() method.

*) Feature: added support for shorthand property names for Object
   literals.

*) Bugfix: fixed Function.prototype.bind().

*) Bugfix: fixed parsing of string literals containing newline
   characters.

*) Bugfix: fixed line number in reporting variable reference errors.

*) Bugfix: fixed creation of long UTF8 strings.

*) Bugfix: fixed String.prototype.split() for unicode strings.

*) Bugfix: fixed heap-buffer-overflow in String.prototype.split().

*) Bugfix: fixed Array.prototype.fill().
   Thanks to Artem S. Povalyukhin.

*) Improvement: code related to function invocation is refactored.
   Thanks to 洪志道 (Hong Zhi Dao).

*) Improvement: code related to variables is refactored.
   Thanks to 洪志道 (Hong Zhi Dao).

*) Improvement: parser is refactored.
   Thanks to 洪志道 (Hong Zhi Dao).

*) Improvement: reporting filenames in exceptions.
___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx

Re: njs question

2019-02-26 Thread Dmitry Volyntsev


On 26.02.2019 9:24, ?? wrote:

hello!
Hello! I would like to ask some questions about the development of NJS.


Hi ??


First: when will NJS improve the ES6 standard?


According to http://nginx.org/en/docs/njs/index.html we plan to extend 
coverage of ES6 and later specifications. This is ongoing process. You 
can see what is currently under development here: 
https://github.com/nginx/njs



Second: can NJS be made into nodejs similar to nodejs? 
Can import third-party js files through "require" script.


No, require() in njs works only with built-in modules.
But we plan to support loading external files using ES6 import statements.



Thus realize the transformation from js to AST;
Third: we want to add js to AST and AST to js functions in NJS. Do you 
have any good plans and Suggestions?	


I am sorry, I didn't get it. Can you elaborate?



Thank you very much!

___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx


___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx

njs-0.3.0

2019-03-26 Thread Dmitry Volyntsev

Hello,

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

This release proceeds to extend the coverage of ECMAScript
specifications and modules functionality.

- Added initial ES6 modules support:
: // module.js
: function sum(a, b) {return a + b}
: export default {sum};
: // shell
: > import m from 'module.js'
: undefined
: > m.sum(3, 4)
: 7

You can learn more about njs:

- Overview and introduction: http://nginx.org/en/docs/njs/
- Presentation: https://youtu.be/Jc_L6UffFOs

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.3.0   26 Mar 2019

nginx modules:

*) Feature: added js_path directive.

*) Change: returning undefined value instead of empty strings
   for absent properties in the following objects: r.args,
   r.headersIn, r.headersOut, r.variables, s.variables.

*) Change: returning undefined value instead of throwing an
   exception for r.requestBody when request body is unavailable.

*) Bugfix: fixed crash while iterating over r.args when a value is
   absent in a key-value pair.

Core:

*) Feature: added initial ES6 modules support. Default import and
   default export statements are supported.
   Thanks to 洪志道 (Hong Zhi Dao).

*) Feature: added Object.prototype.propertyIsEnumerable().

*) Feature: reporting file name and function name in disassembler
   output.

*) Bugfix: fixed function redeclarations in interactive shell.
   Thanks to 洪志道 (Hong Zhi Dao).

*) Bugfix: fixed RegExp literals parsing.

*) Bugfix: fixed setting length of UTF8 string in fs.readFileSync().

*) Bugfix: fixed nxt_file_dirname() for paths with no dir component.
___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx

njs-0.3.1

2019-04-16 Thread Dmitry Volyntsev

Hello,

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

This release proceeds to extend the coverage of ECMAScript
specifications and modules functionality.

- Added ES6 arrow functions support:
: > var materials = ['Hydrogen', 'Helium', 'Lithium']
: undefined
: > materials.map(material => material.length)
: [
:  8,
:  6,
:  7
: ]

: r.subrequest('/foo', rep => r.return(rep.status, rep.responseBody))

You can learn more about njs:

- Overview and introduction: http://nginx.org/en/docs/njs/
- Presentation: https://youtu.be/Jc_L6UffFOs

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.3.1  16 Apr 2019

Core:

*) Feature: added arrow functions support.
   Thanks to 洪志道 (Hong Zhi Dao) and Artem S. Povalyukhin.

*) Feature: added Object.getOwnPropertyNames().
   Thanks to Artem S. Povalyukhin.

*) Feature: added Object.getOwnPropertyDescriptors().
   Thanks to Artem S. Povalyukhin.

*) Feature: making __proto__ accessor descriptor of Object instances
   mutable.

*) Feature: added shebang support in CLI.

*) Feature: added support for module mode execution in CLI. In module
   mode global this is unavailable.

*) Bugfix: fixed editline detection.

*) Bugfix: fixed Function.prototype.bind().
   Thanks to 洪志道 (Hong Zhi Dao).

*) Bugfix: fixed checking of duplication of parameters for functions.
   Thanks to 洪志道 (Hong Zhi Dao).

*) Bugfix: fixed function declaration with the same name as a variable.
   Thanks to 洪志道 (Hong Zhi Dao).

*) Improvement: code related to parsing of objects, variables and
   functions is refactored.
   Thanks to 洪志道 (Hong Zhi Dao).

*) Improvement: console.log() improved for outputting large values.

*) Improvement: console.log() improved for outputting strings in a
   compliant way (without escaping and quotes).

*) Improvement: using ES6 version of ToInt32(), ToUint32(), ToLength().
___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx

njs-0.3.2

2019-05-21 Thread Dmitry Volyntsev


Hello,

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

This release mostly focuses on stability issues in njs core after regular
fuzzing tests were introduced.

Notable new features:
- Added ES6 template literals support:
: > var a = "Template", b = "literals"
: undefined
: > `${a} ${b.toUpperCase()}!`
: 'Template LITERALS!'

- Added ES9 RegExp "groups" object support:
: > /(?(?no)?(?yes)?)/.exec('yes').groups
{
 no: undefined,
 r: 'yes',
 yes: 'yes'
}

You can learn more about njs:

- Overview and introduction: http://nginx.org/en/docs/njs/
- Presentation: https://youtu.be/Jc_L6UffFOs

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.3.2  21 May 2019

Core:

*) Feature: added support for template literals.
   Thanks to 洪志道 (Hong Zhi Dao) and Artem S. Povalyukhin.

*) Feature: executing command from command line arguments.

*) Feature: added support for RegExp "groups" object (ES9).

*) Feature: added block scoped function definitions support.

*) Feature: added support for building with GNU Readline library.

*) Feature: made configurable "length", "name", and most of built-in
   methods.

*) Feature: made all constructor properties configurable.

*) Bugfix: fixed Regexp.prototype.exec() for Unicode-only regexps.

*) Bugfix: fixed njs_vm_value_dump() for empty string values.

*) Bugfix: fixed RegExp constructor for regexp value arguments.

*) Bugfix: fixed walking over prototypes chain during iteration
   over an object.

*) Bugfix: fixed overflow in Array.prototype.concat().

*) Bugfix: fixed length calculation for UTF-8 string with escape
   characters.

*) Bugfix: fixed parsing surrogate pair presents as UTF-16 escape
   sequences.

*) Bugfix: fixed processing asterisk quantifier for
   String.prototype.match().

*) Bugfix: fixed Date() constructor with one argument.

*) Bugfix: fixed arrays expansion.

*) Bugfix: fixed heap-buffer-overflow in String.prototype.replace().

*) Bugfix: fixed heap-buffer-overflow in
   String.prototype.lastIndexOf().

*) Bugfix: fixed regexp literals parsing with escaped backslash and
   backslash in square brackets.

*) Bugfix: fixed regexp literals with lone closing brackets.

*) Bugfix: fixed uninitialized-memory-access in
   Object.defineProperties().

*) Bugfix: fixed processing "*" quantifier for
   String.prototype.replace().

*) Bugfix: fixed Array.prototype.slice() for UTF8-invalid byte
   strings.

*) Bugfix: fixed String.prototype.split() for UTF8-invalid byte
   strings.

*) Bugfix: fixed handling of empty block statements.
___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx

Re: njs: how to define a global variable

2019-06-03 Thread Dmitry Volyntsev




On 29.05.2019 20:02, guy1976 wrote:

hi

is it possible to define a global variable that will be persist  for
different requests?



Hi Guy,

Currently it is not possible as all njs VM are short-lived (a VM per 
request).
If performance is not a serious issue you can use FS API (see 
http://nginx.org/en/docs/njs/reference.html#njs_api_fs)





thank you,
Guy.

Posted at Nginx Forum: 
https://forum.nginx.org/read.php?2,284350,284350#msg-284350

___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx


___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx


njs-0.3.3

2019-06-25 Thread Dmitry Volyntsev
Hello,

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

This release mostly focuses on stability issues in njs core after regular
fuzzing tests were introduced.

Notable new features:
- Added ES5 property getter/setter runtime support:
: > var o = {a:2};
: undefined
: > Object.defineProperty(o, ‘b’, {get:function(){return 2*this.a}}); o.b
: 4

- Added global “process” variable:
: > process.pid

:  > process.env.HOME


You can learn more about njs:

- Overview and introduction: http://nginx.org/en/docs/njs/
- Presentation: https://youtu.be/Jc_L6UffFOs

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.3.3   25 Jun 2019

nginx modules:

*) Improvement: getting of special response headers in headersOut.

*) Improvement: working with unknown methods in r.subrequest().

*) Improvement: added support for null as a second argument
   of r.subrequest().

*) Bugfix: fixed processing empty output chain in stream body filter.

Core:
*) Feature: added runtime support for property getter/setter.
   Thanks to 洪志道 (Hong Zhi Dao) and Artem S. Povalyukhin.

*) Feature: added “process” global object.

*) Feature: writable most of built-in properties and methods.

*) Feature: added generic implementation of Array.prototype.fill().

*) Bugfix: fixed integer-overflow in String.prototype.concat().

*) Bugfix: fixed setting of object properties.

*) Bugfix: fixed Array.prototype.toString().

*) Bugfix: fixed Date.prototype.toJSON().

*) Bugfix: fixed overwriting “constructor” property of built-in
   prototypes.

*) Bugfix: fixed processing of invalid surrogate pairs in strings.

*) Bugfix: fixed processing of invalid surrogate pairs in JSON
   strings.

*) Bugfix: fixed heap-buffer-overflow in toUpperCase() and
   toLowerCase().

*) Bugfix: fixed escaping lone closing square brackets in RegExp()
   constructor.

*) Bugfix: fixed String.prototype.toBytes() for ASCII strings.

*) Bugfix: fixed handling zero byte characters inside RegExp
   pattern strings.

*) Bugfix: fixed String.prototype.toBytes() for ASCII strings.

*) Bugfix: fixed truth value of JSON numbers in JSON.parse().

*) Bugfix: fixed use-of-uninitialized-value in 
   njs_string_replace_join().

*) Bugfix: fixed parseInt(‘-0’).
   Thanks to Artem S. Povalyukhin.___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx

njs-0.3.4

2019-08-13 Thread Dmitry Volyntsev


Hello,

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

This release proceeds to extend the coverage of ECMAScript
specifications. Apart from specs conformance fuzzing under
Memory-Sanitizer is introduced which allowed to catch new types of bugs.

Notable new features:
- Shorthand method names (ES2015):
: > ({foo(){return 123}}).foo() // ({foo:function(){return 123}})
: 123

- Computed property names (ES2015)
: > ({['b' + 'ar']:123}).bar
: 123

- added getter/setter literal support:
: > ({get foo(){return 123}}).foo
: 123
: > ({get ['f' + 'oo'](){return 123}}).foo
: 123

You can learn more about njs:

- Overview and introduction: http://nginx.org/en/docs/njs/
- Presentation: https://youtu.be/Jc_L6UffFOs

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.3.4  13 Aug 2019

Core:
*) Feature: added Object shorthand methods and computed property
   names. Thanks to 洪志道 (Hong Zhi Dao) and Artem S. Povalyukhin.

*) Feature: added getter/setter literal support.
   Thanks to 洪志道 (Hong Zhi Dao) and Artem S. Povalyukhin.

*) Feature: added fs.renameSync().

*) Feature: added String.prototype.trimStart() and
   String.prototype.trimEnd().

*) Improvement: added memory-sanitizer support.

*) Improvement: Unicode case tables updated to version 12.1.

*) Improvement: added UTF8 validation for string literals.

*) Bugfix: fixed reading files with zero size in fs.readFileSync().

*) Bugfix: extended the list of space separators in
   String.prototype.trim().

*) Bugfix: fixed using of uninitialized value in
   String.prototype.padStart().

*) Bugfix: fixed String.prototype.replace() for '$0' and '$&'
   replacement string.

*) Bugfix: fixed String.prototype.replace() for byte strings with
   regex argument.

*) Bugfix: fixed global match in String.prototype.replace()
   with regexp argument.

*) Bugfix: fixed Array.prototype.slice() for primitive types.

*) Bugfix: fixed heap-buffer-overflow while importing module.

*) Bugfix: fixed UTF-8 character escaping.

*) Bugfix: fixed Object.values() and Object.entries() for shared
   objects.

*) Bugfix: fixed uninitialized memory access in
   String.prototype.match().

*) Bugfix: fixed String.prototype.match() for byte strings with
   regex argument.

*) Bugfix: fixed Array.prototype.lastIndexOf() with undefined
   arguments.

*) Bugfix: fixed String.prototype.substring() with empty substring.

*) Bugfix: fixed invalid memory access in
   String.prototype.substring().

*) Bugfix: fixed String.fromCharCode() for code points > 65535
   and NaN.

*) Bugfix: fixed String.prototype.toLowerCase() and
   String.prototype.toUpperCase().

*) Bugfix: fixed Error() constructor with no arguments.

*) Bugfix: fixed "in" operator for values with accessor descriptors.

*) Bugfix: fixed Object.defineProperty() for non-boolean descriptor
   props.

*) Bugfix: fixed Error.prototype.toString() with UTF8 string
   properties.

*) Bugfix: fixed Error.prototype.toString() with non-string values
   for "name" and "message".
___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx

njs-0.3.5

2019-08-15 Thread Dmitry Volyntsev
This is a bugfix release that eliminates heap-use-after-free
introduced in 0.3.4.

What installations are affected:

- Importing built-in modules (crypto, fs) using require().

You can learn more about njs:

- Overview and introduction: http://nginx.org/en/docs/njs/ 

- Presentation: https://youtu.be/Jc_L6UffFOs 

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.3.5 15 Aug 2019
   Core:
   *) Bugfix: fixed module importing using require(). The bug was
  introduced in 0.3.4.

   *) Bugfix: fixed [[SetPrototypeOf]].___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx

njs-0.3.6

2019-10-22 Thread Dmitry Volyntsev

Hello,

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

This release proceeds to extend the coverage of ECMAScript
specifications.

Notable new features:

- Function constructor:
: > var sum = new Function('a, b', 'return a + b');
: undefined
: > sum(2, 3)
: 5

You can learn more about njs:

- Overview and introduction: http://nginx.org/en/docs/njs/
- Presentation: https://youtu.be/Jc_L6UffFOs

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.3.6  22 Oct 2019

nginx modules:

*) Improvement: getting special headers from r.headersIn.

Core:

*) Feature: added new Function() support.

*) Feature: added Number.prototype.toFixed().

*) Feature: added Number.prototype.toPrecision().

*) Feature: added Number.prototype.toExponential().

*) Improvement: making "prototype" property of function
   instances writable.

*) Improvement: limiting recursion depth while compiling.

*) Improvement: moving global functions to the global object.

*) Bugfix: fixed prototype mutation for object literals.

*) Bugfix: fixed heap-buffer-overflow while parsing regexp literals.

*) Bugfix: fixed integer-overflow while parsing exponent
   of number literals.

*) Bugfix: fixed parseFloat().

*) Bugfix: fixed Array.prototype functions according to the 
specification.
   The following functions were fixed: every, includes, indexOf, 
filter,

   find, findIndex, forEach, lastIndexOf, map, pop, push, reduce,
   reduceRight, shift, some, unshift.

*) Bugfix: fixed handing of accessor descriptors in Object.freeze().

*) Bugfix: fixed String.prototype.replace() when first argument
   is not a string.

*) Bugfix: fixed stack-use-after-scope in Array.prototype.map().

*) Bugfix: Date.prototype.toUTCString() format was aligned to ES9.

*) Bugfix: fixed buffer overflow in Number.prototype.toString(radix).

*) Bugfix: fixed Regexp.prototype.test() for regexps with 
backreferences.


*) Bugfix: fixed Array.prototype.map() for objects with nonexistent 
values.


*) Bugfix: fixed Array.prototype.pop() and shift() for sparse objects.

*) Bugfix: fixed Date.UTC() according to the specification.

*) Bugfix: fixed Date() constructor according to the specification.

*) Bugfix: fixed type of Date.prototype.
   Thanks to Artem S. Povalyukhin.

*) Bugfix: fixed Date.prototype.setTime().
   Thanks to Artem S. Povalyukhin.

*) Bugfix: fixed default number of arguments expected by built-in 
functions.


*) Bugfix: fixed "caller" and "arguments" properties of a function 
instance.

   Thanks to Artem S. Povalyukhin.
___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx


njs-0.3.7

2019-11-19 Thread Dmitry Volyntsev

Hello,

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

This release proceeds to extend the coverage of ECMAScript
specifications.

Notable new features:

- Object.assign() method:
: > var obj = { a: 1, b: 2 }
: undefined
: > var copy = Object.assign({}, obj)
: undefined
: > console.log(copy)
: {a:1,b:2}

You can learn more about njs:

- Overview and introduction: http://nginx.org/en/docs/njs/
- Presentation: https://youtu.be/Jc_L6UffFOs

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.3.719 Nov 2019

nginx modules:

*) Improvement: refactored iteration over external objects.

Core:

*) Feature: added Object.assign().

*) Feature: added Array.prototype.copyWithin().

*) Feature: added support for labels in console.time().

*) Change: removed console.help() from CLI.

*) Improvement: moved constructors and top-level objects to
   global object.

*) Improvement: arguments validation for configure script.

*) Improvement: refactored JSON methods.

*) Bugfix: fixed heap-buffer-overflow in njs_array_reverse_iterator()
   function. The following functions were affected:
   Array.prototype.lastIndexOf(), Array.prototype.reduceRight().

*) Bugfix: fixed [[Prototype]] slot of NativeErrors.

*) Bugfix: fixed NativeError.prototype.message properties.

*) Bugfix: added conversion of "this" value to object in
   Array.prototype functions.

*) Bugfix: fixed iterator for Array.prototype.find() and
   Array.prototype.findIndex() functions.

*) Bugfix: fixed Array.prototype.includes() and
   Array.prototype.join() with "undefined" argument.

*) Bugfix: fixed "constructor" property of "Hash" and "Hmac"
   objects.

*) Bugfix: fixed "__proto__" property of getters and setters.

*) Bugfix: fixed "Date" object string formatting.

*) Bugfix: fixed handling of NaN and -0 arguments in Math.min()
   and Math.max().

*) Bugfix: fixed Math.round() according to the specification.

*) Bugfix: reimplemented "bound" functions according to
   the specification.
___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx


njs-0.3.8

2020-01-21 Thread Dmitry Volyntsev

Hello,

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

This release proceeds to extend the coverage of ECMAScript
specifications. This release adds Promise object support and
typed-arrays from ES6.

Notable new features:
- Promise support in r.subrequest():
:   r.subrequest(r, '/auth')
:   .then(reply => JSON.parse(reply.responseBody))
:   .then(response => {
:   if (!response['token']) {
:   throw new Error("token is not available");
:   }
:   return token;
:   })
:  .then(token => {
:  r.subrequest('/backend', `token=${token}`)
:  .then(reply => r.return(reply.status, reply.responseBody));
:  })
:  .catch(_ => r.return(500));

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: 
http://nginx.org/en/docs/njs/node_modules.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.3.8  21 Jan 2020

nginx modules:

*) Feature: added Promise support for r.subrequest(). If callback
   is not provided r.subrequest() returns an ordinary Promise object
   that resolves to subrequest response object.

*) Change: r.parent property handler now returns "undefined"
  instead of throwing exception if parent object is not available.

Core:

*) Feature: added Promise support. Implemented according to
   the specification without: Promise.all(), Promise.allSettled(),
   Promise.race().

*) Feature: added initial Typed-arrays support.
   Thanks to Tiago Natel de Moura.

*) Feature: added ArrayBuffer support.
   Thanks to Tiago Natel de Moura.

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

*) Feature: added externals supopor for JSON.stringify().

*) Feature: added Object.is().
   Thanks to Artem S. Povalyukhin.

*) Feature: added Object.setPrototypeOf().
   Thanks to Artem S. Povalyukhin.

*) Feature: introduced nullish coalescing operator.
   Thanks to Valentin Bartenev.

*) Bugfix: fixed Object.getPrototypeOf() according to the
   specification.

*) Bugfix: fixed Object.prototype.valueOf() according to the
   specification.

*) Bugfix: fixed JSON.stringify() with unprintable values and
   replacer function.

*) Bugfix: fixed operator "in" according to the specification.

*) Bugfix: fixed Object.defineProperties() according to the
   specification.

*) Bugfix: fixed Object.create() according to the specification.
   Thanks to Artem S. Povalyukhin.

*) Bugfix: fixed Number.prototype.toString(radix) when
   fast-math is enabled.

*) Bugfix: fixed RegExp() instance properties.

*) Bugfix: fixed import segfault.
   Thanks to 洪志道 (Hong Zhi Dao).
___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx

njs-0.3.9

2020-03-03 Thread Dmitry Volyntsev

Hello,

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

This release proceeds to extend the coverage of ECMAScript
specifications.

Notable new features:
- Promises API for "fs" module.
: var fs = require('fs').promises;
: fs.readFile('/file/path').then(data => r.return(200, data));

- detached r.subrequest(): Running a subrequest in the log phase
: nginx.conf:
:   ...
:   js_set $js_log js_log;
:   ...
:   log_format subrequest_log "...$js_log";
:   access_log /log/path.log subrequest_log;
:
: nginx.js:
:   function js_log(r) {
:r.subrequest('/_log', {detached:true});
:return '';
:   }

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: 
http://nginx.org/en/docs/njs/node_modules.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.3.9 03 Mar 2020

nginx modules:

*) Feature: added detached mode for r.subrequest(). Responses to
   detached subrequests are ignored. Unlike ordinary subrequests,
   a detached subrequest can be created inside a variable handler.

Core:

*) Feature: added promises API for "fs" module.
   Thanks to Artem S. Povalyukhin.

*) Feature: extended "fs" module. Added access(), symlink(), unlink(),
   realpath() and friends.
   Thanks to Artem S. Povalyukhin.

*) Improvement: introduced memory-efficient ordinary arrays.

*) Improvement: lexer refactoring.

*) Bugfix: fixed matching of native functions in backtraces.

*) Bugfix: fixed callback invocations in "fs" module.
   Thanks to Artem S. Povalyukhin.

*) Bugfix: fixed Object.getOwnPropertySymbols().

*) Bugfix: fixed heap-buffer-overflow in njs_json_append_string().

*) Bugfix: fixed encodeURI() and decodeURI() according to
   the specification.

*) Bugfix: fixed Number.prototype.toPrecision().

*) Bugfix: fixed handling of space argument in JSON.stringify().

*) Bugfix: fixed JSON.stringify() with Number() and String() objects.

*) Bugfix: fixed Unicode Escaping in JSON.stringify() according
   to specification.

*) Bugfix: fixed non-native module importing.
   Thanks to 洪志道 (Hong Zhi Dao).

*) Bugfix: fixed njs.dump() with the Date() instance in a container.
___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx

njs-0.4.0

2020-04-23 Thread Dmitry Volyntsev
Hello,

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

This release focuses on extending http and stream modules.

Notable new features:
- js_import directive.
: nginx.conf:
:   js_import foo.js;
:   js_import lib from path/file.js;
: 
:   location / {
:   js_content foo.bar;
:   }
:
: foo.js:
:   function bar(r) {
:   r.return(200);
:   }
:
:   export default {bar};

- multi-value headers support in r.headersOut:
: foo.js:
:   function content(r) {
:r.headersOut[‘Set-Cookie’] = [
:   ‘foo=111; Max-Age=3600; path=/’,
:   ‘bar=qqq; Max-Age=86400; path=/’
:];
:
:r.return(200);
:   }

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: http://nginx.org/en/docs/njs/node_modules.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.4.0  23 Apr 2020

nginx modules:

*) Feature: added js_import directive.

*) Feature: added support for multi-value headers in r.headersOut.

*) Improvement: iteration over r.headersOut with special headers.

*) Improvement: iteration over r.headersOut with duplicates.

*) Change: r.responseBody property handler now returns “undefined”
   instead of throwing an exception if response body is not available.

Core:

*) Feature: added script arguments support in CLI.

*) Feature: converting externals values to native js objects.

*) Bugfix: fixed NULL-pointer dereference in “__proto__” property
   handler.

*) Bugfix: fixed handling of no-newline at the end of the script.

*) Bugfix: fixed RegExp() constructor with empty pattern and
   non-empty flags.

*) Bugfix: fixed String.prototype.replace() when function
   returns non-string.

*) Bugfix: fixed reading of pseudofiles in “fs”.
___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx

njs-0.4.1

2020-05-19 Thread Dmitry Volyntsev
Hello,

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

This release extends http module.

Notable new features:
- raw headers API:
With the following request headers:
: Host: localhost
: Foo: bar
: foo: bar2
All 'foo' headers can be collected with the syntax:
: r.rawHeadersIn.filter(v=>v[0].toLowerCase() == 'foo').map(v=>v[1]);
the output will be:
: ['bar', 'bar2']

- TypeScript API definition:
: foo.ts:
: /// 
: function content_handler(r: NginxHTTPRequest) 
: {
:r.headersOut['content-type'] = 'text/plain';
:r.return(200, "Hello from TypeScript");
: }
: 
: tsc foo.ts --outFile foo.js
foo.js can be used directly with njs.

You can learn more about njs:

- Overview and introduction: http://nginx.org/en/docs/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.4.1  19 May 2020

*) Feature: added support for multi-value headers in r.headersIn.

*) Feature: introduced raw headers API.

*) Feature: added TypeScript API description.

Core:

*) Bugfix: fixed Array.prototype.slice() for sparse arrays.___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx

njs-0.4.2

2020-07-07 Thread Dmitry Volyntsev

Hello,

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

This release proceeds to extend the coverage of ECMAScript
specification.

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: 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.4.2 07 Jul 2020

Core:

*) Feature: added RegExp.prototype[Symbol.replace].

*) Feature: introduced line level backtrace.

*) Feature: added %TypedArray%.prototype.sort().

*) Feature: extended "fs" module. Added mkdir(), readdir(), rmdir()
   and friends.
   Thanks to Artem S. Povalyukhin.

*) Improvement: parser refactoring.

*) Bugfix: fixed TypedScript API description for HTTP headers.

*) Bugfix: fixed TypedScript API description for NjsByteString type.

*) Bugfix: fixed String.prototype.repeat() according to the
   specification.

*) Bugfix: fixed parsing of flags for regexp literals.

*) Bugfix: fixed index generation for global objects in generator.

*) Bugfix: fixed String.prototype.replace() according to the
   specification.

*) Bugfix: fixed %TypedArray%.prototype.copyWithin() with nonzero
   byte offset.

*) Bugfix: fixed Array.prototype.splice() for sparse arrays.

*) Bugfix: fixed Array.prototype.reverse() for sparse arrays.

*) Bugfix: fixed Array.prototype.sort() for sparse arrays.

___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx

Re: Is there any plan to support WebAssembly?

2020-07-22 Thread Dmitry Volyntsev


On 20.07.2020 06:21, 肖涵 wrote:



  Hi


  WebAssembly provides a new way to extend the module, like envoy
  already supports WebAssembly. we would like to consult nginx's
  attitude towards this


  In addition, We have supported  WebAssembly for Nignx. we can
  load the wasm module as your extension like Lua. Will you
  consider accepting our code as part of open source nginx in the
  future?


Thanks

Han



Hi Han,
We are in  the process of investigation of applicability of WebAssembly 
in nginx.

Please share more details about the ways you use WebAssembly in nginx.

1) do you have publicly available code right now?
2) Do you support any interoperability interfaces like proxy-wasm? 
(https://github.com/proxy-wasm/spec/tree/master/abi-versions/vNEXT)
Or please share the details about your WASM runtime, and the way you 
interact with nginx internals.


>Will you consider accepting our code as part of open source nginx in 
the future?
If it is just a module, feel free to release it. There are multitudes of 
community supported modules for nginx. We rarely accept external large 
patches, because its support requires considerable time and energy.





___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx

njs-0.4.3

2020-08-11 Thread Dmitry Volyntsev

Hello,

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

This release proceeds to extend the coverage of ECMAScript
specifications.

Notable new features:
- querystring module.
: var qs = require('querystring');
:
: function fix_args(args) {
: args = qs.parse(args);
:
: args.t2 = args.t;
: delete args.t;
:
: return qs.stringify(args);
: }
:
: fix_args("t=1&v=%41%42") -> "v=AB&t2=1"

- TextDecoder/TextEncoder.
: >> (new TextDecoder()).decode(new Uint8Array([206,177,206,178]))
: 'αβ'

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: 
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.4.3  11 Aug 2020


    Core:

    *) Feature: added Query String module.

    *) Feature: improved fs.mkdir() to support recursive directory 
creation.

   Thanks to Artem S. Povalyukhin.

    *) Feature: improved fs.rmdir() to support recursive directory removal.
   Thanks to Artem S. Povalyukhin.

    *) Feature: introduced UTF-8 decoder according to WHATWG encoding spec.

    *) Feature: added TextEncoder/TextDecoder implementation.

    *) Bugfix: fixed parsing return statement without semicolon.

    *) Bugfix: fixed njs_number_to_int32() for big-endian platforms.

    *) Bugfix: fixed unit test on big-endian platforms.

    *) Bugfix: fixed regexp-literals parsing with '=' characters.

    *) Bugfix: fixed pre/post increment/decrement in assignment 
operations.

___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx

njs-0.4.4

2020-09-29 Thread Dmitry Volyntsev

Hello,

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

This release proceeds to extend the coverage of ECMAScript
specifications.

Notable new features:
- Buffer object.
: >> var buf = Buffer.from([0x80,206,177,206,178])
: undefined
: >> buf.slice(1).toString()
: 'αβ'
: >> buf.toString('base64')
: 'gM6xzrI='

- DataView object.
: >> (new DataView(buf.buffer)).getUint16()
: 32974

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: 
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.4.4 
29 Sep 2020


    nginx modules:

    *) Bugfix: fixed location merge.

    *) Bugfix: fixed r.httpVersion for HTTP/2.

    Core:

    *) Feature: added support for numeric separators (ES12).

    *) Feature: added remaining methods for %TypedArray%.prototype.
   The following methods were added: every(), filter(), find(),
   findIndex(), forEach(), includes(), indexOf(), lastIndexOf(),
   map(), reduce(), reduceRight(), reverse(), some().

    *) Feature: added %TypedArray% remaining methods.
   The following methods were added: from(), of().

    *) Feature: added DataView object.

    *) Feature: added Buffer object implementation.

    *) Feature: added support for ArrayBuffer in
   TextDecoder.prototype.decode().

    *) Feature: added support for Buffer object in "crypto" methods.

    *) Feature: added support for Buffer object in "fs" methods.

    *) Change: Hash.prototype.digest() and Hmac.prototype.digest()
   now return a Buffer instance instead of a byte string when
   encoding is not provided.

    *) Change: fs.readFile() and friends now return a Buffer instance
   instead of a byte string when encoding is not provided.

    *) Bugfix: fixed function "prototype" property handler while
   setting.

    *) Bugfix: fixed function "constructor" property handler while
   setting.

    *) Bugfix: fixed String.prototype.indexOf() for byte strings.

    *) Bugfix: fixed RegExpBuiltinExec() with a global flag and
   byte strings.

    *) Bugfix: fixed RegExp.prototype[Symbol.replace] when the
   replacement value is a function.

    *) Bugfix: fixed TextDecoder.prototype.decode() with non-zero
   TypedArray offset.

___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx

njs-0.5.0

2020-12-02 Thread Dmitry Volyntsev

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 mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx

Re: Response headers adding/filtering during proxy with njs

2021-01-19 Thread Dmitry Volyntsev


On 19.01.2021 18:44, Grzegorz Kulewski wrote:

Hello,

Is it possible to (at least) add (or better also) filter response headers (like 
for example setting or modifying or deleting cookies, of course without harming 
other cookies set by the upstream) dynamically from njs after it is returned 
from the upstream (or cache) and before it is sent to the client?

I think something like that is possible with lua but I would really like to 
avoid using 3rd party modules and just go the njs route.

If not possible - is there any workaround? And/or can it be easily added in 
next release(s)?

Thank you in advance.



Hi Grzegorz,

Please, clarify what are you trying to do with Set-Cookie headers? 
Consider built-in directives for a typical modifications like 
proxy_cookie_domain, proxy_cookie_flags etc.


If nothing is applicable take a look at the following example:

nginx.conf:

js_import main from http.js;
js_set $modify_cookies  main.modify_cookies;

location /modify_cookies {
    add_header _ $modify_cookies;
    proxy_pass http://127.0.0.1:8080;
 }

server {
listen   127.0.0.1:8080;

location /modify_cookies {
add_header Set-Cookie "XX";
add_header Set-Cookie "BB";
add_header Set-Cookie "YYY";
return 200;
}
}

http.js:
function modify_cookies(r) {
var cookies = r.headersOut['Set-Cookie'];
r.headersOut['Set-Cookie'] = cookies.filter(v=>v.length > 
Number(r.args.len));

return "";
}


curl http://localhost:8000/modify_cookies?len=1 -v
...
< Set-Cookie: XX
< Set-Cookie: BB
< Set-Cookie: YYY



curl http://localhost:8000/modify_cookies?len=3 -v
...
< Set-Cookie: XX
< Set-Cookie: YYY


This works because arbitrary njs code can be executed when nginx 
evaluates a variable at runtime.
The trick is to find an appropriate directives which supports variables 
and which is evaluated at appropriate moment of request processing. So, 
in the example an auxiliary variable is used to inject njs code after an 
upstream data is processed but response headers are not sent to a client 
yet.




___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx

njs-0.5.1

2021-02-16 Thread Dmitry Volyntsev

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('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://127.0.0.1:8081/;
:   }
:
: 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:
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.116 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.

___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx

njs-0.5.2

2021-03-09 Thread Dmitry Volyntsev

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:
- js_body_filter directive. The directive allows changing the
response body.
: nginx.conf:
:   js_import foo.js;
:
:   location / {
:   js_body_filter foo.to_lower;
:   proxy_pass http://127.0.0.1:8081/;
:   }
:
: foo.js:
:   function to_lower(r, data, flags) {
: r.sendBuffer(data.toLowerCase(), flags);
:   }
:
:   export default {to_lower};
- njs.on('exit') callback. The "exit" hook allows to implement
some cleanup logic before the VM instance is destroyed.
: foo.js:
:   function handler(r) {
: njs.on('exit', () => {
: r.warn("DONE");
: });
:   }

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:
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.209 Mar 2021

nginx modules:

*) Feature: added the "js_body_filter" directive.

*) Feature: introduced the "status" property for stream session
   object.

*) Feature: added njs.on('exit') callback support.

*) Bugfix: fixed property descriptor reuse for not extensible
   objects.
   Thanks to Artem S. Povalyukhin.

*) Bugfix: fixed Object.freeze() and friends according to
   the specification.
   Thanks to Artem S. Povalyukhin.

*) Bugfix: fixed Function() in CLI mode.

*) Bugfix: fixed for-in iteration of typed array values.
   Thanks to Artem S. Povalyukhin.

___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx


njs-0.5.3

2021-03-30 Thread Dmitry Volyntsev

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:
- js_var directive. The directive creates an nginx variable writable
from njs. The variable is not overwritten after a redirect unlike
variables created with the set directive.

This is especially useful in situations where some directive value
depends on the result of a subrequest.

The following example illustrates the case where Authorization header
is processed by a HTTP endpoint which returns foo value as a result.
This result is passed as a header to the backend.

: nginx.conf:
:   js_import main.js;
:
:   js_var $foo;
:   ..
:
:   location /secure/ {
:   auth_request /set_foo;
:
:   proxy_set_header Foo $foo;
:   proxy_pass http://backend;
:   }
:
:  location =/set_foo {
:   internal;
:   js_content main.set_foo;
:  }
:
: main.js:
:   function set_foo(r) {
:ngx.fetch('http://127.0.0.1:8080', {headers: {Authorization: 
r.headersIn.Authorization}})
:.then(reply => {
:r.variables.foo = reply.headers.get('foo');
:r.return(200);
:});
:   }
:
:   export default {set_foo};

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:
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.330 Mar 2021

nginx modules:

*) Feature: added the "js_var" directive.

___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx


njs-0.6.0

2021-06-15 Thread Dmitry Volyntsev

Hello,

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

This release proceeds to extend the coverage of ECMAScript
specifications.

Notable new features:
- let and const declarations support
: >> fuction test() { x = 1; let x; }
: undefined
: >> test()
: ReferenceError: cannot access variable before initialization
: >> function test2() {const x = 1; x = 2; }
: undefined
: >> test2()
: TypeError: assignment to constant variable

You can learn more about njs:

- Overview and introduction: http://nginx.org/en/docs/njs/
- NGINX JavaScript in Your Web Server Configuration:
https://youtu.be/Jc_L6UffFOs
- Extending NGINX with Custom Code: https://youtu.be/0CVhq4AUU7M
- 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.6.015 Jun 2021

Core:

*) Feature: added let and const declaration support.

*) Feature: added RegExp.prototype[Symbol.split].

*) Feature: added sticky flag support for RegExp.

*) Bugfix: fixed heap-buffer-overflow in
   String.prototype.lastIndexOf().

*) Bugfix: fixed RegExp.prototype.test() according to the
   specification.

*) Bugfix: fixed String.prototype.split() according to the
   specification.

*) Bugfix: fixed use-of-uninitialized-value while tracking
   rejected promises.

*) Bugfix: fixed njs.dump() for objects with circular
   references.

___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx


njs-0.6.1

2021-06-29 Thread Dmitry Volyntsev

Hello,

This is a bugfix release that fixes RegExp matching for a regular expression
containing UTF-8 characters.  The matching of ASCII or byte string by UTF-8
regexp was always negative.

What methods were affected:
- RegExp.prototype.exec() (since 0.4.2)
- RegExp.protytype.test() (since 0.5.3)

You can learn more about njs:

- Overview and introduction: http://nginx.org/en/docs/njs/
- NGINX JavaScript in Your Web Server Configuration:
https://youtu.be/Jc_L6UffFOs
- Extending NGINX with Custom Code: https://youtu.be/0CVhq4AUU7M
- 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.6.129 Jun 2021

*) Bugfix: fixed RegExpBuiltinExec() with UTF-8 only regexps.
   The bug was introduced in 0.4.2.

*) Bugfix: fixed parsing of export default declaration with
   non-assignment expressions.
   Thanks to Artem S. Povalyukhin.

___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx


Re: NJS Questions and/or Bugs

2021-08-11 Thread Dmitry Volyntsev

Hi Lance,

Thanks for your detailed feedback.

>What exactly should r.variables and r.rawVariables contain?  ...

r.variables and r.rawVariables are special objects, because they are 
created on the fly. There is no way to get all the possible variable 
names from nginx. So Object.keys(r.variables) is empty list. Therefore 
dumping and iterating over r.variables returns nothing. But, if you have 
a $foo variable, r.variables.foo would return the $foo content as a string.


> That might also be a fallacy of our testing methodology since we’re 
using JSON.stringify to visualize the output in the browser.


The JSON.stringify() is no the best, use njs.dump(). 
http://nginx.org/en/docs/njs/reference.html#njs


>Is there already an NJS object or are there plans for an object that 
parses and maps POST key/value pairs into a JSON object?


Take a look at https://github.com/nginx/njs/issues/48#issuecomment-415745451

>Filters for the different phase of the Nginx request

We are thinking about the adding phases handlers.

>Direct variable access to the Nginx variables (either read only or 
writable depending on the context within which they were created)


this is already in place

>Array like access to the request arguments (e.g. cookies, post args, 
query string args, etc).  Right now the only version of this that we’ve 
found reliably working in the js_content phase is query string related 
stuff (in the args array)


Feel free to add a feature request here https://github.com/nginx/njs
Although this is not a feature requested often (for some reason).
___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx


njs-0.6.2

2021-08-31 Thread Dmitry Volyntsev

Hello,

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

This release proceeds to extend the coverage of ECMAScript
specifications.

Notable new features:
- Advanced Promise constructor methods
: Promise.all(urls.map(u => ngx.fetch(u)))
: .then(responses => r.return(200, JSON.stringify(responses)))

Learn more about njs:

- Overview and introduction: https://nginx.org/en/docs/njs/
- NGINX JavaScript in Your Web Server Configuration:
https://youtu.be/Jc_L6UffFOs
- Extending NGINX with Custom Code: https://youtu.be/0CVhq4AUU7M
- Using node modules with njs:
https://nginx.org/en/docs/njs/node_modules.html
- Writing njs code using TypeScript definition files:
   https://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: https://mailman.nginx.org/mailman/listinfo/nginx-devel


Changes with njs 0.6.231 Aug 2021

nginx modules:

*) Bugfix: fixed CPU hog when js_filter is registered
   in both directions.

Core:

*) Feature: introduced AggregateError implementation.

*) Feature: added remaining Promise constructor methods.
   The following methods were added: Promise.all(),
   Promise.allSettled(), Promise.any(), Promise.race().

*) Improvement: removed recursion from code generator.

*) Bugfix: fixed rest parameter parsing without binding
   identifier.

*) Bugfix: fixed resolve/reject callback for
   Promise.prototype.finally().

*) Bugfix: fixed %TypedArray%.prototype.join() with
   detached buffer.

*) Bugfix: fixed memory leak in interactive shell.

___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx


njs-0.7.0

2021-10-19 Thread Dmitry Volyntsev

Hello,

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

This release adds a bunch of long-awaited features.

Notable new features:
- async/await support:
- HTTPS support in Fetch API:
: async function content(r) {
: let results = await Promise.all([ngx.fetch('https://nginx.org/'),
:  ngx.fetch('https://nginx.org/en/')]);
:
: r.return(200, JSON.stringify(results, undefined, 4));
: }

- WebCrypto API support:
: async function host_hash(r) {
: let hash = await crypto.subtle.digest('SHA-512', r.headersIn.host);
: r.setReturnValue(Buffer.from(hash).toString('hex'));
: }

Learn more about njs:

- Overview and introduction: https://nginx.org/en/docs/njs/
- NGINX JavaScript in Your Web Server Configuration:
https://youtu.be/Jc_L6UffFOs
- Extending NGINX with Custom Code: https://youtu.be/0CVhq4AUU7M
- Using node modules with njs:
https://nginx.org/en/docs/njs/node_modules.html
- Writing njs code using TypeScript definition files:
   https://nginx.org/en/docs/njs/typescript.html

We are hiring:

If you are a C programmer, passionate about Open Source and you
love what we do, consider the following career opportunity:
https://ffive.wd5.myworkdayjobs.com/NGINX/job/Ireland-Homebase/Software-Engineer-III---NGNIX-NJS_RP1022237

Feel free to try it and give us feedback on:

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


Changes with njs 0.7.019 Oct 2021

nginx modules:

*) Feature: added HTTPS support for Fetch API.

*) Feature: added setReturnValue() method.

Core:

*) Feature: introduced Async/Await implementation.

*) Feature: added WebCrypto API implementation.

*) Bugfix: fixed copying of closures for declared
   functions. The bug was introduced in 0.6.0.

*) Bugfix: fixed unhandled promise rejection in handle
   events.

*) Bugfix: fixed Response.headers getter in Fetch API.

___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx


njs-0.7.1

2021-12-28 Thread Dmitry Volyntsev

Hello,

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

This release focuses on stabilization of recently released features
including async/await and HTTPS support in ngx.fetch().

The "js_include" directive deprecated since 0.4.0 was removed.

Also a series of user invisible refactoring was committed. The most
prominent one is PCRE2 support. PCRE2 is the default RegExp engine
now.

Learn more about njs:

- Overview and introduction: https://nginx.org/en/docs/njs/
- NGINX JavaScript in Your Web Server Configuration:
https://youtu.be/Jc_L6UffFOs
- Extending NGINX with Custom Code: https://youtu.be/0CVhq4AUU7M
- Using node modules with njs:
https://nginx.org/en/docs/njs/node_modules.html
- Writing njs code using TypeScript definition files:
   https://nginx.org/en/docs/njs/typescript.html

We are hiring:

If you are a C programmer, passionate about Open Source and you
love what we do, consider the following career opportunity:
https://ffive.wd5.myworkdayjobs.com/NGINX/job/Ireland-Homebase/Software-Engineer-III---NGNIX-NJS_RP1022237

Feel free to try it and give us feedback on:

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


Changes with njs 0.7.128 Dec 2021

nginx modules:

*) Change: the "js_include" directive deprecated since 0.4.0 was
   removed.

*) Change: PCRE/PCRE2-specific code was moved to the modules.
   This ensures that njs uses the same RegExp library as nginx.

Core:

*) Feature: extended "fs" module. Added stat(), fstat()
   and friends.

*) Change: default RegExp engine for CLI is switched
   to PCRE2.

*) Bugfix: fixed decodeURI() and decodeURIComponent() with
   invalid byte strings. The bug was introduced in 0.4.3.

*) Bugfix: fixed heap-use-after-free in await frame.
   The bug was introduced in 0.7.0.

*) Bugfix: fixed WebCrypto sign() and verify() methods
   with OpenSSL 3.0.

*) Bugfix: fixed exception throwing when RegExp match fails.
   The bug was introduced in 0.1.15.

*) Bugfix: fixed catching of exception thrown in try block
   of async function. The bug was introduced in 0.7.0.

*) Bugfix: fixed execution of async function in synchronous
   context. The bug was introduced in 0.7.0.

*) Bugfix: fixed function redeclaration in CLI when interactive
   mode is on. The bug was introduced in 0.6.2.

*) Bugfix: fixed typeof operator with DataView object.

*) Bugfix: eliminated information leak in Buffer.from().

___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx


njs-0.7.2

2022-01-25 Thread Dmitry Volyntsev

Hello,

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

This release focuses on stabilization of recently released features
including async/await and fixing bugs found by various fuzzers.

Learn more about njs:

- Overview and introduction: https://nginx.org/en/docs/njs/
- NGINX JavaScript in Your Web Server Configuration:
https://youtu.be/Jc_L6UffFOs
- Extending NGINX with Custom Code: https://youtu.be/0CVhq4AUU7M
- Using node modules with njs:
https://nginx.org/en/docs/njs/node_modules.html
- Writing njs code using TypeScript definition files:
   https://nginx.org/en/docs/njs/typescript.html

We are hiring:

If you are a C programmer, passionate about Open Source and you
love what we do, consider the following career opportunity:
https://ffive.wd5.myworkdayjobs.com/NGINX/job/Ireland-Homebase/Software-Engineer-III---NGNIX-NJS_RP1022237

Feel free to try it and give us feedback on:

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


Changes with njs 0.7.2 25 Jan 2022

Core:

*) Bugfix: fixed Array.prototype.join() when array is changed
   while iterating.

*) Bugfix: fixed Array.prototype.slice() when array is changed
   while iterating.

*) Bugfix: fixed Array.prototype.concat() when array is changed
   while iterating.

*) Bugfix: fixed Array.prototype.reverse() when array is changed
   while iterating.

*) Bugfix: fixed Buffer.concat() with subarrays.
   Thanks to Sylvain Etienne.

*) Bugfix: fixed type confusion bug while resolving promises.

*) Bugfix: fixed Function.prototype.apply() with large array
   arguments.

*) Bugfix: fixed recursive async function calls.

*) Bugfix: fixed function redeclaration. The bug was introduced
   in 0.7.0.

___
nginx mailing list -- nginx@nginx.org
To unsubscribe send an email to nginx-le...@nginx.org


Re: Njs Utility not working

2022-04-05 Thread Dmitry Volyntsev

Hi,

Please attach the configure output.

If njs CLI was built successfully, but the binary does not work in 
terminal mode. The reason is libreadline was not found during configure 
phase.


On 05.04.2022 16:15, 王明君 wrote:
Hi, i'm trying to build only njs command-line utility following 
_http://nginx.org/en/docs/njs/install.html_, but the final njs does 
not work as expected. See this mail's attached file to find out how i 
was trying.


*uname -a*
Linux localhost.localdomain 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 
16:18:59 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux


*cat os-release*
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/";
BUG_REPORT_URL="https://bugs.centos.org/";

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"


___
nginx mailing list -- nginx@nginx.org
To unsubscribe send an email to nginx-le...@nginx.org

___
nginx mailing list -- nginx@nginx.org
To unsubscribe send an email to nginx-le...@nginx.org


Re: Njs Utility not working

2022-04-05 Thread Dmitry Volyntsev

You have to install libreadline for your Linux.

I hope the following or similar command should help:

sudo yum install readline-devel

On 05.04.2022 19:04, 王明君 wrote:

Thanks for helping me. As you reminded, i found this log:

*checking for GNU readline library ... not found
checking for editline library in editline/readline.h ... not found
checking for editline in edit/readline/readline.h ... not found
checking for editline in readline/readline.h ... not found
- njs CLI is built without interactive shell support*

So, what can i do to solve this? I'm actually not much experienced

Full configure output:
-
configuring for Linux 3.10.0-1062.9.1.el7.x86_64 x86_64
checking for C compiler: cc
+ using GNU C compiler
+ gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
checking for sizeof(int) ... 4
checking for sizeof(u_int) ... 4
checking for sizeof(void *) ... 8
checking for sizeof(uintptr_t) ... 8
checking for sizeof(size_t) ... 8
checking for sizeof(off_t) ... 8
checking for sizeof(time_t) ... 8
checking for system byte ordering ... little
checking for GCC unsigned __int128 ... found
checking for GCC __builtin_expect() ... found
checking for GCC __builtin_unreachable() ... found
checking for GCC __builtin_prefetch() ... found
checking for GCC __builtin_clz() ... found
checking for GCC __builtin_clzll() ... found
checking for GCC __attribute__ visibility ... found
checking for GCC __attribute__ malloc ... found
checking for GCC __attribute__ aligned ... found
checking for GCC __attribute__ packed ... found
checking for Address sanitizer ... not found
checking for Memory sanitizer ... not found
checking for _mm_setcsr() ... found
checking for clock_gettime(CLOCK_MONOTONIC) ... found
checking for struct tm.tm_gmtoff ... found
checking for altzone ... not found
checking for posix_memalign() ... found
checking for getrandom() ... not found
checking for SYS_getrandom in Linux ... found
checking for stat.st_atimespec ... not found
checking for stat.st_birthtim ... not found
checking for stat.st_atim ... found
checking for explicit_bzero() ... not found
checking for explicit_memset() ... not found
checking for PCRE2 library ... not found
checking for PCRE library ... not found
checking for PCRE library in /usr ... found
checking for PCRE version ... 8.32
checking for GNU readline library ... not found
checking for editline library in editline/readline.h ... not found
checking for editline in edit/readline/readline.h ... not found
checking for editline in readline/readline.h ... not found
- njs CLI is built without interactive shell support
checking for OpenSSL library ... not found
checking for OpenSSL library -lcrypto ... found
checking for OpenSSL version ... "OpenSSL 1.0.2k-fips  26 Jan 2017"
creating build/Makefile
checking for expect ... found
+ Expect version: expect version 5.45
- expect tests are disabled

NJS configuration summary:

+ using CC: "cc"
+ using CFLAGS: " -pipe -fPIC -fvisibility=hidden -O -W -Wall -Wextra 
-Wno-unused-parameter -Wwrite-strings -Wmissing-prototypes -Werror -g -O "


+ using PCRE library: -lpcre
+ using OpenSSL library: -lcrypto

njs build dir: build
njs CLI: build/njs


王明君
wmjhappy...@126.com

<https://maas.mail.163.com/dashi-web-extend/html/proSignature.html?ftlId=1&name=%E7%8E%8B%E6%98%8E%E5%90%9B&uid=wmjhappy_ok%40126.com&iconUrl=https%3A%2F%2Fmail-online.nosdn.127.net%2Fsm169ab9356098976ee9a1ecee61e677f0.jpg&items=%5B%22wmjhappy_ok%40126.com%22%5D> 

On 4/6/2022 09:51,Dmitry Volyntsev 
<mailto:xei...@nginx.com> wrote:


Hi,

Please attach the configure output.

If njs CLI was built successfully, but the binary does not work in
terminal mode. The reason is libreadline was not found during
configure
phase.

On 05.04.2022 16:15, 王明君 wrote:

Hi, i'm trying to build only njs command-line utility following
_http://nginx.org/en/docs/njs/install.html_, but the final njs
does
not work as expected. See this mail's attached file to find
out how i
was trying.

*uname -a*
Linux localhost.localdomain 3.10.0-1160.el7.x86_64 #1 SMP Mon
Oct 19
16:18:59 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

*cat os-release*
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/";
BUG_REPORT_URL="https://bugs.centos.org/";

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
 

Re: Njs - r.variables does not contain variables declared by js_var

2022-04-06 Thread Dmitry Volyntsev

Hi,

See the following reply on Github

https://github.com/nginx/njs/issues/460#issuecomment-1015642606

On 06.04.2022 00:02, 王明君 wrote:

Hi, sorry to bother again ~
I was trying to access variables declared using js_var but failed. 
Confused why is that.


This is a test demo, but actually i have a massive nginx config file 
that i want to minify using njs, and under which circumstance i need 
the js script to have access to variables declared in nginx.conf, 
either by using js_var directive, or something else (not found).


*demo - nginx.conf*
--
http {
js_import main from main.js;
js_var $abc "ss fd";

server {

listen 80;
server_name localhost;

location / {

js_content main.hello;

}

}
}

*demo - **main.js*
--
function hello(r) {
       r.headersOut["Content-Type"] = "application/json";
       var m = {};
       for(var p in r)
               m[p] = r[p];
       m["variables"] = r.variables;
       r.return(200, JSON.stringify(m));
}

export default { hello };
---

*demo - **output*



===

*uname -a*
Linux localhost.localdomain 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 
16:18:59 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux


*cat os-release*
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/";
BUG_REPORT_URL="https://bugs.centos.org/";

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"





___
nginx mailing list -- nginx@nginx.org
To unsubscribe send an email to nginx-le...@nginx.org

___
nginx mailing list -- nginx@nginx.org
To unsubscribe send an email to nginx-le...@nginx.org


njs-0.7.3

2022-04-12 Thread Dmitry Volyntsev

Hello,

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

This release focuses on stabilization of recently released features
including async/await and fixing bugs found by various fuzzers.

Learn more about njs:

- Overview and introduction:https://nginx.org/en/docs/njs/
- NGINX JavaScript in Your Web Server Configuration:
https://youtu.be/Jc_L6UffFOs
- Extending NGINX with Custom Code:https://youtu.be/0CVhq4AUU7M
- Using node modules with njs:
https://nginx.org/en/docs/njs/node_modules.html
- Writing njs code using TypeScript definition files:
   https://nginx.org/en/docs/njs/typescript.html

We are hiring:

If you are a C programmer, passionate about Open Source and you
love what we do, consider the following career opportunity:
https://ffive.wd5.myworkdayjobs.com/NGINX/job/Ireland-Homebase/Software-Engineer-III---NGNIX-NJS_RP1022237

Feel free to try it and give us feedback on:

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


Changes with njs 0.7.312 Apr 2022

Core:

*) Feature: added support of module resolution callback.
   This feature allows a host environment to control
   how imported modules are loaded.

*) Bugfix: fixed backtraces while traversing imported user
   modules.

*) Bugfix: fixed Array.prototype.concat() when "this" is a slow
   array.

*) Bugfix: fixed frame allocation from an awaited frame.

*) Bugfix: fixed allocation of large array literals.

*) Bugfix: fixed interpreter when "toString" conversion fails.
___
nginx mailing list -- nginx@nginx.org
To unsubscribe send an email to nginx-le...@nginx.org


njs-0.7.4

2022-05-24 Thread Dmitry Volyntsev

Hello,

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

This release focuses on stabilization of recently released features
including WebCrypto API and fixing bugs found by various fuzzers.

Learn more about njs:

- Overview and introduction:https://nginx.org/en/docs/njs/
- NGINX JavaScript in Your Web Server Configuration:
https://youtu.be/Jc_L6UffFOs
- Extending NGINX with Custom Code:https://youtu.be/0CVhq4AUU7M
- Using node modules with njs:
https://nginx.org/en/docs/njs/node_modules.html
- Writing njs code using TypeScript definition files:
   https://nginx.org/en/docs/njs/typescript.html

We are hiring:

If you are a C programmer, passionate about Open Source and you
love what we do, consider the following career opportunity:
https://ffive.wd5.myworkdayjobs.com/NGINX/job/Ireland-Homebase/Software-Engineer-III---NGNIX-NJS_RP1022237

Feel free to try it and give us feedback on:

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

Additional examples and howtos can be found here:

- Github:https://github.com/nginx/njs-examples

Changes with njs 0.7.424 May 2022

nginx modules:

*) Feature: added extended directive to configure Fetch API.
   The following directives were added: "js_fetch_timeout",
   "js_fetch_verify", "js_fetch_buffer_size",
   "js_fetch_max_response_buffer_size".

*) Change: r.internalRedirect() now accepts escaped URIs.

*) Bugfix: fixed Response parsing with more than 8 headers
   in Fetch API.

Core:

*) Feature: added njs.version_number property.

*) Feature: added compatibility with BoringSSL for
   WebCrypto API.

*) Bugfix: fixed Array.prototype.sort() when arr size is changed
   in a comparator.

*) Bugfix: fixed Array.prototype.slice() with slow "this" argument.

*) Bugfix: fixed aggregation methods of Promise ctor with
   array-like object.

*) Bugfix: fixed Array.prototype.lastIndexOf() with Unicode
   string as "this".

*) Bugfix: fixed JSON.parse() when reviver function is provided.

*) Bugfix: fixed Object.defineProperty() when a recursive descriptor
   is provided.

*) Bugfix: fixed Array.prototype.fill() for typed-arrays.

*) Bugfix: making function expression binding immutable according
   the specs.

*) Bugfix: fixed redefinition of special props in
   Object.defineProperty().
___
nginx mailing list -- nginx@nginx.org
To unsubscribe send an email to nginx-le...@nginx.org


njs-0.7.4 (fixed formatting)

2022-05-24 Thread Dmitry Volyntsev

Hello,

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

This release focuses on stabilization of recently released features
including WebCrypto API and fixing bugs found by various fuzzers.

Learn more about njs:

- Overview and introduction: https://nginx.org/en/docs/njs/
- NGINX JavaScript in Your Web Server Configuration:
https://youtu.be/Jc_L6UffFOs
- Extending NGINX with Custom Code: https://youtu.be/0CVhq4AUU7M
- Using node modules with njs:
https://nginx.org/en/docs/njs/node_modules.html
- Writing njs code using TypeScript definition files:
   https://nginx.org/en/docs/njs/typescript.html

We are hiring:

If you are a C programmer, passionate about Open Source and you
love what we do, consider the following career opportunity:
https://ffive.wd5.myworkdayjobs.com/NGINX/job/Ireland-Homebase/Software-Engineer-III---NGNIX-NJS_RP1022237

Feel free to try it and give us feedback on:

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

Additional examples and howtos can be found here:

- Github: https://github.com/nginx/njs-examples

Changes with njs 0.7.4  24 May 2022

nginx modules:

*) Feature: added extended directive to configure Fetch API.
   The following directives were added: “js_fetch_timeout”,
   “js_fetch_verify”, “js_fetch_buffer_size”,
   “js_fetch_max_response_buffer_size”.

*) Change: r.internalRedirect() now accepts escaped URIs.

*) Bugfix: fixed Response parsing with more than 8 headers
   in Fetch API.

Core:

*) Feature: added njs.version_number property.

*) Feature: added compatibility with BoringSSL for
   WebCrypto API.

*) Bugfix: fixed Array.prototype.sort() when arr size is changed
   in a comparator.

*) Bugfix: fixed Array.prototype.slice() with slow “this” argument.

*) Bugfix: fixed aggregation methods of Promise ctor with
   array-like object.

*) Bugfix: fixed Array.prototype.lastIndexOf() with unicode
   string as “this”.

*) Bugfix: fixed JSON.parse() when reviver function is provided.

*) Bugfix: fixed Object.defineProperty() when a recursive descriptor
   is provided.

*) Bugfix: fixed Array.prototype.fill() for typed-arrays.

*) Bugfix: making function expression binding immutable according
   the specs.

*) Bugfix: fixed redefinition of special props in
   Object.defineProperty().
___
nginx mailing list -- nginx@nginx.org
To unsubscribe send an email to nginx-le...@nginx.org


njs-0.7.5

2022-06-21 Thread Dmitry Volyntsev

Hello,

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

This release focuses on stabilization of recently released features
and fixing bugs found by various fuzzers.

Learn more about njs:

- Overview and introduction: https://nginx.org/en/docs/njs/
- NGINX JavaScript in Your Web Server Configuration:
https://youtu.be/Jc_L6UffFOs
- Extending NGINX with Custom Code: https://youtu.be/0CVhq4AUU7M
- Using node modules with njs:
https://nginx.org/en/docs/njs/node_modules.html
- Writing njs code using TypeScript definition files:
   https://nginx.org/en/docs/njs/typescript.html

We are hiring:

If you are a C programmer, passionate about Open Source and you
love what we do, consider the following career opportunity:
https://ffive.wd5.myworkdayjobs.com/NGINX/job/Ireland-Homebase/Software-Engineer-III---NGNIX-NJS_RP1022237

Feel free to try it and give us feedback on:

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

Additional examples and howtos can be found here:

- Github: https://github.com/nginx/njs-examples

Changes with njs 0.7.5  21 Jun 2022

nginx modules:

*) Change: adapting to changes in nginx header structures.

*) Bugfix: fixed r.headersOut special getters when value
   is absent.

*) Change: returning undefined value instead of an empty string
   for Content-Type when the header is absent.

Core:

*) Bugfix: fixed catching of the exception thrown from an
   awaited function.

*) Bugfix: fixed function value initialization.

*) Bugfix: fixed interpreter when await fails.

*) Bugfix: fixed typed-array constructor when source array
   is changed while iterating.

*) Bugfix: fixed String.prototype.replace() with byte strings.

*) Bugfix: fixed template literal from producing byte-strings.

*) Bugfix: fixed array iterator with sparse arrays.

*) Bugfix: fixed memory free while converting a flat array to
   a slow array.

*) Bugfix: properly handling NJS_DECLINE in promise native
   functions.

*) Bugfix: fixed working with an array-like object in Promise.all()
   and friends.
___
nginx mailing list -- nginx@nginx.org
To unsubscribe send an email to nginx-le...@nginx.org


njs-0.7.6

2022-07-19 Thread Dmitry Volyntsev

Hello,

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

Notable new features:
 - improved r.args:
Now, duplicate keys are returned as an array, keys are
case-sensitive, both keys and values are percent-decoded.

For example, the query string

'a=1&b=%32&A=3&b=4&B=two%20words'

is converted to r.args as:

{a: "1", b: ["2", "4"], A: "3", B: "two words"}

Learn more about njs:

- Overview and introduction: https://nginx.org/en/docs/njs/
- NGINX JavaScript in Your Web Server Configuration:
 https://youtu.be/Jc_L6UffFOs
- Extending NGINX with Custom Code: https://youtu.be/0CVhq4AUU7M
- Using node modules with njs:
https://nginx.org/en/docs/njs/node_modules.html
- Writing njs code using TypeScript definition files:
https://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: https://mailman.nginx.org/mailman/listinfo/nginx-devel

Additional examples and howtos can be found here:

- Github: https://github.com/nginx/njs-examples

Changes with njs 0.7.619 Jul 2022

nginx modules:

*) Feature: improved r.args object. Added support for multiple
   arguments with the same key. Added case sensitivity for
   keys. Keys and values are percent-decoded now.

*) Bugfix: fixed r.headersOut setter for special headers.

Core:

*) Feature: added Symbol.for() and Symbol.keyfor().

*) Feature: added btoa() and atob() from WHATWG spec.

*) Bugfix: fixed large non-decimal literals.

*) Bugfix: fixed unicode argument trimming in parseInt().

*) Bugfix: fixed break instruction in a try-catch block.

*) Bugfix: fixed async function declaration in CLI.
___
nginx mailing list -- nginx@nginx.org
To unsubscribe send an email to nginx-le...@nginx.org


njs-0.7.7

2022-08-30 Thread Dmitry Volyntsev

Hello,

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

Notable new features:
 - advances fs API:
New API allows to open a file and read from and write to at
specified location without reading the whole file.

import fs from 'fs';

async function modifying_large_file() {
let fh = await fs.promises.open('/my/path');

let buf = Buffer.alloc(4);

await fh.read(buf, 0, 4, 64);

console.log(`read ${buf.toString('hex')}`);

// modify part
buf[0] = buf[0] ^ buf[3];

await fh.write(buf, 0, 4, 64);

console.log(`written ${buf.toString('hex')}`);

await fh.close();
}

Learn more about njs:

- Overview and introduction: https://nginx.org/en/docs/njs/
- NGINX JavaScript in Your Web Server Configuration:
 https://youtu.be/Jc_L6UffFOs
- Extending NGINX with Custom Code: https://youtu.be/0CVhq4AUU7M
- Using node modules with njs:
https://nginx.org/en/docs/njs/node_modules.html
- Writing njs code using TypeScript definition files:
https://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: https://mailman.nginx.org/mailman/listinfo/nginx-devel

Additional examples and howtos can be found here:

- Github: https://github.com/nginx/njs-examples

Changes with njs 0.7.7 30 Aug 2022

nginx modules:

*) Feature: the number of nginx configuration contexts where
   js directives can be specified is extended.

   HTTP: js_import, js_path, js_set and js_var are allowed
   in server and location contexts. js_content, js_body_filter
   and js_header_filter are allowed in 'if' context.

   Stream: js_import, js_path, js_set and js_var are allowed
   in server context.

*) Feature: added r.internal property.

*) Bugfix: fixed reading response body in fetch API.

*) Bugfix: fixed "js_fetch_timeout" in stream module.

*) Bugfix: fixed socket leak with 0 fetch timeout.

Core:

*) Feature: extended "fs" module.  Added fs.openSync(),
   fs.promises.open(), fs.fstatSync(), fs.readSync(),
   fs.writeSync().

   The following properties of FileHandle are implemented:
   fd, read(), stat(), write(), close().

*) Bugfix: fixed parseInt(), parseFloat(), Symbol.for()
   with no arguments.
___
nginx mailing list -- nginx@nginx.org
To unsubscribe send an email to nginx-le...@nginx.org


njs-0.7.8

2022-10-25 Thread Dmitry Volyntsev

Hello,

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

Notable new features:
 - js_preload_object directive:
The directive preloads an immutable object at configure time.
This significantly reduces the runtime cost of referencing large
objects in JS code.

Learn more about njs:

- Overview and introduction: https://nginx.org/en/docs/njs/
- NGINX JavaScript in Your Web Server Configuration:
 https://youtu.be/Jc_L6UffFOs
- Extending NGINX with Custom Code: https://youtu.be/0CVhq4AUU7M
- Using node modules with njs:
https://nginx.org/en/docs/njs/node_modules.html
- Writing njs code using TypeScript definition files:
https://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: https://mailman.nginx.org/mailman/listinfo/nginx-devel

Additional examples and howtos can be found here:

- Github: https://github.com/nginx/njs-examples

Changes with njs 0.7.825 Oct 2022

nginx modules:

*) Feature: added js_preload_object directive.

*) Feature: added ngx.conf_prefix property.

*) Feature: added s.sendUpstream() and s.sendDownstream()
   in stream module.

*) Feature: added support for HEAD method in Fetch API.

*) Improvement: improved async callback support for s.send()
   in stream module.

Core:

*) Feature: added "name" instance property for a function
   object.

*) Feature: added njs.memoryStats object.

*) Bugfix: fixed String.prototype.trimEnd() with unicode
   string.

*) Bugfix: fixed Object.freeze() with fast arrays.

*) Bugfix: fixed Object.defineProperty() with fast arrays.

*) Bugfix: fixed async token as a property name of an object.

*) Bugfix: fixed property set instruction when key modifies
   base binding.

*) Bugfix: fixed complex assignments.

*) Bugfix: fixed handling of unhandled promise rejection.

*) Bugfix: fixed process.env when duplicate environ variables
   are present.

*) Bugfix: fixed double declaration detection in modules.

*) Bugfix: fixed bound function calls according to the spec.

*) Bugfix: fixed break label for if statement.

*) Bugfix: fixed labeled empty statements.
___
nginx mailing list -- nginx@nginx.org
To unsubscribe send an email to nginx-le...@nginx.org


njs-0.7.9

2022-11-17 Thread Dmitry Volyntsev

Hello,

This is a bugfix release that fixes Fetch Response prototype 
reinitialization.

When at least one js_import directive was declared in both HTTP
and Stream, ngx.fetch() returned inapproriate response in Stream.
The bug was introduced in 0.7.7.

Learn more about njs:

- Overview and introduction: https://nginx.org/en/docs/njs/
- NGINX JavaScript in Your Web Server Configuration:
 https://youtu.be/Jc_L6UffFOs
- Extending NGINX with Custom Code: https://youtu.be/0CVhq4AUU7M
- Using node modules with njs:
https://nginx.org/en/docs/njs/node_modules.html
- Writing njs code using TypeScript definition files:
https://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: https://mailman.nginx.org/mailman/listinfo/nginx-devel

Additional examples and howtos can be found here:

- Github: https://github.com/nginx/njs-examples


Changes with njs 0.7.9  17 Nov 2022
nginx modules:

*) Bugfix: fixed Fetch Response prototype reinitialization.
   When at least one js_import directive was declared in both HTTP
   and Stream, ngx.fetch() returned inapproriate response in Stream.
   The bug was introduced in 0.7.7.

Core:

*) Bugfix: fixed String.prototype.replace(re) if re.exec() returns
   non-flat array.

*) Bugfix: fixed Array.prototype.fill() when start object changes
   "this".

*) Bugfix: fixed description for fs.mkdir() and fs.rmdir() methods.

*) Bugfix: fixed %TypedArray%.prototype.set(s) when s element changes
   "this".

*) Bugfix: fixed Array.prototype.splice(s, d) when d resizes "this"
   during evaluation.

*) Bugfix: fixed for-in loop with left and right hand side
   expressions.
___
nginx mailing list -- nginx@nginx.org
To unsubscribe send an email to nginx-le...@nginx.org


njs-0.7.10

2023-02-07 Thread Dmitry Volyntsev

Hello,

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

Notable new features:
- Fetch API extended support, including Headers() and Request()
constructors:
: async function makeRequest(uri, headers) {
: let h = new Headers(headers);
: h.delete("bar");
: h.append("foo", "xxx");
: let r = new Request(uri, {headers: h});
: return await ngx.fetch(r);
: }

- Extended WebCrypto API, most notably JWK support was added:
: async function importSigningJWK(jwk) {
:return await crypto.subtle.importKey('jwk', jwk,
: {name: "RSASSA-PKCS1-v1_5"},
: true, ['sign']);
: }

- XML parsing module:
: const xml = require("xml");
: let data = `>ToveJani`;

: let doc = xml.parse(data);
:
: console.log(doc.note.to.$text) /* 'Tove' */
: console.log(doc.note.to.$attr$b) /* 'bar' */
: console.log(doc.note.$tags[1].$text) /* 'Jani' */


Learn more about njs:

- Overview and introduction:
https://nginx.org/en/docs/njs/
- NGINX JavaScript in Your Web Server Configuration:
https://youtu.be/Jc_L6UffFOs
- Extending NGINX with Custom Code:
https://youtu.be/0CVhq4AUU7M
- Using node modules with njs:
https://nginx.org/en/docs/njs/node_modules.html
- Writing njs code using TypeScript definition files:
https://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:
https://mailman.nginx.org/mailman/listinfo/nginx-devel

Additional examples and howtos can be found here:

- Github:
https://github.com/nginx/njs-examples


Changes with njs 0.7.10  7 Feb 2023
nginx modules:

*) Feature: added Request, Response and Headers ctors in Fetch API.

*) Bugfix: fixed nginx logger callback for calls in master process.

Core:

*) Feature: added signal support in CLI.

*) Feature: added "xml" module for working with XML documents.

*) Feature: extended support for symmetric and asymmetric keys
   in WebCrypto. Most notably JWK format for importKey() was added.
   generateKey() and exportKey() were also implemented.

*) Feature: added String.prototype.replaceAll().

*) Bugfix: fixed for(expr1; conditional syntax error handling.

*) Bugfix: fixed Object.values() and Object.entries() with external
   objects.

*) Bugfix: fixed RegExp.prototype[@@replace]().
___
nginx mailing list
nginx@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx


Re: NJS Body File Access Race Condition?

2023-02-10 Thread Dmitry Volyntsev

Hi Lance,

On 10.02.2023 18:24, Lance Dockins wrote:
This sort of NJS behavior "seems" like some sort of race condition 
where NJS is trying to access the file after Nginx has already 
disposed of it.  Since this is a js_content directive, it should be 
blocking and it seems to be one of the few stages where access to the 
POST body is even possible.  So it's unclear why the client body 
buffer file wouldn't exist at the time that this code runs.




Take a look at 
http://nginx.org/en/docs/http/ngx_http_core_module.html#client_body_in_file_only.




___
nginx mailing list
nginx@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx


Re: NJS Body File Access Race Condition?

2023-02-10 Thread Dmitry Volyntsev


Hi Lance,

On 2/10/23 7:10 PM, Lance Dockins wrote:

Thanks, Dmitry.

Is it correct to assume that this setting just forces all POST bodies 
into a file (like shutting off client body buffers)?  And would that be 
true even with the “clean” directive?

>
> The “clean” value sounds like it just retains the POST body file until
> the request completes (at which point it’s cleaned), but if that’s an
> incorrect understanding, please let me know.

yes, "client_body_in_file_only clean" ensures two things:

1) the request body is always in a file
2) the temporary file is unlinked from a directory at the moment the 
request finishes.



By default, client_body_in_file_only is off which means
that the file is unlinked from directory right away at the moment
the file is created (thus making the file inaccessible by a name, only
through open file descriptor).


I was sort of hoping to use memory buffers for smaller request body 
sizes and only use file for larger request bodies.  But if this setting 
is the only solution to the problem (or if one of the settings is going 
to do what I’m describing), I’ll go with that.



The another option is to increase the  client_body_buffer_size ensuring the
the body is always in memory.




--
Lance Dockins

On Feb 10, 2023 at 8:49 PM -0600, Dmitry Volyntsev , 
wrote:

Hi Lance,

On 10.02.2023 18:24, Lance Dockins wrote:

This sort of NJS behavior "seems" like some sort of race condition
where NJS is trying to access the file after Nginx has already
disposed of it.  Since this is a js_content directive, it should be
blocking and it seems to be one of the few stages where access to the
POST body is even possible.  So it's unclear why the client body
buffer file wouldn't exist at the time that this code runs.



Take a look at
http://nginx.org/en/docs/http/ngx_http_core_module.html#client_body_in_file_only.





___
nginx mailing list
nginx@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx


njs-0.7.11

2023-03-09 Thread Dmitry Volyntsev

Hello,

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

Notable new features:
- XMLNode API to modify XML documents:
: const xml = require("xml");
: let data = `ToveJani`;
: let doc = xml.parse(data);
:
: doc.$root.to.$attr$b = 'bar2';
: doc.$root.to.setAttribute('c', 'baz');
: delete doc.$root.to.$attr$a;
:
: console.log(xml.serializeToString(doc.$root.to))
: /* 'Tove' */
:
: doc.$root.to.removeAllAttributes();
: doc.$root.from.$text = 'Jani2';
:
: console.log(xml.serializeToString(doc))
: /* 'ToveJani2' */
:
: doc.$root.to.$tags = [xml.parse(``), xml.parse(``)];
: doc.$root.to.addChild(xml.parse(``));
:
: console.log(xml.serializeToString(doc.$root.to))
: /* '' */
:
: doc.$root.to.removeChildren('a');
:
: console.log(xml.serializeToString(doc.$root.to))
: /* '' */


Learn more about njs:

- Overview and introduction:
https://nginx.org/en/docs/njs/
- NGINX JavaScript in Your Web Server Configuration:
https://youtu.be/Jc_L6UffFOs
- Extending NGINX with Custom Code:
https://youtu.be/0CVhq4AUU7M
- Using node modules with njs:
https://nginx.org/en/docs/njs/node_modules.html
- Writing njs code using TypeScript definition files:
https://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:
https://mailman.nginx.org/mailman/listinfo/nginx-devel

Additional examples and howtos can be found here:

- Github:
https://github.com/nginx/njs-examples

Changes with njs 0.7.11  9 Mar 2023
nginx modules:

*) Bugfix: added missed linking with libxml2 for the dynamic module.
   The bug was introduced in 0.7.10.

Core:

*) Feature: added XMLNode API to modify XML documents.

*) Change: removed XML_PARSE_DTDVALID during parsing of XML document
   due to security implications. The issue was introduced
   in 0.7.10. When XML_PARSE_DTDVALID is enabled, libxml2 parses and
   executes external entities present inside an XML document.

*) Bugfix: fixed the detection of await in arguments.

*) Bugfix: fixed Error() instance dumping when "name" prop is not
   primitive.

*) Bugfix: fixed array instance with a getter property dumping.

*) Bugfix: fixed njs_object_property() with NJS_WHITEOUT properties.

*) Bugfix: fixed func instance dumping with "name" as getter.

*) Bugfix: fixed attaching of a stack to an error object.

*) Bugfix: fixed String.prototype.replace() with replacement
   containing "$'", "$`".
___
nginx mailing list
nginx@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx


njs-0.7.12

2023-04-10 Thread Dmitry Volyntsev

Hello,

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

Notable new features:
- "zlib" module:
: const zlib = require('zlib');
: zlib.deflateRawSync('αβγ').toString('base64')
: /* "O7fx3KZzmwE=" */
:
: zlib.inflateRawSync(Buffer.from('O7fx3KZzmwE=', 'base64')).toString()
: /* "αβγ" */

Learn more about njs:

- Overview and introduction:
https://nginx.org/en/docs/njs/
- NGINX JavaScript in Your Web Server Configuration:
https://youtu.be/Jc_L6UffFOs
- Extending NGINX with Custom Code:
https://youtu.be/0CVhq4AUU7M
- Using node modules with njs:
https://nginx.org/en/docs/njs/node_modules.html
- Writing njs code using TypeScript definition files:
https://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:
https://mailman.nginx.org/mailman/listinfo/nginx-devel

Additional examples and howtos can be found here:

- Github:
https://github.com/nginx/njs-examples

Changes with njs 0.7.12 10 Apr 2023

nginx modules:

*) Bugfix: fixed Headers() constructor in Fetch API.

Core:

*) Feature: added Hash.copy() method in "crypto" module.

*) Feature: added "zlib" module.

*) Improvement: added support for export {name as default}
   statement.

*) Bugfix: fixed Number constructor according to the spec.
___
nginx mailing list
nginx@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx


Re: nginScript question

2017-07-13 Thread Dmitry Volyntsev



On 12.07.2017 23:57, aledbf wrote:

Hi,

It is possible to make a HTTP request with nginScript?



Hi,

Unfortunately, this is not possible so far. But, we are going to add 
such functionality in the future. You can find what is currently 
possible here http://nginx.org/en/docs/http/ngx_http_js_module.html

___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx


Re: Where can I find nginScript shell

2018-01-09 Thread Dmitry Volyntsev



On 07.01.2018 17:06, kimown wrote:

I find the associated code, thanks for your help, but I'm not familiar with
how to building the nginScript shell, I think it's better add instruction in
README.Also, nginScript is really really awesome.



It is available as a part of nginx official packages.
Just follow http://nginx.org/en/linux_packages.html#mainline
NJS CLI is included as a part of nginx-module-njs package.

___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx


Re: nginScript question

2018-04-10 Thread Dmitry Volyntsev



On 13.07.2017 18:14, aledbf wrote:

Thanks!


Hi,

I am glad to inform you that since njs-0.2.0 it is possible to create 
arbitrary http subrequests from js_content phase.


Here you can find the subrequest API description: 
http://hg.nginx.org/njs/rev/750f7c6f071c


Here you can find some usage examples: 
http://hg.nginx.org/nginx-tests/rev/8e593b068fc0

___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx


Re: unknown directive "js_include"

2018-04-12 Thread Dmitry Volyntsev



On 12.04.2018 17:17, Dineshkumar wrote:

Hi All,

Im getting the following error when using nginscript module in RHEL 5
server.
nginx: [emerg] unknown directive "js_include" in /etc/nginx/nginx.conf:13

Installed the nginx using the following RPM
https://nginx.org/packages/rhel/5/x86_64/RPMS/nginx-1.10.0-1.el5.ngx.x86_64.rpm

Installed the nginx-module-njs module using the following RPM
https://nginx.org/packages/rhel/5/x86_64/RPMS/nginx-module-njs-1.10.0.0.0.20160414.1c50334fbea6-1.el5.ngx.x86_64.rpm

Please let me know if there are any alternatives to mitigate this issue.



Did you enabled the module in the nginx config?

http://nginx.org/en/docs/ngx_core_module.html#load_module



Regards,
Dinesh

Posted at Nginx Forum: 
https://forum.nginx.org/read.php?2,279415,279415#msg-279415

___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx


___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx


Re: unknown directive "js_include"

2018-04-12 Thread Dmitry Volyntsev



On 12.04.2018 17:28, Dineshkumar wrote:

Hi Dmitry,

The module has been loaded in the nginx.conf file using the following
load_module modules/ngx_http_js_module.so;

and the compile module files are available in the path as well.


Please note that RHEL5 packets are outdated (js_include was not 
available back then). I would recommend using RHEL 6 or 7.





Posted at Nginx Forum: 
https://forum.nginx.org/read.php?2,279415,279417#msg-279417

___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx


___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx


Re: nginScript question

2018-04-18 Thread Dmitry Volyntsev



On 17.04.2018 21:30, djcza...@gmail.com wrote:

Is there a roadmap for nginScript


There is. The short term preliminary plan is:
 - stream integration refactoring to match the way it done in
 http
 - access to shared memory storage
 - base64 encode
___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx


Re: redirect based on file content

2018-07-16 Thread Dmitry Volyntsev

You can try to use njs here:

http://nginx.org/en/docs/http/ngx_http_js_module.html
http://nginx.org/en/docs/njs/njs_api.html#http - more about r object.

nginx.conf:
http {
js_include http.njs;
...
server {
listen 9000;
location / {
js_content redirect;
}
}
}

http.njs:
function redirect(r) {
var fs = require('fs');
var body = fs.readFileSync('/redirects/' + r.uri);
var parts = body.split(' ');
var code = Number(parts[0]);
var uri = parts[1];

r.return(code, uri);
}


On 16.07.2018 17:38, Torsten Curdt wrote:
I want to have files in the filesystem that specify the response code 
and redirect location instead of relying on the nginx configuration for it.


Imagine a file foo.ext looking like:

   301 https://some.host.com/foo.bla

On a GET of foo.ext it should result in a 301 to 
https://some.host.com/foo.bla


So far I haven't found a module for this. I presume it should not be too 
terribly hard to write a module for it but maybe I missed something? So 
I thought I rather double check if there is an easier route.


Any thoughts?

cheers,
Torsten


___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx


___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx

Re: sub_filter not working on JSON file

2018-08-02 Thread Dmitry Volyntsev



On 02.08.2018 16:46, Friscia, Michael wrote:
I’m trying to figure out why my sub_filter is not working on a JSON 
file. I do have application/json and text/json listed in the 
sub_filter_types but the simple string replace is not happening. It 
causes me to think that for whatever reason, Nginx is not seeing this 
file as JSON. Is there a way to output what mime type the file from the 
upstream server is so I can make sure I have the right filter type?


Or, is there something I should also be doing to make the sub_filter 
work on a JSON file?




Hi,

Do not forget to configure sub_filter_types appropriately.




___

Michael Friscia

Office of Communications

Yale School of Medicine

(203) 737-7932 - office

(203) 931-5381 - mobile

http://web.yale.edu 



___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx


___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx

Re: How to install njs after building from sources

2018-08-08 Thread Dmitry Volyntsev



On 08.08.2018 17:06, Mustafa Aldemir wrote:

Hello,

I built NGINX and njs from sources. Now I have njs executable and some 
static object files under ~/njs/build.


How should I install njs or configure NGINX to run with njs?



Hi Mustafa,

Please, use the instruction from here
http://nginx.org/en/docs/njs_about.html#install_sources






regards,
mustafa


___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx


___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx

Re: nginx-1.11.0

2016-05-25 Thread Dmitry Volyntsev


On 25.05.2016 12:01, Alexey Genus wrote:

 > *) Feature: the "map" directive supports combinations of multiple
variables as resulting values.
Does this mean this ticket can be resolved?
https://trac.nginx.org/nginx/ticket/663


Yes, it is resolved.

___
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx


njs-0.8.0

2023-07-06 Thread Dmitry Volyntsev

Hello,

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

Notable new features:
- shared dictionaries:
Shared dictionary keeps the key-value pairs shared between worker
processes. This allows to cache data in memory and share it between
workers.

: example.conf:
:   # Creates a 1Mb dictionary with string values,
:   # removes key-value pairs after 60 seconds of inactivity:
:   js_shared_dict_zone zone=foo:1M timeout=60s;
:
:   # Creates a 512Kb dictionary with string values,
:   # forcibly removes oldest key-value pairs when the zone is overflowed:
:   js_shared_dict_zone zone=bar:512K timeout=30s evict;
:
:   # Creates a 32Kb permanent dictionary with numeric values:
:   js_shared_dict_zone zone=num:32k type=number;
:
: example.js:
:function get(r) {
:r.return(200, ngx.shared.foo.get(r.args.key));
:}
:
:function set(r) {
:r.return(200, ngx.shared.foo.set(r.args.key, r.args.value));
:}
:
:function delete(r) {
:r.return(200, ngx.shared.bar.delete(r.args.key));
:}
:
:function increment(r) {
:r.return(200, ngx.shared.num.incr(r.args.key, 2));
:}

Learn more about njs:

- Overview and introduction:
 https://nginx.org/en/docs/njs/
- NGINX JavaScript in Your Web Server Configuration:
 https://youtu.be/Jc_L6UffFOs
- Extending NGINX with Custom Code:
 https://youtu.be/0CVhq4AUU7M
- Using node modules with njs:
 https://nginx.org/en/docs/njs/node_modules.html
- Writing njs code using TypeScript definition files:
 https://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:
 https://mailman.nginx.org/mailman/listinfo/nginx-devel

Additional examples and howtos can be found here:

- Github:
 https://github.com/nginx/njs-examples

Changes with njs 0.8.06 Jul 2023

nginx modules:

*) Change: removed special treatment of forbidden headers in Fetch API
   introduced in 0.7.10.

*) Change: removed deprecated since 0.5.0 r.requestBody and
   r.responseBody in HTTP module.

*) Change: throwing an exception in r.internalRedirect() while
   filtering in HTTP module.

*) Feature: introduced global nginx properties.
ngx.build - an optional nginx build name, corresponds to
--build=name argument of configure script, by default is "".
ngx.conf_file_path - the file path to current nginx configuration
file.
ngx.error_log_path - the file path to current error log file.
ngx.prefix - the directory that keeps server files.
ngx.version - the nginx version as a string, for example: "1.25.0".
ngx.version_number - the nginx version as a number, for example:
1025000.
ngx.worker_id - corresponds to an nginx internal worker id.
   The value is between 0 and worker_processes - 1.

*) Feature: introduced js_shared_dict_zone directive.
The directive allows to declare a dictionary that is shared 
among the

working processes.

*) Improvement: added compile-time options to disable njs modules.
For example to disable libxslt related code:
NJS_LIBXSLT=NO ./configure  .. --add-module=/path/to/njs/module

*) Bugfix: fixed r.status setter when filtering in HTTP module.

*) Bugfix: fixed setting of Location header in HTTP module.

Core:

*) Change: native methods are provided with retval argument.
   This change breaks compatibility with C extension for njs
   requiring to modify the code.

*) Change: non-compliant deprecated String methods were removed.
The following methods were removed: String.bytesFrom(),
String.prototype.fromBytes(), String.prototype.fromUTF8(),
String.prototype.toBytes(), String.prototype.toUTF8(),
String.prototype.toString(encoding).

*) Change: removed support for building with GNU readline.

*) Feature: added Array.from(), Array.prototype.toSorted(),
Array.prototype.toSpliced(), Array.prototype.toReversed().

*) Feature: added %TypedArray%.prototype.toSorted(),
%TypedArray%.prototype.toSpliced(),
%TypedArray%.prototype.toReversed().

*) Feature: added CryptoKey properties in WebCrypto.
The following properties for CryptoKey were added:
algorithm, extractable, type, usages.

*) Bugfix: fixed retval of crypto.getRandomValues().

*) Bugfix: fixed evaluation of computed property names with function
   expressions.

*) Bugfix: fixed implicit name for a function expression declared in
   arrays.

*) Bugfix: fixed parsing of for-in loops.

*) Bugfix: fixed Date.parse() with ISO-8601 format and UTC time
   offset.
___
nginx mailing list
nginx@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx


njs-0.8.1

2023-09-12 Thread Dmitry Volyntsev

Hello,

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

Notable new features:
- Periodic code execution:
js_periodic direcrive specifies a content handler to run at regular 
interval.
The handler receives a session object as its first argument, it also has 
access

to global objects such as ngx.

: example.conf:
:  location @periodics {
:# to be run at 1 minute intervals in worker process 0
:js_periodic main.handler interval=60s;
:
:# to be run at 1 minute intervals in all worker processes
:js_periodic main.handler interval=60s worker_affinity=all;
:
:# to be run at 1 minute intervals in worker processes 1 and 3
:js_periodic main.handler interval=60s worker_affinity=0101;
:
:resolver 10.0.0.1;
:js_fetch_trusted_certificate /path/to/ISRG_Root_X1.pem;
:  }
:
: example.js:
:  async function handler(s) {
:let reply = async ngx.fetch('https://nginx.org/en/docs/njs/');
:let body = async reply.text();
:
:ngx.log(ngx.INFO, body);
:  }

Learn more about njs:

- Overview and introduction:
  https://nginx.org/en/docs/njs/
- NGINX JavaScript in Your Web Server Configuration:
  https://youtu.be/Jc_L6UffFOs
- Extending NGINX with Custom Code:
  https://youtu.be/0CVhq4AUU7M
- Using node modules with njs:
  https://nginx.org/en/docs/njs/node_modules.html
- Writing njs code using TypeScript definition files:
  https://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:
  https://mailman.nginx.org/mailman/listinfo/nginx-devel

Additional examples and howtos can be found here:

- Github:
  https://github.com/nginx/njs-examples

Changes with njs 0.8.1   12 Sep 2023

nginx modules:

*) Feature: introduced js_periodic directive.
The directive specifies a JS handler to run at regular intervals.

*) Feature: implemented items() method for a shared dictionary.
   The method returns all the non-expired key-value pairs.

*) Bugfix: fixed size() and keys() methods of a shared dictionary.

*) Bugfix: fixed erroneous exception in r.internalRedirect()
   introduced in 0.8.0.

Core:

*) Bugfix: fixed incorrect order of keys in
   Object.getOwnPropertyNames().
___
nginx mailing list
nginx@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx


Re: njs-0.8.1

2023-09-12 Thread Dmitry Volyntsev


On 12.09.2023 16:48, Manuel wrote:

Hello,

thank you for all the work for njs.
We will probably use it in one of our next projects.

Regarding the example


let body = async reply.text();

should it be const body = await reply.next(); ?

Kind regards,
Manuel


Hi Manuel, you you are right. It is a typo.






Am 13.09.2023 um 01:10 schrieb Dmitry Volyntsev :

Hello,

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

Notable new features:
- Periodic code execution:
js_periodic direcrive specifies a content handler to run at regular interval.
The handler receives a session object as its first argument, it also has access
to global objects such as ngx.

: example.conf:
:  location @periodics {
:# to be run at 1 minute intervals in worker process 0
:js_periodic main.handler interval=60s;
:
:# to be run at 1 minute intervals in all worker processes
:js_periodic main.handler interval=60s worker_affinity=all;
:
:# to be run at 1 minute intervals in worker processes 1 and 3
:js_periodic main.handler interval=60s worker_affinity=0101;
:
:resolver 10.0.0.1;
:js_fetch_trusted_certificate /path/to/ISRG_Root_X1.pem;
:  }
:
: example.js:
:  async function handler(s) {
:let reply = async ngx.fetch('https://nginx.org/en/docs/njs/');
:let body = async reply.text();
:
:ngx.log(ngx.INFO, body);
:  }

Learn more about njs:

- Overview and introduction:
 https://nginx.org/en/docs/njs/
- NGINX JavaScript in Your Web Server Configuration:
 https://youtu.be/Jc_L6UffFOs
- Extending NGINX with Custom Code:
 https://youtu.be/0CVhq4AUU7M
- Using node modules with njs:
 https://nginx.org/en/docs/njs/node_modules.html
- Writing njs code using TypeScript definition files:
 https://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:
 https://mailman.nginx.org/mailman/listinfo/nginx-devel

Additional examples and howtos can be found here:

- Github:
 https://github.com/nginx/njs-examples

Changes with njs 0.8.1   12 Sep 2023

   nginx modules:

   *) Feature: introduced js_periodic directive.
   The directive specifies a JS handler to run at regular intervals.

   *) Feature: implemented items() method for a shared dictionary.
  The method returns all the non-expired key-value pairs.

   *) Bugfix: fixed size() and keys() methods of a shared dictionary.

   *) Bugfix: fixed erroneous exception in r.internalRedirect()
  introduced in 0.8.0.

   Core:

   *) Bugfix: fixed incorrect order of keys in
  Object.getOwnPropertyNames().
___
nginx mailing list
nginx@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx

___
nginx mailing list
nginx@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx

___
nginx mailing list
nginx@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx


Re: Help

2023-09-17 Thread Dmitry Volyntsev


On 17.09.2023 06:39, Revvy via nginx wrote:
Sep 17 13:36:52 toronto-srv-03 nginx[127394]: nginx: [emerg] dlopen() 
"/etc/nginx/modules/ngx_http_js_module.so" failed 
(/etc/nginx/modules/ngx_http_js_module.so: undefined symbol: 
EVP_PKEY_CTX_set1_hkdf_salt) in /etc/nginx/nginx.conf:4





Hi Revvy,

Can you please share your operation system details (name, version) and 
the output of the following command: nginx -V. Also, I would like to 
know the OpenSSL library you are using.

___
nginx mailing list
nginx@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx


Re: Help

2023-09-17 Thread Dmitry Volyntsev


On 17.09.2023 11:28, Revvy wrote:


$ uname -a
Linux toronto-srv-03 6.1.0-12-amd64 #1 SMP PREEMPT_DYNAMIC Debian 
6.1.52-1 (2023-09-07) x86_64 GNU/Linux


$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux 12 (bookworm)
Release:    12
Codename:   bookworm

$ /sbin/nginx -V
nginx version: nginx/1.24.0
built by gcc 10.2.1 20210110 (Debian 10.2.1-6)
built with OpenSSL 1.1.1n  15 Mar 2022
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx 
--modules-path=/usr/lib/nginx/modules 
--conf-path=/etc/nginx/nginx.conf 
--error-log-path=/var/log/nginx/error.log 
--http-log-path=/var/log/nginx/access.log 
--pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock 
--http-client-body-temp-path=/var/cache/nginx/client_temp 
--http-proxy-temp-path=/var/cache/nginx/proxy_temp 
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp 
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp 
--http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx 
--group=nginx --with-compat --with-file-aio --with-threads 
--with-http_addition_module --with-http_auth_request_module 
--with-http_dav_module --with-http_flv_module 
--with-http_gunzip_module --with-http_gzip_static_module 
--with-http_mp4_module --with-http_random_index_module 
--with-http_realip_module --with-http_secure_link_module 
--with-http_slice_module --with-http_ssl_module 
--with-http_stub_status_module --with-http_sub_module 
--with-http_v2_module --with-mail --with-mail_ssl_module --with-stream 
--with-stream_realip_module --with-stream_ssl_module 
--with-stream_ssl_preread_module --with-cc-opt='-g -O2 
-ffile-prefix-map=/data/builder/debuild/nginx-1.24.0/debian/debuild-base/nginx-1.24.0=. 
-fstack-protector-strong -Wformat -Werror=format-security 
-Wp,-D_FORTIFY_SOURCE=2 -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now 
-Wl,--as-needed -pie'


$ openssl version
OpenSSL 3.0.9 30 May 2023 (Library: OpenSSL 3.0.9 30 May 2023)

I think I see the problem now. I am using Debian /bookworm/ and the 
official nginx repos for Debian /bookworm/.


$ cat /etc/apt/sources.list.d/nginx.list
deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] 
http://nginx.org/packages/debian bookworm nginx


That version is built with OpenSSL 1.1.1n and the updated Debian 
bookworm version is OpenSSL 3.0.9. Is that the problem?




Yes, this looks like the reason for a problem .


Another thing I should have mentioned is this issue only popped up 
after I upgraded the nginx-module-njs and nginx packages, the same 
configuration was working fine before.



Can you, please, share the current version of njs packet  and the 
version you used before?




On 9/17/23 12:28, Dmitry Volyntsev wrote:


On 17.09.2023 06:39, Revvy via nginx wrote:
Sep 17 13:36:52 toronto-srv-03 nginx[127394]: nginx: [emerg] 
dlopen() "/etc/nginx/modules/ngx_http_js_module.so" failed 
(/etc/nginx/modules/ngx_http_js_module.so: undefined symbol: 
EVP_PKEY_CTX_set1_hkdf_salt) in /etc/nginx/nginx.conf:4





Hi Revvy,

Can you please share your operation system details (name, version) 
and the output of the following command: nginx -V. Also, I would like 
to know the OpenSSL library you are using.



___
nginx mailing list
nginx@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx


Re: Debugging Nginx Memory Spikes on Production Servers

2023-09-20 Thread Dmitry Volyntsev


On 20.09.2023 20:37, Lance Dockins wrote:
So I guess my question at the moment is whether endless memory use 
growth being reported by njs.memoryStats.size after file writes is 
some sort of false positive tied to quirks in how memory use is being 
reported or whether this is indicative of a memory leak?  Any insight 
would be appreicated.


Hi Lance,
The reason njs.memoryStats.size keeps growing is because NJS uses arena 
memory allocator linked to a current request and a new object 
representing memoryStats structure is returned every time 
njs.memoryStats is accessed. Currently NJS does not free most of the 
internal objects and structures until the current request is destroyed 
because it is not intended for a long running code.


Regarding the sudden memory spikes, please share some details about JS 
code you are using.
One place to look is to analyze the amount of traffic that goes to NJS 
locations and what exactly those location do.

___
nginx mailing list
nginx@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx


Re: Debugging Nginx Memory Spikes on Production Servers

2023-09-21 Thread Dmitry Volyntsev
 Nginx layer instead of at 
the NJS layer, it seems like that could be a lot more sensitive to 
memory use.  Right now, if my understanding is correct, the only 
option that I’d even have would be to just stop doing POST body 
handling if the POST body is above a certain total size.  I guess if 
there was some way to forcibly free memory, that would help too.  But 
I don’t think that that is as common of a problem as having to deal 
with very large query strings that some third party appends to a URL 
(probably maliciously) and/or a very large file upload attached to a 
multipart POST.  So the only concern that I’d have about memory in a 
situation where I don’t have to worry about memory when parsing a 
larger file woudl be if multiple js_sets and such would just keep 
spawning VMs and accumulating memory during a single request.


Any thoughts?

—
Lance Dockins


On Thursday, Sep 21, 2023 at 1:45 AM, Dmitry Volyntsev
 wrote:

On 20.09.2023 20:37, Lance Dockins wrote:

So I guess my question at the moment is whether endless memory use
growth being reported by njs.memoryStats.size after file writes is
some sort of false positive tied to quirks in how memory use is
being
reported or whether this is indicative of a memory leak?  Any
insight
would be appreicated.


Hi Lance,
The reason njs.memoryStats.size keeps growing is because NJS uses
arena
memory allocator linked to a current request and a new object
representing memoryStats structure is returned every time
njs.memoryStats is accessed. Currently NJS does not free most of the
internal objects and structures until the current request is
destroyed
because it is not intended for a long running code.

Regarding the sudden memory spikes, please share some details
about JS
code you are using.
One place to look is to analyze the amount of traffic that goes to
NJS
locations and what exactly those location do.


___
nginx mailing list
nginx@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx


Re: Debugging Nginx Memory Spikes on Production Servers

2023-09-21 Thread Dmitry Volyntsev


On 9/21/23 4:41 PM, Lance Dockins wrote:

That’s good info.  Thank you.

I have been doing some additional testing since my email last night 
and I have seen enough evidence to believe that file I/O in NJS is 
basically the source of the memory issues.  I did some testing with 
very basic commands like readFileSync and Buffer + readSync and in all 
cases, the memory footprint when doing file handling in NJS is massive.


Just doing this:

let content = fs.readFileSync(path/to//file);
let parts = content.split(boundary);

Resulted in memory use that was close to a minimum of 4-8x the size of 
the file during my testing.  We do have an upper bound on files that 
can be uploaded and that does contain this somwhat but it’s not hard 
for a larger request that is 99% file attachment to use exhorbitant 
amounts of memory.




Regarding the task at hand, do you check for Content-Type of the POST 
body? So you can exclude anything except probably 
application/x-www-form-urlencoded. At least what I see in lua: the 
handler is only looking for application/x-www-form-urlencoded and not 
multipart/form-data.


https://github.com/openresty/lua-nginx-module/blob/c89469e920713d17d703a5f3736c9335edac22bf/src/ngx_http_lua_args.c#L171


 I actually tried doing a Buffer + readSync variation on the same 
thing and the memory footprint was actually FAR FAR worse when I did that.




As of now, the resulting memory consumption will depend heavily on the 
boundary.


In worst case, for 1mb of memory file that is split into 1 character 
array, You will get ~16x memory consumed, because every 1 byte character 
will be put into a njs_value_t structure.


With larger chunks the situation will be less extreme. Right now we are 
implementing a way to deduplicate identical strings, this may help in 
some situations.


The 4-8x minimum memory commit seems like a problem to me just 
generally.  But the fact that readSync doesn’t seem to be any better 
on memory (much worse actually) basically means that NJS is only safe 
to use for processing smaller files (or POST bodies) right now. 
 There’s just no good way to keep data that you don’t care about in a 
file from occupying excessive amounts of memory that can’t be 
reclaimed. If there is no way to improve the memory footprint when 
handling files (or big strings), no memory conservative way to stream 
a file through some sort of buffer, and no first-party utility for 
providing parsed POST bodies right now,
then it might be worth the time to put some notes in the NJS docs that 
the fs module may not be appropriate for larger files (e.g. files over 
1mb).


For what it’s worth, I’d also love to see some examples of how to 
properly use fs.readSync in the NJS examples docs.  There really 
wasn’t much out there for that for NJS (or even in a lot of the Node 
docs) so I can’t say that my specific test implementation for that was 
ideal.  But that’s just above and beyond the basic problems that I’m 
seeing with memory use with any form of file I/O at all (since the 
memory problems seem to be persistent whether doing reads or even log 
writes).


—
Lance Dockins


On Thursday, Sep 21, 2023 at 5:01 PM, Dmitry Volyntsev
 wrote:

On 9/21/23 6:50 AM, Lance Dockins wrote:

Hi Lance,

See my comments below.


Thanky you, Dmitry.

One question before I describe what we are doing with NJS.  I did
read
about the VM handling process before switching from Lua to NJS
and it
sounded very practical but my current understanding is that there
could be multiple VM’s instantiated for a single request.  A js_set,
js_content, and js_header_filter directive that applies to a single
request, for example, would instantiate 3 VMs.  And were you to need
to set multiple variables with js_set, then keep adding to that #
of VMs.



This is not correct. For js_set, js_content and js_header_filter
there
is only a single VM.
The internalRedirect() is the exception, because a VM does not
survive
it, but the previous VMs will not be freed until current request is
finished. BTW, a VM instance itself is pretty small in size (~2kb)
so it
should not be a problem if you have a reasonable number of redirects.




My original understanding of that was that those VMs would be
destroyed once they exited so even if you had multiple VMs
instantiated per request, the memory impact would not be
cumulative in
a single request.  Is that understanding correct?  Or are you saying
that each VM accumulates more and more memory until the entire
request
completes?

As far as how we’re using NJS, we’re mostly using it for header
filters, internal redirection, and access control.  So there really
shouldn’t be a threat to memory in most instances unless we’re not
just dealing with a single request memory leak inside of a VM but
also
a memory leak that involves every VM that NJS instantiates

Re: Debugging Nginx Memory Spikes on Production Servers

2023-09-26 Thread Dmitry Volyntsev


On 9/26/23 8:30 AM, Lance Dockins wrote:
Up until now, I had assumed that string.match types of statements were 
just transparently calling PCRE behind the scenes so that the 
associated memory from the PCRE call was being freed after use.  Maybe 
that’s not even an accurate read on how Nginx is using PCRE but that’s 
how I envisioned it.


String.prototype.match() returns an array of matched elements. See 
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match. 
It means that many calls to that method that have positive matches 
consume memory proportional to the size of the resulting chunks. But if 
the match fails it should not consume (much) memory. So if you have a 
bunch of if/then clauses until the first match it should not be a 
problem (if not let me know).



In general doing a routing in NJS (or any other scripting) is not 
recommended, because it complicates the native nginx location routing. 
Could you please explain what exactly you want to do with NJS RegExp 
what nginx cannot do with regexp locations?




In any case, that lead me to a few questions.

 1. How does keepalive affect these VMs?  I realize that keepalive is
for the connection rather than the request, but I still wanted to
confirm that VM’s are not sticking around occupying memory after
the request completes due to keepavlive settings.



All the current VMs are destroyed when a current HTTP request is finalized.



 1.   We have a mix of fast requests and long running requests (e.g
5-10s) so if enough long running requests build up at the same
time that a flood of very fast requests come in, NJS could
certainly burn out a lot of memory under the current conditions as
I understand it.  If there were a lot of large file downloads,
those would also occupy memory for the entirety of the download if
I understand correctly.
 2. Is it possible to adjust the NJS codebase to free memory for the
actual if condition and for string matches after they’ve run as
long as they didn’t include a variable assignment inside of the
actual if condition?  I’m not talking about whatever is in the
block content - just the actual condition.  Given how likely it is
for people to use basic if conditions and string matches in NJS,
that seems like it might be a stopgap measure that reduces the
memory footprint without having to build full garbage collection.


The problem with JS Regexps is that they produce a lot of intermediary 
objects. Because most of the RegExp related calls end up 
RegExp.prototype.exec() which return a large object representing the 
result of PCRE matching.



One way to mediate the problem could be using RegExp.prototype.test() 
which return just a boolean.
But I need to improve it first, because right now it uses 
RegExp.prototype.exec() internally. The reason RegExp.prototype.test() 
will be easier to improve is that I can be sure that the resulting 
object can be freed right away. In addition to that I plan to improve 
the memory consumption for RegExp.prototype.exec() result, thanks for 
reporting.





 1. Is there any workaround for this type of memory problem other than
just to force the use of an internalRedirect to drop the existing
VM and create a new one?

 1. Could it make sense to allow for a directive that would force the
destruction and regeneration of a new JS VM?  That wouldn’t solve
the memory leak that bulids to 1mb per request but it would
shorten its lifetime (which could ease memory pressure in
situations where there are some long running requests holding open
the requests)


I do not think so.

___
nginx mailing list
nginx@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx


njs-0.8.2

2023-10-24 Thread Dmitry Volyntsev
Hello,

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

Notable new features:
- console object in nginx modules:
Console object is a global object that provides access to the environment's
console. It can be used to log information to the console, using
console.log(), console.info(), console.warn(), console.error() methods.

This feature unifies logging in nginx modules and njs CLI.

Learn more about njs:

- Overview and introduction:
  https://nginx.org/en/docs/njs/
- NGINX JavaScript in Your Web Server Configuration:
  https://youtu.be/Jc_L6UffFOs
- Extending NGINX with Custom Code:
  https://youtu.be/0CVhq4AUU7M
- Using node modules with njs:
  https://nginx.org/en/docs/njs/node_modules.html
- Writing njs code using TypeScript definition files:
  https://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:
  https://mailman.nginx.org/mailman/listinfo/nginx-devel

Additional examples and howtos can be found here:

- Github:
  https://github.com/nginx/njs-examples

Changes with njs 0.8.2   24 Oct 2023

nginx modules:

*) Feature: introduced console object. The following methods
   were introduced: error(), info(), log(), time(), timeEnd(),
   warn().

*) Bugfix: fixed HEAD response handling with large Content-Length
   in fetch API.

*) Bugfix: fixed items() method for a shared dictionary.

*) Bugfix: fixed delete() method for a shared dictionary.

Core:

*) Feature: extended "fs" module. Added existsSync().

*) Bugfix: fixed "xml" module. Fixed broken XML exception handling
   in parse() method.

*) Bugfix: fixed RegExp.prototype.exec() with global regexp and
   unicode input.

*) Bugfix: fixed return statement parsing with invalid expression.
___
nginx mailing list
nginx@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx


njs-0.8.3

2024-02-07 Thread Dmitry Volyntsev

Hello,

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

This release focuses on stabilization of recently released features
and fixing bugs found by various fuzzers.

Learn more about njs:

- Overview and introduction:
  https://nginx.org/en/docs/njs/
- NGINX JavaScript in Your Web Server Configuration:
  https://youtu.be/Jc_L6UffFOs
- Extending NGINX with Custom Code:
  https://youtu.be/0CVhq4AUU7M
- Using node modules with njs:
  https://nginx.org/en/docs/njs/node_modules.html
- Writing njs code using TypeScript definition files:
  https://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:
  https://mailman.nginx.org/mailman/listinfo/nginx-devel

Additional examples and howtos can be found here:

- Github:
  https://github.com/nginx/njs-examples

Changes with njs 0.8.3   07 Feb 2024

    nginx modules:

    *) Bugfix: fixed Headers.set().

    *) Bugfix: fixed js_set with Buffer values.

    *) Bugfix: fixed clear() method of a shared dictionary when
   timeout is not specified.

    *) Bugfix: fixed stub_status statistic when js_periodic is
   enabled.

    Core:

    *) Bugfix: fixed building with libxml2 2.12 and later.

    *) Bugfix: fixed Date constructor for overflows and with
   NaN values.

    *) Bugfix: fixed underflow in querystring.parse().

    *) Bugfix: fixed potential buffer overread in
   String.prototype.match().

    *) Bugfix: fixed parsing of for-in loops.

    *) Bugfix: fixed parsing of hexadecimal, octal, and binary
   literals with no digits.
___
nginx mailing list
nginx@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx


njs-0.8.4

2024-04-16 Thread Dmitry Volyntsev

Hello,

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

This release introduced the initial QuickJS engine support in CLI
as well as regular bugfixes.

Notable new features:
- QuickJS in njs CLI:
: $ ./configure --cc-opt="-I/path/to/quickjs -L/path/to/quickjs" && make njs
: $ ./build/njs -n QuickJS
:
: >> new Map()
: [object Map]

Learn more about njs:

- Overview and introduction:
  https://nginx.org/en/docs/njs/
- NGINX JavaScript in Your Web Server Configuration:
  https://youtu.be/Jc_L6UffFOs
- Extending NGINX with Custom Code:
  https://youtu.be/0CVhq4AUU7M
- Using node modules with njs:
  https://nginx.org/en/docs/njs/node_modules.html
- Writing njs code using TypeScript definition files:
  https://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:
  https://mailman.nginx.org/mailman/listinfo/nginx-devel

Additional examples and howtos can be found here:

- Github:
  https://github.com/nginx/njs-examples

Changes with njs 0.8.4   16 Apr 2024

    nginx modules:

    *) Feature: allowing to set Server header for outgoing headers.

    *) Improvement: validating URI and args arguments in r.subrequest().

    *) Improvement: checking for duplicate js_set variables.

    *) Bugfix: fixed clear() method of a shared dictionary without
   timeout introduced in 0.8.3.

    *) Bugfix: fixed r.send() with Buffer argument.

    Core:

    *) Feature: added QuickJS engine support in CLI.

    *) Bugfix: fixed atob() with non-padded base64 strings.
___
nginx mailing list
nginx@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx


NGINX JavaScript (njs) has migrated to Github

2024-06-05 Thread Dmitry Volyntsev

Hello,

This week we took the next step in our commitment to the Open Source
community by moving the official njs code repository to GitHub
(https://github.com/nginx/njs).

As part of the move, we have revamped our testing infrastructure and added
clearer guidelines around installation, building, and contributing source
code. We believe these changes will serve two purposes:

1. Modernize njs by creating a single place for the community to
contribute, ask questions, and provide feedback.

2. Underscore our commitment to openness, consistency, transparency,
and fairness in our acceptance of contributions.

Importantly, these changes do not impact core njs source code,
functionality, or license in any way. They simply do a better job at
codifying existing guidelines, while providing a modern approach for
managing the project and community.

Please refer to the following files for more details:

README.md

https://github.com/nginx/njs/blob/master/README.md

Provides basic information on what NJS is, how it is used (including links
to sample code & projects), installing, debugging, building from source,
etc...

CONTRIBUTING.md

https://github.com/nginx/njs/blob/master/CONTRIBUTING.md

Provides clear guidelines for asking questions, suggesting improvements,
and contributing code. You will also find our code and git style guides
here.

CODE_OF_CONDUCT.md

https://github.com/nginx/njs/blob/master/CODE_OF_CONDUCT.md

Our pledge, policies, and guidelines for community etiquette, along with
enforcement procedures.

SECURITY.md

https://github.com/nginx/njs/blob/master/SECURITY.md

Our security policy, including what constitutes a security concern and
procedures for reporting vulnerabilities.

SUPPORT.md

https://github.com/nginx/njs/blob/master/SUPPORT.md

A list of all support resources available to the community.


For additional information on F5 NGINX’s commitment to our Open Source
projects and communities, please see:

https://www.f5.com/company/blog/nginx/meetup-recap-nginxs-commitments-to-the-open-source-community

We look forward to your feedback, questions, and contributions as we work
together to make njs even faster, more powerful, and feature-rich!
___
nginx mailing list
nginx@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx


njs-0.8.5

2024-06-25 Thread Dmitry Volyntsev

Hello,

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

Learn more about njs:

- Overview and introduction:
  https://nginx.org/en/docs/njs/
- NGINX JavaScript in Your Web Server Configuration:
  https://youtu.be/Jc_L6UffFOs
- Extending NGINX with Custom Code:
  https://youtu.be/0CVhq4AUU7M
- Using node modules with njs:
  https://nginx.org/en/docs/njs/node_modules.html
- Writing njs code using TypeScript definition files:
  https://nginx.org/en/docs/njs/typescript.html

Feel free to try it and give us feedback on:

- Github:
  https://github.com/nginx/njs/issues

Additional examples and howtos can be found here:

- Github:
  https://github.com/nginx/njs-examples

Changes with njs 0.8.5   25 Jun 2024

    nginx modules:

    *) Change: r.variables.var, r.requestText, r.responseText,
   s.variables.var, and the "data" argument of the s.on() callback
   with "upload" or "download" event types will now convert bytes
   invalid in UTF-8 encoding into the replacement character. When
   working with binary data, use r.rawVariables.var, r.requestBuffer,
   r.responseBuffer, s.rawVariables.var, and the "upstream" or
   "downstream" event type for s.on() instead.

    *) Feature: added timeout argument for shared dictionary methods
   add(), set() and incr().

    *) Bugfix: fixed checking for duplicate js_set variables.

    *) Bugfix: fixed request Host header when the port is non-standard.

    *) Bugfix: fixed handling of a zero-length request body in ngx.fetch()
   and r.subrequest().

    *) Bugfix: fixed heap-buffer-overflow in Headers.get().

    *) Bugfix: fixed r.subrequest() error handling.

    Core:

    *) Feature: added zlib module for QuickJS engine.

    *) Bugfix: fixed zlib.inflate().

    *) Bugfix: fixed String.prototype.replaceAll() with zero-length
   argument.

    *) Bugfix: fixed retval handling after an exception in
   Array.prototype.toSpliced(), Array.prototype.toReversed(),
   Array.prototype.toSorted().

    *) Bugfix: fixed RegExp.prototype[@@replace]() with replacements
   containing "$'", "$\`" and strings with Unicode characters.

    *) Bugfix: fixed a one-byte overread in decodeURI() and
   decodeURIComponent().

    *) Bugfix: fixed tracking of argument scope.

    *) Bugfix: fixed integer overflow in Date.parse().
___
nginx mailing list
nginx@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx