1) Ensuring that consistent prefixes are used:
"http js" in HTTP module and "stream js" in Stream module.
2) Added debug for every event/callback handler entrance.
3) Added debug with a method name for every JS call.
Tests: fixed incr() tests for a shared dictionary.
Previously, the incr() method called SharedDict.incr() with a NaN value
as a second argument because parseInt(undefined) returns NaN.
The test itself failed to capture the issue because it matches the whole
HTTP response and the pattern itself was too short, so it matched
accidentally.
Modules: added a session object for js_periodic handler.
Now js_periodic handler is provided with a session object as its first
argument. Session object can be used to access variables created with
js_set, js_var or map directives.
Modules: added worker_affinity parameter for js_periodic directive.
worker_affinity specifies on what set of workers the js_periodic handler
should be executed. By default the js_handler is executed only on worker 0.
The parameter accepts a binary mask or "all" to specify all workers.
example.conf:
worker_processes 4;
...
location @periodics {
# to be run at 1 minute intervals in worker 0
js_periodic main.handler interval=60s;
# to be run at 1 minute intervals in all the workers
js_periodic main.handler interval=60s worker_affinity=all;
# to be run at 1 minute intervals in workers 1 and 3
js_periodic main.handler interval=60s worker_affinity=0101;
}
Dmitry Volyntsev [Thu, 31 Aug 2023 01:59:28 +0000 (18:59 -0700)]
Modules: fixed size() and keys() methods of a shared dictionary.
Previously, these methods did not take into the account exprired
entries. The expired entries appear in js_shared_dict_zone when timeout
directive is specified as the expired elements are not removed at the
moment they become stale right away.
Dmitry Volyntsev [Tue, 22 Aug 2023 18:13:09 +0000 (11:13 -0700)]
Modules: introduced js_periodic directive.
The directive specifies a JS handler to run at regular intervals. The JS
handler will be executed in each worker process. The handler receives no
arguments. It has access to ngx and other global objects.
example.conf:
location @periodics {
# Specifies a JS handler to be run at 1 minute intervals
js_periodic main.handler interval=60s jitter=5s;
Previously, r.headersOut['Last-Modified'] setter did not update
r->headers_out.last_modified. As a result a client might get two
Last-Modified headers.
The directive allows to declare a dictionary that is shared among the
working processes. A dictionary expects strings as keys. It stores
string or number as values. The value type is declared using
type= argument of the directive. The default type is string.
example.conf:
# Declares a shared dictionary of strings of size 1 Mb that
# removes key-value after 60 seconds of inactivity.
js_shared_dict_zone zone=foo:1M timeout=60s;
# Declares a shared dictionary of strings of size 512Kb that
# forcibly remove oldest key-value pairs when memory is not enough.
js_shared_dict_zone zone=bar:512K timeout=30s evict;
# Declares a permanent number shared dictionary of size 32Kb.
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));
}
In collaboration with Artem S. Povalyukhin, Jakub Jirutka and
洪志道 (Hong Zhi Dao).
Dmitry Volyntsev [Thu, 22 Jun 2023 22:40:36 +0000 (15:40 -0700)]
Fetch: fixed setting of Content-Type header.
Previously, Content-Type was set unconditionally to
"text/plain;charset=UTF-8" when fetch request contained a string body.
This may overlap with user's Content-Type.
The fix is to set the header only if it was not set before.
Dmitry Volyntsev [Wed, 21 Jun 2023 23:30:00 +0000 (16:30 -0700)]
WebCrypto: added back custom exception types using new public API.
In f1432043a6a4, when rewriting webcrypto module using public API all
the exceptions types were squashed into a single Error type. This patch
reintroduces the standard exception types back using new API.
Dmitry Volyntsev [Wed, 21 Jun 2023 23:29:51 +0000 (16:29 -0700)]
QueryString: added back custom exception types using new public API.
In fd956d2a25a3, when rewriting querystring module using public API all
the exceptions types were squashed into a single Error type. This patch
reintroduces the standard exception types back using new API.
Dmitry Volyntsev [Wed, 21 Jun 2023 23:29:48 +0000 (16:29 -0700)]
Crypto: added back custom exception types using new public API.
In b2cbf06ba017, when rewriting crypto module using public API all the
exceptions types were squashed into a single Error type. This patch
reintroduces the standard exception types back using new API.
Dmitry Volyntsev [Wed, 21 Jun 2023 23:29:45 +0000 (16:29 -0700)]
FS: added back custom exception types using new public API.
In 18385a4a90ad, when rewriting FS module using public API all the
exceptions types were squashed into a single Error type. This patch
reintroduces the standard exception types back using new API.
Dmitry Volyntsev [Tue, 13 Jun 2023 03:51:54 +0000 (20:51 -0700)]
Fixed Date.parse() with ISO-8601 date-only forms.
According to the spec when the UTC offset representation is absent,
date-only forms are interpreted as a UTC time and date-time forms
are interpreted as a local time.
Dmitry Volyntsev [Sat, 20 May 2023 03:22:16 +0000 (20:22 -0700)]
Shell: improved working with libedit.
Previously, libedit unlike GNU readline does not reinstall
rl_callback_handler_install handler after the handler was called. As a
result make shell_test executed ~20 times longer with libedit.
The fix is to reinstall the rl_callback_handler_install handler
explicitely every time the handler is invoked.
Dmitry Volyntsev [Sat, 20 May 2023 03:22:14 +0000 (20:22 -0700)]
Added support of regular expressions not supported directly by PCRE2.
The following patterns were fixed:
`[]` - matches nothing, previously was rejected as invalid expression.
`[^]` - matched any character, unlike `.` this syntax matches new
line, previously was rejected as invalid expression.
`++`, `*+`, `?+` - are rejected now, whereas in PCRE2 they are considered
valid possessive quantifiers.
Dmitry Volyntsev [Thu, 18 May 2023 04:16:19 +0000 (21:16 -0700)]
Modules: introduced global nginx properties.
The following properties were introduced:
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.
Dmitry Volyntsev [Wed, 17 May 2023 07:39:45 +0000 (00:39 -0700)]
Fixed evaluation of computed property names with function expressions.
Previously, while evaluating a property name expression with a function
expression as the right side, the evaluation modified the value used to
compute the property name in-place. The in-place modification changes
values not intended to be changed.
Sergey A. Osokin [Fri, 12 May 2023 23:38:29 +0000 (19:38 -0400)]
Always use a sharp (#) symbol as the sed separator.
sed(1) command line utility may fail with the following error:
sed: 1: "s, at EXTRA_LIBS@,-lm -L ...": bad in substitute command: '-'
when a replacement for @EXTRA_LIBS@ contains a comma symbol.
Dmitry Volyntsev [Thu, 11 May 2023 05:36:53 +0000 (22:36 -0700)]
Modules: added options to disable parts dependant on 3rd party libs.
The following environment variables are added: NJS_OPENSSL, NJS_LIBXSLT,
NJS_ZLIB. When a variable evaluates to "NO" the part of the module
related to the corresponsing library is disabled.
For example to disable libxslt related code:
NJS_LIBXSLT=NO ./configure .. --add-module=/path/to/njs/module