[njs] Types: extending data types for methods with NjsStringLike args.
details: https://hg.nginx.org/njs/rev/5bd78c74777a
branches:
changeset: 1572:5bd78c74777a
user: Dmitry Volyntsev
date: Thu Nov 26 11:10:59 2020 +
description:
Types: extending data types for methods with NjsStringLike args.
diffstat:
test/ts/test.ts | 5 -
ts/ngx_http_js_module.d.ts | 20 ++--
ts/ngx_stream_js_module.d.ts | 8
ts/njs_core.d.ts | 1 +
ts/njs_modules/crypto.d.ts | 6 +++---
ts/njs_modules/fs.d.ts | 8
6 files changed, 26 insertions(+), 22 deletions(-)
diffs (207 lines):
diff -r 434f20c29f4c -r 5bd78c74777a test/ts/test.ts
--- a/test/ts/test.ts Wed Nov 25 10:47:47 2020 +
+++ b/test/ts/test.ts Thu Nov 26 11:10:59 2020 +
@@ -49,6 +49,7 @@ function http_module(r: NginxHTTPRequest
// r.log
r.log(bs);
+r.log(Buffer.from("abc"));
r.log(r.headersOut['Connection'] ?? '');
// r.variables
@@ -61,7 +62,7 @@ function http_module(r: NginxHTTPRequest
r.subrequest('/p/sub2', {method:'POST'}).then(reply =>
r.return(reply.status));
vod = r.subrequest('/p/sub3', reply => r.return(reply.status));
vod = r.subrequest('/p/sub4', {method:'POST'}, reply =>
r.return(reply.status));
-vod = r.subrequest('/p/sub5', {detached:true});
+vod = r.subrequest(Buffer.from('/p/sub5'), {detached:true});
// Warning: vod = r.subrequest('/p/sub9', {detached:true}, reply =>
r.return(reply.status));
r.subrequest('/p/sub6', 'a=1&b=2').then(reply => r.return(reply.status,
JSON.stringify(JSON.parse(reply.responseBody ?? '';
@@ -73,6 +74,8 @@ function fs_module() {
s = fs.readFileSync('/path', 'utf8');
s = fs.readFileSync(Buffer.from('/path'), {encoding:'hex'});
+
+fs.writeFileSync('/path', Buffer.from('abc'));
}
function qs_module(str: NjsByteString) {
diff -r 434f20c29f4c -r 5bd78c74777a ts/ngx_http_js_module.d.ts
--- a/ts/ngx_http_js_module.d.tsWed Nov 25 10:47:47 2020 +
+++ b/ts/ngx_http_js_module.d.tsThu Nov 26 11:10:59 2020 +
@@ -263,7 +263,7 @@ interface NginxHTTPRequest {
* Writes a string to the error log on the error level of logging.
* @param message Message to log.
*/
-error(message: NjsStringLike): void;
+error(message: NjsStringOrBuffer): void;
/**
* Finishes sending a response to the client.
*/
@@ -286,12 +286,12 @@ interface NginxHTTPRequest {
* The actual redirect happens after the handler execution is completed.
* @param uri Location to redirect to.
*/
-internalRedirect(uri: NjsStringLike): void;
+internalRedirect(uri: NjsStringOrBuffer): void;
/**
* Writes a string to the error log on the info level of logging.
* @param message Message to log.
*/
-log(message: NjsStringLike): void;
+log(message: NjsStringOrBuffer): void;
/**
* HTTP method.
*/
@@ -323,11 +323,11 @@ interface NginxHTTPRequest {
* @param status Respose status code.
* @param body Respose body.
*/
-return(status: number, body?: NjsStringLike): void;
+return(status: number, body?: NjsStringOrBuffer): void;
/**
* Sends the HTTP headers to the client.
*/
-send(part: NjsStringLike): void;
+send(part: NjsStringOrBuffer): void;
/**
* Sends the HTTP headers to the client.
*/
@@ -346,11 +346,11 @@ interface NginxHTTPRequest {
* @param options Subrequest options.
* @param callback Completion callback.
*/
-subrequest(uri: NjsStringLike, options: NginxSubrequestOptions & {
detached: true }): void;
-subrequest(uri: NjsStringLike, options?: NginxSubrequestOptions | string):
Promise;
-subrequest(uri: NjsStringLike, options: NginxSubrequestOptions & {
detached?: false } | string,
+subrequest(uri: NjsStringOrBuffer, options: NginxSubrequestOptions & {
detached: true }): void;
+subrequest(uri: NjsStringOrBuffer, options?: NginxSubrequestOptions |
string): Promise;
+subrequest(uri: NjsStringOrBuffer, options: NginxSubrequestOptions & {
detached?: false } | string,
callback:(reply:NginxHTTPRequest) => void): void;
-subrequest(uri: NjsStringLike, callback:(reply:NginxHTTPRequest) => void):
void;
+subrequest(uri: NjsStringOrBuffer, callback:(reply:NginxHTTPRequest) =>
void): void;
/**
* Current URI in request, normalized.
*/
@@ -363,5 +363,5 @@ interface NginxHTTPRequest {
* Writes a string to the error log on the warn level of logging.
* @param message Message to log.
*/
-warn(message: NjsStringLike): void;
+warn(message: NjsStringOrBuffer): void;
}
diff -r 434f20c29f4c -r 5bd78c74777a ts/ngx_stream_js_module.d.ts
--- a/ts/ngx_stream_js_module.d.ts Wed Nov 25 10:47:47 2020 +
+++ b/ts/ngx_stream_js_module.d.ts Thu Nov 26 11:10:59 2020 +
@@ -110,12 +110,12 @@ interface NginxStreamRequest {
[njs] Types: added description for "ngx" object.
details: https://hg.nginx.org/njs/rev/42dfbf020c68
branches:
changeset: 1573:42dfbf020c68
user: Dmitry Volyntsev
date: Thu Nov 26 11:11:01 2020 +
description:
Types: added description for "ngx" object.
diffstat:
test/ts/test.ts | 9 +++--
ts/ngx_core.d.ts | 14 ++
ts/ngx_http_js_module.d.ts | 1 +
ts/ngx_stream_js_module.d.ts | 1 +
4 files changed, 23 insertions(+), 2 deletions(-)
diffs (62 lines):
diff -r 5bd78c74777a -r 42dfbf020c68 test/ts/test.ts
--- a/test/ts/test.ts Thu Nov 26 11:10:59 2020 +
+++ b/test/ts/test.ts Thu Nov 26 11:11:01 2020 +
@@ -66,7 +66,6 @@ function http_module(r: NginxHTTPRequest
// Warning: vod = r.subrequest('/p/sub9', {detached:true}, reply =>
r.return(reply.status));
r.subrequest('/p/sub6', 'a=1&b=2').then(reply => r.return(reply.status,
JSON.stringify(JSON.parse(reply.responseBody ?? '';
-
}
function fs_module() {
@@ -107,7 +106,13 @@ function buffer(b: Buffer) {
b.equals(b);
}
-function builtins() {
+function njs_object() {
njs.dump('asdf');
njs.version != process.argv[1];
}
+
+function ngx_object() {
+ngx.log(ngx.INFO, 'asdf');
+ngx.log(ngx.WARN, Buffer.from('asdf'));
+ngx.log(ngx.ERR, 'asdf');
+}
diff -r 5bd78c74777a -r 42dfbf020c68 ts/ngx_core.d.ts
--- /dev/null Thu Jan 01 00:00:00 1970 +
+++ b/ts/ngx_core.d.ts Thu Nov 26 11:11:01 2020 +
@@ -0,0 +1,14 @@
+interface NgxObject {
+readonly INFO: number;
+readonly WARN: number;
+readonly ERR: number;
+/**
+ * Writes a string to the error log with the specified level
+ * of logging.
+ * @param level Log level (ngx.INFO, ngx.WARN, ngx.ERR).
+ * @param message Message to log.
+ */
+log(level: number, message: NjsStringOrBuffer): void;
+}
+
+declare const ngx: NgxObject;
diff -r 5bd78c74777a -r 42dfbf020c68 ts/ngx_http_js_module.d.ts
--- a/ts/ngx_http_js_module.d.tsThu Nov 26 11:10:59 2020 +
+++ b/ts/ngx_http_js_module.d.tsThu Nov 26 11:11:01 2020 +
@@ -1,4 +1,5 @@
///
+///
interface NginxHTTPArgs {
readonly [prop: string]: NjsByteString;
diff -r 5bd78c74777a -r 42dfbf020c68 ts/ngx_stream_js_module.d.ts
--- a/ts/ngx_stream_js_module.d.ts Thu Nov 26 11:10:59 2020 +
+++ b/ts/ngx_stream_js_module.d.ts Thu Nov 26 11:11:01 2020 +
@@ -1,4 +1,5 @@
///
+///
interface NginxStreamVariables {
readonly 'binary_remote_addr'?: NjsByteString;
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] Modules: renaming vars to rawVariables to better reflect purpose.
details: https://hg.nginx.org/njs/rev/a141a29417dc
branches:
changeset: 1574:a141a29417dc
user: Dmitry Volyntsev
date: Thu Nov 26 11:36:03 2020 +
description:
Modules: renaming vars to rawVariables to better reflect purpose.
In 434f20c29f4c, obj.vars was introduced. obj.vars is almost identical
to obj.variables except a value of the Buffer type is returned.
Since most nginx variables are valid strings, it is preferable to
leave both variants.
To avoid confusion rawVariables name is used for Buffer variables.
diffstat:
nginx/ngx_http_js_module.c | 2 +-
nginx/ngx_stream_js_module.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diffs (24 lines):
diff -r 42dfbf020c68 -r a141a29417dc nginx/ngx_http_js_module.c
--- a/nginx/ngx_http_js_module.cThu Nov 26 11:11:01 2020 +
+++ b/nginx/ngx_http_js_module.cThu Nov 26 11:36:03 2020 +
@@ -406,7 +406,7 @@ static njs_external_t ngx_http_js_ext_r
{
.flags = NJS_EXTERN_OBJECT,
-.name.string = njs_str("vars"),
+.name.string = njs_str("rawVariables"),
.u.object = {
.writable = 1,
.prop_handler = ngx_http_js_ext_variables,
diff -r 42dfbf020c68 -r a141a29417dc nginx/ngx_stream_js_module.c
--- a/nginx/ngx_stream_js_module.c Thu Nov 26 11:11:01 2020 +
+++ b/nginx/ngx_stream_js_module.c Thu Nov 26 11:36:03 2020 +
@@ -245,7 +245,7 @@ static njs_external_t ngx_stream_js_ext
{
.flags = NJS_EXTERN_OBJECT,
-.name.string = njs_str("vars"),
+.name.string = njs_str("rawVariables"),
.u.object = {
.writable = 1,
.prop_handler = ngx_stream_js_ext_variables,
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
[njs] Modules: fixed promise events handling.
details: https://hg.nginx.org/njs/rev/fac7e5dc8009
branches:
changeset: 1575:fac7e5dc8009
user: Alexander Borisov
date: Thu Nov 26 21:43:17 2020 +0300
description:
Modules: fixed promise events handling.
Previously, promise chain might not be invoked at all in some cases.
Specifically, this happened in HTTP module if promise chain did not start
with a r.subrequest() invocation.
The fix is to always process all pending promise events after the main module
function.
This closes #359 issue on GitHub.
diffstat:
nginx/ngx_js.c | 6 +-
src/njs_vm.c | 2 +-
2 files changed, 2 insertions(+), 6 deletions(-)
diffs (28 lines):
diff -r a141a29417dc -r fac7e5dc8009 nginx/ngx_js.c
--- a/nginx/ngx_js.cThu Nov 26 11:36:03 2020 +
+++ b/nginx/ngx_js.cThu Nov 26 21:43:17 2020 +0300
@@ -79,11 +79,7 @@ ngx_js_call(njs_vm_t *vm, ngx_str_t *fna
return NGX_ERROR;
}
-if (njs_vm_pending(vm)) {
-return NGX_AGAIN;
-}
-
-return NGX_OK;
+return njs_vm_run(vm);
}
diff -r a141a29417dc -r fac7e5dc8009 src/njs_vm.c
--- a/src/njs_vm.c Thu Nov 26 11:36:03 2020 +
+++ b/src/njs_vm.c Thu Nov 26 21:43:17 2020 +0300
@@ -578,7 +578,7 @@ njs_vm_handle_events(njs_vm_t *vm)
} while (!njs_queue_is_empty(promise_events));
-return njs_posted_events(vm) ? NJS_AGAIN : NJS_OK;
+return njs_vm_pending(vm) ? NJS_AGAIN : NJS_OK;
}
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
[PATCH] Core: fixed inconsistent state of subrequest's headers_in list
# HG changeset patch
# User Jan Prachař
# Date 1606420825 -3600
# Thu Nov 26 21:00:25 2020 +0100
# Node ID cf3d537ec6706f8713a757df256f2cfccb8f9b01
# Parent e35b529b03781e64912e0d8a72bd0f957dc08cd2
Core: fixed inconsistent state of subrequest's headers_in list
When copying structure ngx_list_t, a reference to the last part need to be
updated, if list contains only one part.
This fixes an issue, when adding a header to the subrequest's headers_in list
has no effect.
diff -r e35b529b0378 -r cf3d537ec670 src/core/ngx_list.h
--- a/src/core/ngx_list.h Mon Sep 21 19:49:49 2020 +0200
+++ b/src/core/ngx_list.h Thu Nov 26 21:00:25 2020 +0100
@@ -51,6 +51,15 @@
return NGX_OK;
}
+static ngx_inline void
+ngx_list_copy(ngx_list_t *target, ngx_list_t *src)
+{
+*target = *src;
+if (target->part.next == NULL) {
+target->last = &target->part;
+}
+}
+
/*
*
diff -r e35b529b0378 -r cf3d537ec670 src/http/ngx_http_core_module.c
--- a/src/http/ngx_http_core_module.c Mon Sep 21 19:49:49 2020 +0200
+++ b/src/http/ngx_http_core_module.c Thu Nov 26 21:00:25 2020 +0100
@@ -2364,6 +2364,7 @@
sr->pool = r->pool;
sr->headers_in = r->headers_in;
+ngx_list_copy(&sr->headers_in.headers, &r->headers_in.headers);
ngx_http_clear_content_length(sr);
ngx_http_clear_accept_ranges(sr);
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
[nginx] Version bump.
details: https://hg.nginx.org/nginx/rev/ac09a57ec50d branches: changeset: 7749:ac09a57ec50d user: Ruslan Ermilov date: Thu Nov 26 23:46:59 2020 +0300 description: Version bump. diffstat: src/core/nginx.h | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diffs (14 lines): diff -r 66a441bf669b -r ac09a57ec50d src/core/nginx.h --- a/src/core/nginx.h Tue Nov 24 18:06:34 2020 +0300 +++ b/src/core/nginx.h Thu Nov 26 23:46:59 2020 +0300 @@ -9,8 +9,8 @@ #define _NGINX_H_INCLUDED_ -#define nginx_version 1019005 -#define NGINX_VERSION "1.19.5" +#define nginx_version 1019006 +#define NGINX_VERSION "1.19.6" #define NGINX_VER "nginx/" NGINX_VERSION #ifdef NGX_BUILD ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
[nginx] Upstream: excluded down servers from the next_upstream tries.
details: https://hg.nginx.org/nginx/rev/90cc7194e993
branches:
changeset: 7750:90cc7194e993
user: Ruslan Ermilov
date: Fri Nov 27 00:01:20 2020 +0300
description:
Upstream: excluded down servers from the next_upstream tries.
Previously, the number of next_upstream tries included servers marked
as "down", resulting in "no live upstreams" with the code 502 instead
of the code derived from an attempt to connect to the last tried "up"
server (ticket #2096).
diffstat:
src/http/ngx_http_upstream_round_robin.c | 20 +---
src/http/ngx_http_upstream_round_robin.h | 1 +
src/stream/ngx_stream_upstream_round_robin.c | 20 +---
src/stream/ngx_stream_upstream_round_robin.h | 1 +
4 files changed, 36 insertions(+), 6 deletions(-)
diffs (208 lines):
diff -r ac09a57ec50d -r 90cc7194e993 src/http/ngx_http_upstream_round_robin.c
--- a/src/http/ngx_http_upstream_round_robin.c Thu Nov 26 23:46:59 2020 +0300
+++ b/src/http/ngx_http_upstream_round_robin.c Fri Nov 27 00:01:20 2020 +0300
@@ -10,8 +10,8 @@
#include
-#define ngx_http_upstream_tries(p) ((p)->number \
-+ ((p)->next ? (p)->next->number : 0))
+#define ngx_http_upstream_tries(p) ((p)->tries\
++ ((p)->next ? (p)->next->tries : 0))
static ngx_http_upstream_rr_peer_t *ngx_http_upstream_get_peer(
@@ -32,7 +32,7 @@ ngx_http_upstream_init_round_robin(ngx_c
ngx_http_upstream_srv_conf_t *us)
{
ngx_url_t u;
-ngx_uint_t i, j, n, w;
+ngx_uint_t i, j, n, w, t;
ngx_http_upstream_server_t*server;
ngx_http_upstream_rr_peer_t *peer, **peerp;
ngx_http_upstream_rr_peers_t *peers, *backup;
@@ -44,6 +44,7 @@ ngx_http_upstream_init_round_robin(ngx_c
n = 0;
w = 0;
+t = 0;
for (i = 0; i < us->servers->nelts; i++) {
if (server[i].backup) {
@@ -52,6 +53,10 @@ ngx_http_upstream_init_round_robin(ngx_c
n += server[i].naddrs;
w += server[i].naddrs * server[i].weight;
+
+if (!server[i].down) {
+t += server[i].naddrs;
+}
}
if (n == 0) {
@@ -75,6 +80,7 @@ ngx_http_upstream_init_round_robin(ngx_c
peers->number = n;
peers->weighted = (w != n);
peers->total_weight = w;
+peers->tries = t;
peers->name = &us->host;
n = 0;
@@ -110,6 +116,7 @@ ngx_http_upstream_init_round_robin(ngx_c
n = 0;
w = 0;
+t = 0;
for (i = 0; i < us->servers->nelts; i++) {
if (!server[i].backup) {
@@ -118,6 +125,10 @@ ngx_http_upstream_init_round_robin(ngx_c
n += server[i].naddrs;
w += server[i].naddrs * server[i].weight;
+
+if (!server[i].down) {
+t += server[i].naddrs;
+}
}
if (n == 0) {
@@ -139,6 +150,7 @@ ngx_http_upstream_init_round_robin(ngx_c
backup->number = n;
backup->weighted = (w != n);
backup->total_weight = w;
+backup->tries = t;
backup->name = &us->host;
n = 0;
@@ -214,6 +226,7 @@ ngx_http_upstream_init_round_robin(ngx_c
peers->number = n;
peers->weighted = 0;
peers->total_weight = n;
+peers->tries = n;
peers->name = &us->host;
peerp = &peers->peer;
@@ -332,6 +345,7 @@ ngx_http_upstream_create_round_robin_pee
peers->single = (ur->naddrs == 1);
peers->number = ur->naddrs;
+peers->tries = ur->naddrs;
peers->name = &ur->host;
if (ur->sockaddr) {
diff -r ac09a57ec50d -r 90cc7194e993 src/http/ngx_http_upstream_round_robin.h
--- a/src/http/ngx_http_upstream_round_robin.h Thu Nov 26 23:46:59 2020 +0300
+++ b/src/http/ngx_http_upstream_round_robin.h Fri Nov 27 00:01:20 2020 +0300
@@ -68,6 +68,7 @@ struct ngx_http_upstream_rr_peers_s {
#endif
ngx_uint_t total_weight;
+ngx_uint_t tries;
unsignedsingle:1;
unsignedweighted:1;
diff -r ac09a57ec50d -r 90cc7194e993
src/stream/ngx_stream_upstream_round_robin.c
--- a/src/stream/ngx_stream_upstream_round_robin.c Thu Nov 26 23:46:59
2020 +0300
+++ b/src/stream/ngx_stream_upstream_round_robin.c Fri Nov 27 00:01:20
2020 +0300
@@ -10,8 +10,8 @@
#include
-#define ngx_stream_upstream_tries(p) ((p)->number \
- + ((p)->next ? (p)->next->number : 0))
+#define ngx_stream_upstream_tries(p) ((p)->tries \
+ + ((p)->next ? (p)->next->tries : 0))
static ngx_stream_upstream_rr_peer_t *ngx_stream_upstream_get_peer(
@@ -38,7 +38,7 @@ ngx_stream_upstream_init_round_robin(ngx
ngx_stream_
