From alfred at huji.fr Fri Jul 2 16:00:34 2021 From: alfred at huji.fr (Alfred Sawaya) Date: Fri, 2 Jul 2021 18:00:34 +0200 Subject: ssl_protocols don't respected Message-ID: <44a125cd-123f-7b4d-ef64-2ef21c88f4af@huji.fr> Hello, I am trying to configure an nginx that can accept only one ssl protocols. In order to do that, I tried to set ssl_protocols to only one protocol, but it does not work. The server always accept all TLS versions. I found that in the source code : src/http/modules/ngx_http_ssl_module.c : 673 ??? ngx_conf_merge_bitmask_value(conf->protocols, prev->protocols, ???????????????????????? (NGX_CONF_BITMASK_SET|NGX_SSL_TLSv1 ????????????????????????? |NGX_SSL_TLSv1_1|NGX_SSL_TLSv1_2)); So nginx seems to always activate TLS 1, 1.1 and 1.2. It should rather respect the directive ssl_protocls, shouldn't it ? Why it is not : ngx_conf_merge_bitmask_value(conf->protocols, prev->protocols, ???????????????????????? (NGX_CONF_BITMASK_SET)); With a if juste before calling nginx_ssl_create to set conf->protocols to NGX_SSL_TLSv1 | NGX_SSL_TLSv1_1 | NGX_SSL_TLSv1_2, only if conf->protocols == 0 ? (I also tried to use ssl_conf_command with MinProtocol and MaxProtocol, it does not work either...) Thank you, Alfred From alfred at huji.fr Fri Jul 2 16:05:40 2021 From: alfred at huji.fr (Alfred Sawaya) Date: Fri, 2 Jul 2021 18:05:40 +0200 Subject: ssl_protocols don't respected In-Reply-To: <44a125cd-123f-7b4d-ef64-2ef21c88f4af@huji.fr> References: <44a125cd-123f-7b4d-ef64-2ef21c88f4af@huji.fr> Message-ID: <5d64f274-2380-92a7-dc59-820db0b50454@huji.fr> Sorry, don't bother. It is because the default value is inherited from the http block. And if the ssl_protocols is not specified in the http block, then the default value is to enable TLS 1, 1.1 and 1.2 Maybe it would be more natural to no inherit for this directive if it is specified in an underlying block. Alfred On 02/07/2021 18:00, Alfred Sawaya wrote: > Hello, > > > I am trying to configure an nginx that can accept only one ssl > protocols. In order to do that, I tried to set ssl_protocols to only one > protocol, but it does not work. > > The server always accept all TLS versions. > > > I found that in the source code : > > src/http/modules/ngx_http_ssl_module.c : 673 > > ??? ngx_conf_merge_bitmask_value(conf->protocols, prev->protocols, > ???????????????????????? (NGX_CONF_BITMASK_SET|NGX_SSL_TLSv1 > ????????????????????????? |NGX_SSL_TLSv1_1|NGX_SSL_TLSv1_2)); > > > So nginx seems to always activate TLS 1, 1.1 and 1.2. It should rather > respect the directive ssl_protocls, shouldn't it ? > > Why it is not : > > ngx_conf_merge_bitmask_value(conf->protocols, prev->protocols, > ???????????????????????? (NGX_CONF_BITMASK_SET)); > > With a if juste before calling nginx_ssl_create to set conf->protocols > to NGX_SSL_TLSv1 | NGX_SSL_TLSv1_1 | NGX_SSL_TLSv1_2, only if > conf->protocols == 0 ? > > > (I also tried to use ssl_conf_command with MinProtocol and MaxProtocol, > it does not work either...) > > > Thank you, > > Alfred > From gfrankliu at gmail.com Sat Jul 3 04:47:11 2021 From: gfrankliu at gmail.com (Frank Liu) Date: Fri, 2 Jul 2021 21:47:11 -0700 Subject: ssl_protocols don't respected In-Reply-To: <5d64f274-2380-92a7-dc59-820db0b50454@huji.fr> References: <44a125cd-123f-7b4d-ef64-2ef21c88f4af@huji.fr> <5d64f274-2380-92a7-dc59-820db0b50454@huji.fr> Message-ID: See this ticket: https://trac.nginx.org/nginx/ticket/844 On Fri, Jul 2, 2021 at 9:05 AM Alfred Sawaya wrote: > Sorry, don't bother. > > It is because the default value is inherited from the http block. > > And if the ssl_protocols is not specified in the http block, then the > default value is to enable TLS 1, 1.1 and 1.2 > > > Maybe it would be more natural to no inherit for this directive if it is > specified in an underlying block. > > > Alfred > > > On 02/07/2021 18:00, Alfred Sawaya wrote: > > Hello, > > > > > > I am trying to configure an nginx that can accept only one ssl > > protocols. In order to do that, I tried to set ssl_protocols to only one > > protocol, but it does not work. > > > > The server always accept all TLS versions. > > > > > > I found that in the source code : > > > > src/http/modules/ngx_http_ssl_module.c : 673 > > > > ngx_conf_merge_bitmask_value(conf->protocols, prev->protocols, > > (NGX_CONF_BITMASK_SET|NGX_SSL_TLSv1 > > |NGX_SSL_TLSv1_1|NGX_SSL_TLSv1_2)); > > > > > > So nginx seems to always activate TLS 1, 1.1 and 1.2. It should rather > > respect the directive ssl_protocls, shouldn't it ? > > > > Why it is not : > > > > ngx_conf_merge_bitmask_value(conf->protocols, prev->protocols, > > (NGX_CONF_BITMASK_SET)); > > > > With a if juste before calling nginx_ssl_create to set conf->protocols > > to NGX_SSL_TLSv1 | NGX_SSL_TLSv1_1 | NGX_SSL_TLSv1_2, only if > > conf->protocols == 0 ? > > > > > > (I also tried to use ssl_conf_command with MinProtocol and MaxProtocol, > > it does not work either...) > > > > > > Thank you, > > > > Alfred > > > _______________________________________________ > nginx-devel mailing list > nginx-devel at nginx.org > http://mailman.nginx.org/mailman/listinfo/nginx-devel -------------- next part -------------- An HTML attachment was scrubbed... URL: From hle at owl.eu.com Sat Jul 3 08:18:53 2021 From: hle at owl.eu.com (Hugo Lefeuvre) Date: Sat, 3 Jul 2021 09:18:53 +0100 Subject: test suite failure with 1.20.1 Message-ID: <20210703081853.xhj6huxl2tytvsih@behemoth.owl.eu.com.local> Hi, I am trying to run the test suite, but it seems that, no matter how I build Nginx, it systematically fails. It seems that, most (all?) of the time, tests fail because Nginx returns 403 error codes, e.g.: ./ssi_waited.t ............................. 1/3 # Failed test 'waited non-active' # at ./ssi_waited.t line 60. # 'HTTP/1.1 403 Forbidden # Server: nginx/1.21.0 # Date: Sat, 03 Jul 2021 08:06:00 GMT # Content-Type: text/html # Connection: close # # # 403 Forbidden # #

403 Forbidden

#
nginx/1.21.0
# # # ' # doesn't match '(?^m:^xFIRSTxWAITEDxSECONDx$)' The runtime configuration is the default one from nginx-1.20.1.tar.gz (conf/nginx.conf). I must be doing something wrong with the build or run time configuration, but I cannot pinpoint what. Any idea? Best, Hugo -- Hugo Lefeuvre (hle) | www.owl.eu.com RSA4096_ 360B 03B3 BF27 4F4D 7A3F D5E8 14AA 1EB8 A247 3DFD ed25519_ 37B2 6D38 0B25 B8A2 6B9F 3A65 A36F 5357 5F2D DC4C -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: From mdounin at mdounin.ru Sun Jul 4 01:29:43 2021 From: mdounin at mdounin.ru (Maxim Dounin) Date: Sun, 4 Jul 2021 04:29:43 +0300 Subject: test suite failure with 1.20.1 In-Reply-To: <20210703081853.xhj6huxl2tytvsih@behemoth.owl.eu.com.local> References: <20210703081853.xhj6huxl2tytvsih@behemoth.owl.eu.com.local> Message-ID: Hello! On Sat, Jul 03, 2021 at 09:18:53AM +0100, Hugo Lefeuvre wrote: > I am trying to run the test suite, but it seems that, no matter how I build > Nginx, it systematically fails. > > It seems that, most (all?) of the time, tests fail because Nginx returns > 403 error codes, e.g.: > > ./ssi_waited.t ............................. 1/3 > # Failed test 'waited non-active' > # at ./ssi_waited.t line 60. > # 'HTTP/1.1 403 Forbidden > # Server: nginx/1.21.0 > # Date: Sat, 03 Jul 2021 08:06:00 GMT > # Content-Type: text/html > # Connection: close > # > # > # 403 Forbidden > # > #

403 Forbidden

> #
nginx/1.21.0
> # > # > # ' > # doesn't match '(?^m:^xFIRSTxWAITEDxSECONDx$)' > > The runtime configuration is the default one from nginx-1.20.1.tar.gz > (conf/nginx.conf). > > I must be doing something wrong with the build or run time configuration, > but I cannot pinpoint what. Any idea? Test output suggests that you are testing nginx 1.21.0, not 1.20.1. It looks like you are testing the wrong nginx binary, not the one you think you are testing. This might be the reason, for example, if you have some 3rd party modules compiled in and these modules reject requests for some reason. For additional details try looking into test details - in particular, test suite can leave full test configuration and logs for you with TEST_NGINX_LEAVE environment variable set, or simply cat the error log to the terminal before removing files with TEST_NGINX_CATLOG. See README of the test suite for details. -- Maxim Dounin http://mdounin.ru/ From dleonov at cloudlinux.com Mon Jul 5 12:50:42 2021 From: dleonov at cloudlinux.com (Daniil Leonov) Date: Mon, 5 Jul 2021 15:50:42 +0300 Subject: join nginx developers Message-ID: Hi everyone! My name is Daniil. I am C developer. I want to join nginx development. What are tasks at the moment? -------------- next part -------------- An HTML attachment was scrubbed... URL: From ru at nginx.com Mon Jul 5 16:34:26 2021 From: ru at nginx.com (Ruslan Ermilov) Date: Mon, 05 Jul 2021 16:34:26 +0000 Subject: [nginx] Use only preallocated memory in ngx_readv_chain() (ticket #1408). Message-ID: details: https://hg.nginx.org/nginx/rev/7f5e3595caff branches: changeset: 7886:7f5e3595caff user: Ruslan Ermilov date: Mon Jul 05 13:09:23 2021 +0300 description: Use only preallocated memory in ngx_readv_chain() (ticket #1408). In d1bde5c3c5d2, the number of preallocated iovec's for ngx_readv_chain() was increased. Still, in some setups, the function might allocate memory for iovec's from a connection pool, which is only freed when closing the connection. The ngx_readv_chain() function was modified to use only preallocated memory, similarly to the ngx_writev_chain() change in 8e903522c17a. diffstat: src/os/unix/ngx_readv_chain.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diffs (12 lines): diff -r e0fdd75871e4 -r 7f5e3595caff src/os/unix/ngx_readv_chain.c --- a/src/os/unix/ngx_readv_chain.c Mon Jun 28 18:01:24 2021 +0300 +++ b/src/os/unix/ngx_readv_chain.c Mon Jul 05 13:09:23 2021 +0300 @@ -96,7 +96,7 @@ ngx_readv_chain(ngx_connection_t *c, ngx iov->iov_len += n; } else { - if (vec.nelts >= IOV_MAX) { + if (vec.nelts == vec.nalloc) { break; } From ru at nginx.com Mon Jul 5 16:34:29 2021 From: ru at nginx.com (Ruslan Ermilov) Date: Mon, 05 Jul 2021 16:34:29 +0000 Subject: [nginx] Win32: use only preallocated memory in send/recv chain functions. Message-ID: details: https://hg.nginx.org/nginx/rev/ecf2a9002b37 branches: changeset: 7887:ecf2a9002b37 user: Ruslan Ermilov date: Mon Jul 05 13:26:49 2021 +0300 description: Win32: use only preallocated memory in send/recv chain functions. The ngx_wsasend_chain() and ngx_wsarecv_chain() functions were modified to use only preallocated memory, and the number of preallocated wsabufs was increased to 64. diffstat: src/os/win32/ngx_wsarecv_chain.c | 6 +++++- src/os/win32/ngx_wsasend_chain.c | 26 +++++++++++++++----------- 2 files changed, 20 insertions(+), 12 deletions(-) diffs (101 lines): diff -r 7f5e3595caff -r ecf2a9002b37 src/os/win32/ngx_wsarecv_chain.c --- a/src/os/win32/ngx_wsarecv_chain.c Mon Jul 05 13:09:23 2021 +0300 +++ b/src/os/win32/ngx_wsarecv_chain.c Mon Jul 05 13:26:49 2021 +0300 @@ -10,7 +10,7 @@ #include -#define NGX_WSABUFS 8 +#define NGX_WSABUFS 64 ssize_t @@ -57,6 +57,10 @@ ngx_wsarecv_chain(ngx_connection_t *c, n wsabuf->len += n; } else { + if (vec.nelts == vec.nalloc) { + break; + } + wsabuf = ngx_array_push(&vec); if (wsabuf == NULL) { return NGX_ERROR; diff -r 7f5e3595caff -r ecf2a9002b37 src/os/win32/ngx_wsasend_chain.c --- a/src/os/win32/ngx_wsasend_chain.c Mon Jul 05 13:09:23 2021 +0300 +++ b/src/os/win32/ngx_wsasend_chain.c Mon Jul 05 13:26:49 2021 +0300 @@ -10,7 +10,7 @@ #include -#define NGX_WSABUFS 8 +#define NGX_WSABUFS 64 ngx_chain_t * @@ -47,7 +47,7 @@ ngx_wsasend_chain(ngx_connection_t *c, n vec.elts = wsabufs; vec.size = sizeof(WSABUF); - vec.nalloc = NGX_WSABUFS; + vec.nalloc = ngx_min(NGX_WSABUFS, ngx_max_wsabufs); vec.pool = c->pool; for ( ;; ) { @@ -59,10 +59,8 @@ ngx_wsasend_chain(ngx_connection_t *c, n /* create the WSABUF and coalesce the neighbouring bufs */ - for (cl = in; - cl && vec.nelts < ngx_max_wsabufs && send < limit; - cl = cl->next) - { + for (cl = in; cl && send < limit; cl = cl->next) { + if (ngx_buf_special(cl->buf)) { continue; } @@ -77,6 +75,10 @@ ngx_wsasend_chain(ngx_connection_t *c, n wsabuf->len += cl->buf->last - cl->buf->pos; } else { + if (vec.nelts == vec.nalloc) { + break; + } + wsabuf = ngx_array_push(&vec); if (wsabuf == NULL) { return NGX_CHAIN_ERROR; @@ -169,7 +171,7 @@ ngx_overlapped_wsasend_chain(ngx_connect vec.elts = wsabufs; vec.nelts = 0; vec.size = sizeof(WSABUF); - vec.nalloc = NGX_WSABUFS; + vec.nalloc = ngx_min(NGX_WSABUFS, ngx_max_wsabufs); vec.pool = c->pool; send = 0; @@ -178,10 +180,8 @@ ngx_overlapped_wsasend_chain(ngx_connect /* create the WSABUF and coalesce the neighbouring bufs */ - for (cl = in; - cl && vec.nelts < ngx_max_wsabufs && send < limit; - cl = cl->next) - { + for (cl = in; cl && send < limit; cl = cl->next) { + if (ngx_buf_special(cl->buf)) { continue; } @@ -196,6 +196,10 @@ ngx_overlapped_wsasend_chain(ngx_connect wsabuf->len += cl->buf->last - cl->buf->pos; } else { + if (vec.nelts == vec.nalloc) { + break; + } + wsabuf = ngx_array_push(&vec); if (wsabuf == NULL) { return NGX_CHAIN_ERROR; From mdounin at mdounin.ru Tue Jul 6 15:01:17 2021 From: mdounin at mdounin.ru (Maxim Dounin) Date: Tue, 06 Jul 2021 15:01:17 +0000 Subject: [nginx] nginx-1.21.1-RELEASE Message-ID: details: https://hg.nginx.org/nginx/rev/a68ac0677f85 branches: changeset: 7888:a68ac0677f85 user: Maxim Dounin date: Tue Jul 06 17:59:16 2021 +0300 description: nginx-1.21.1-RELEASE diffstat: docs/xml/nginx/changes.xml | 119 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 119 insertions(+), 0 deletions(-) diffs (129 lines): diff -r ecf2a9002b37 -r a68ac0677f85 docs/xml/nginx/changes.xml --- a/docs/xml/nginx/changes.xml Mon Jul 05 13:26:49 2021 +0300 +++ b/docs/xml/nginx/changes.xml Tue Jul 06 17:59:16 2021 +0300 @@ -5,6 +5,125 @@ + + + + +?????? nginx ??? ?????? CONNECT ?????? ?????????? ??????. + + +now nginx always returns an error for the CONNECT method. + + + + + +?????? nginx ?????? ?????????? ??????, +???? ? ??????? ???????????? ???????????? ?????? ????????? "Content-Length" +? "Transfer-Encoding". + + +now nginx always returns an error +if both "Content-Length" and "Transfer-Encoding" header lines +are present in the request. + + + + + +?????? nginx ?????? ?????????? ??????, +???? ? ?????? ??????? ???????????? ??????? ??? ??????????? ???????. + + +now nginx always returns an error +if spaces or control characters are used in the request line. + + + + + +?????? nginx ?????? ?????????? ??????, +???? ? ????? ????????? ???????????? ??????? ??? ??????????? ???????. + + +now nginx always returns an error +if spaces or control characters are used in a header name. + + + + + +?????? nginx ?????? ?????????? ??????, +???? ? ?????? "Host" ????????? ??????? +???????????? ??????? ??? ??????????? ???????. + + +now nginx always returns an error +if spaces or control characters +are used in the "Host" request header line. + + + + + +??????????? ???????????? ???????????? +??? ????????????? ???????? ?????????? listen-???????. + + +optimization of configuration testing +when using many listening sockets. + + + + + +nginx ?? ??????????? +??????? """, "<", ">", "\", "^", "`", "{", "|", ? "}" +??? ????????????? ? ?????????? URI ???????. + + +nginx did not escape +""", "<", ">", "\", "^", "`", "{", "|", and "}" characters +when proxying with changed URI. + + + + + +SSL-?????????? ????? ???? ??????? ??? ?????? ? ???; +?????? ????????? ? 1.19.5. + + +SSL variables might be empty when used in logs; +the bug had appeared in 1.19.5. + + + + + +keepalive-?????????? ? gRPC-????????? ????? ?? ??????????? +????? ????????? GOAWAY-??????. + + +keepalive connections with gRPC backends might not be closed +after receiving a GOAWAY frame. + + + + + +????????? ??????????? ?????? ??? ???????????? ???????? +??? ????????????? ? ?????????????? ????? 64 ???????. + + +reduced memory consumption for long-lived requests +when proxying with more than 64 buffers. + + + + + + From mdounin at mdounin.ru Tue Jul 6 15:01:20 2021 From: mdounin at mdounin.ru (Maxim Dounin) Date: Tue, 06 Jul 2021 15:01:20 +0000 Subject: [nginx] release-1.21.1 tag Message-ID: details: https://hg.nginx.org/nginx/rev/91f96416f459 branches: changeset: 7889:91f96416f459 user: Maxim Dounin date: Tue Jul 06 17:59:17 2021 +0300 description: release-1.21.1 tag diffstat: .hgtags | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diffs (8 lines): diff -r a68ac0677f85 -r 91f96416f459 .hgtags --- a/.hgtags Tue Jul 06 17:59:16 2021 +0300 +++ b/.hgtags Tue Jul 06 17:59:17 2021 +0300 @@ -461,3 +461,4 @@ 8c65d21464aaa5923775f80c32474adc7a320068 da571b8eaf8f30f36c43b3c9b25e01e31f47149c release-1.19.9 ffcbb9980ee2bad27b4d7b1cd680b14ff47b29aa release-1.19.10 df34dcc9ac072ffd0945e5a1f3eb7987e8275375 release-1.21.0 +a68ac0677f8553b1f84d357bc9da114731ab5f47 release-1.21.1 From jeremie.drouet at gmail.com Thu Jul 8 09:17:00 2021 From: jeremie.drouet at gmail.com (=?iso-8859-1?q?Jeremie_Drouet?=) Date: Thu, 08 Jul 2021 11:17:00 +0200 Subject: [PATCH] Rename referrer to referer in error log Message-ID: <7db380334d2ca671b98a.1625735820@1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa> # HG changeset patch # User Jeremie Drouet # Date 1625150632 -7200 # Thu Jul 01 16:43:52 2021 +0200 # Node ID 7db380334d2ca671b98ab7563bab9ddee501c573 # Parent e0fdd75871e40e4c57ed405cadb94235550142c9 Rename referrer to referer in error log According to the developer doc from mozilla, referrer should be written with only one R and everywhere in the nginx codebase, we are using referer with only one R, so to make it consistent, I propose you to replace referrer with two R in the error log message with referer with only one R. I'm also proposing this because of the work I'm doing on vector regarding a nginx log parser in which we end up having referer and referrer when we parse logs. https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referer https://github.com/timberio/vector/ diff -r e0fdd75871e4 -r 7db380334d2c src/http/ngx_http_request.c --- a/src/http/ngx_http_request.c Mon Jun 28 18:01:24 2021 +0300 +++ b/src/http/ngx_http_request.c Thu Jul 01 16:43:52 2021 +0200 @@ -3889,7 +3889,7 @@ } if (r->headers_in.referer) { - p = ngx_snprintf(buf, len, ", referrer: \"%V\"", + p = ngx_snprintf(buf, len, ", referer: \"%V\"", &r->headers_in.referer->value); buf = p; } From mat999 at gmail.com Thu Jul 8 09:30:50 2021 From: mat999 at gmail.com (Mathew Heard) Date: Thu, 8 Jul 2021 19:30:50 +1000 Subject: [PATCH] Rename referrer to referer in error log In-Reply-To: <7db380334d2ca671b98a.1625735820@1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa> References: <7db380334d2ca671b98a.1625735820@1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa> Message-ID: This should be a major release patch. It's breaking for everyone passing the error log. On Thu, 8 Jul 2021, 7:17 pm Jeremie Drouet, wrote: > # HG changeset patch > # User Jeremie Drouet > # Date 1625150632 -7200 > # Thu Jul 01 16:43:52 2021 +0200 > # Node ID 7db380334d2ca671b98ab7563bab9ddee501c573 > # Parent e0fdd75871e40e4c57ed405cadb94235550142c9 > Rename referrer to referer in error log > > According to the developer doc from mozilla, referrer should be > written with only one R and everywhere in the nginx codebase, we > are using referer with only one R, so to make it consistent, I > propose you to replace referrer with two R in the error log > message with referer with only one R. > I'm also proposing this because of the work I'm doing on vector > regarding a nginx log parser in which we end up having referer > and referrer when we parse logs. > > https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referer > https://github.com/timberio/vector/ > > diff -r e0fdd75871e4 -r 7db380334d2c src/http/ngx_http_request.c > --- a/src/http/ngx_http_request.c Mon Jun 28 18:01:24 2021 +0300 > +++ b/src/http/ngx_http_request.c Thu Jul 01 16:43:52 2021 +0200 > @@ -3889,7 +3889,7 @@ > } > > if (r->headers_in.referer) { > - p = ngx_snprintf(buf, len, ", referrer: \"%V\"", > + p = ngx_snprintf(buf, len, ", referer: \"%V\"", > &r->headers_in.referer->value); > buf = p; > } > > _______________________________________________ > nginx-devel mailing list > nginx-devel at nginx.org > http://mailman.nginx.org/mailman/listinfo/nginx-devel > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeremie.drouet at gmail.com Thu Jul 8 09:33:40 2021 From: jeremie.drouet at gmail.com (=?UTF-8?B?SsOpcsOpbWllIERyb3VldA==?=) Date: Thu, 8 Jul 2021 11:33:40 +0200 Subject: [PATCH] Rename referrer to referer in error log In-Reply-To: References: <7db380334d2ca671b98a.1625735820@1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa> Message-ID: Ok, so what should I do now? Does it mean it cannot be done? On Thu, Jul 8, 2021 at 11:31 AM Mathew Heard wrote: > This should be a major release patch. It's breaking for everyone passing > the error log. > > On Thu, 8 Jul 2021, 7:17 pm Jeremie Drouet, > wrote: > >> # HG changeset patch >> # User Jeremie Drouet >> # Date 1625150632 -7200 >> # Thu Jul 01 16:43:52 2021 +0200 >> # Node ID 7db380334d2ca671b98ab7563bab9ddee501c573 >> # Parent e0fdd75871e40e4c57ed405cadb94235550142c9 >> Rename referrer to referer in error log >> >> According to the developer doc from mozilla, referrer should be >> written with only one R and everywhere in the nginx codebase, we >> are using referer with only one R, so to make it consistent, I >> propose you to replace referrer with two R in the error log >> message with referer with only one R. >> I'm also proposing this because of the work I'm doing on vector >> regarding a nginx log parser in which we end up having referer >> and referrer when we parse logs. >> >> https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referer >> https://github.com/timberio/vector/ >> >> diff -r e0fdd75871e4 -r 7db380334d2c src/http/ngx_http_request.c >> --- a/src/http/ngx_http_request.c Mon Jun 28 18:01:24 2021 +0300 >> +++ b/src/http/ngx_http_request.c Thu Jul 01 16:43:52 2021 +0200 >> @@ -3889,7 +3889,7 @@ >> } >> >> if (r->headers_in.referer) { >> - p = ngx_snprintf(buf, len, ", referrer: \"%V\"", >> + p = ngx_snprintf(buf, len, ", referer: \"%V\"", >> &r->headers_in.referer->value); >> buf = p; >> } >> >> _______________________________________________ >> nginx-devel mailing list >> nginx-devel at nginx.org >> http://mailman.nginx.org/mailman/listinfo/nginx-devel >> > _______________________________________________ > nginx-devel mailing list > nginx-devel at nginx.org > http://mailman.nginx.org/mailman/listinfo/nginx-devel -- J?r?mie Drouet about.me/jdrouet -------------- next part -------------- An HTML attachment was scrubbed... URL: From mat999 at gmail.com Thu Jul 8 09:42:03 2021 From: mat999 at gmail.com (Mathew Heard) Date: Thu, 8 Jul 2021 19:42:03 +1000 Subject: [PATCH] Rename referrer to referer in error log In-Reply-To: References: <7db380334d2ca671b98a.1625735820@1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa> Message-ID: I'm just a user of nginx making a comment. Simple patch, valuable find, potentially far reaching annoyance. On Thu, 8 Jul 2021, 7:33 pm J?r?mie Drouet, wrote: > Ok, so what should I do now? Does it mean it cannot be done? > > On Thu, Jul 8, 2021 at 11:31 AM Mathew Heard wrote: > >> This should be a major release patch. It's breaking for everyone passing >> the error log. >> >> On Thu, 8 Jul 2021, 7:17 pm Jeremie Drouet, >> wrote: >> >>> # HG changeset patch >>> # User Jeremie Drouet >>> # Date 1625150632 -7200 >>> # Thu Jul 01 16:43:52 2021 +0200 >>> # Node ID 7db380334d2ca671b98ab7563bab9ddee501c573 >>> # Parent e0fdd75871e40e4c57ed405cadb94235550142c9 >>> Rename referrer to referer in error log >>> >>> According to the developer doc from mozilla, referrer should be >>> written with only one R and everywhere in the nginx codebase, we >>> are using referer with only one R, so to make it consistent, I >>> propose you to replace referrer with two R in the error log >>> message with referer with only one R. >>> I'm also proposing this because of the work I'm doing on vector >>> regarding a nginx log parser in which we end up having referer >>> and referrer when we parse logs. >>> >>> https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referer >>> https://github.com/timberio/vector/ >>> >>> diff -r e0fdd75871e4 -r 7db380334d2c src/http/ngx_http_request.c >>> --- a/src/http/ngx_http_request.c Mon Jun 28 18:01:24 2021 +0300 >>> +++ b/src/http/ngx_http_request.c Thu Jul 01 16:43:52 2021 +0200 >>> @@ -3889,7 +3889,7 @@ >>> } >>> >>> if (r->headers_in.referer) { >>> - p = ngx_snprintf(buf, len, ", referrer: \"%V\"", >>> + p = ngx_snprintf(buf, len, ", referer: \"%V\"", >>> &r->headers_in.referer->value); >>> buf = p; >>> } >>> >>> _______________________________________________ >>> nginx-devel mailing list >>> nginx-devel at nginx.org >>> http://mailman.nginx.org/mailman/listinfo/nginx-devel >>> >> _______________________________________________ >> nginx-devel mailing list >> nginx-devel at nginx.org >> http://mailman.nginx.org/mailman/listinfo/nginx-devel > > > > -- > > > J?r?mie Drouet > about.me/jdrouet > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mdounin at mdounin.ru Thu Jul 8 13:27:21 2021 From: mdounin at mdounin.ru (Maxim Dounin) Date: Thu, 8 Jul 2021 16:27:21 +0300 Subject: [PATCH] Rename referrer to referer in error log In-Reply-To: <7db380334d2ca671b98a.1625735820@1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa> References: <7db380334d2ca671b98a.1625735820@1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa> Message-ID: Hello! On Thu, Jul 08, 2021 at 11:17:00AM +0200, Jeremie Drouet wrote: > # HG changeset patch > # User Jeremie Drouet > # Date 1625150632 -7200 > # Thu Jul 01 16:43:52 2021 +0200 > # Node ID 7db380334d2ca671b98ab7563bab9ddee501c573 > # Parent e0fdd75871e40e4c57ed405cadb94235550142c9 > Rename referrer to referer in error log > > According to the developer doc from mozilla, referrer should be > written with only one R and everywhere in the nginx codebase, we > are using referer with only one R, so to make it consistent, I > propose you to replace referrer with two R in the error log > message with referer with only one R. The "Referer" HTTP header name is misspelled and written with one R. The word is written with two Rs. In particular, it is written with two Rs in other header names, such as "Referrer-Policy". In the particular log message the "referrer" is a word rather than a header name, hence it is written with two Rs. While the word can be changed to the header name instead, I don't think I see compelling reasons to do so. > I'm also proposing this because of the work I'm doing on vector > regarding a nginx log parser in which we end up having referer > and referrer when we parse logs. Note that nginx error logs currently cannot be parsed automatically, see https://trac.nginx.org/nginx/ticket/191. > > https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referer > https://github.com/timberio/vector/ > > diff -r e0fdd75871e4 -r 7db380334d2c src/http/ngx_http_request.c > --- a/src/http/ngx_http_request.c Mon Jun 28 18:01:24 2021 +0300 > +++ b/src/http/ngx_http_request.c Thu Jul 01 16:43:52 2021 +0200 > @@ -3889,7 +3889,7 @@ > } > > if (r->headers_in.referer) { > - p = ngx_snprintf(buf, len, ", referrer: \"%V\"", > + p = ngx_snprintf(buf, len, ", referer: \"%V\"", > &r->headers_in.referer->value); > buf = p; > } > > _______________________________________________ > nginx-devel mailing list > nginx-devel at nginx.org > http://mailman.nginx.org/mailman/listinfo/nginx-devel -- Maxim Dounin http://mdounin.ru/ From vbart at nginx.com Fri Jul 9 09:05:29 2021 From: vbart at nginx.com (Valentin Bartenev) Date: Fri, 09 Jul 2021 09:05:29 +0000 Subject: [njs] Unicode case tables updated to version 14.0.0 (May 2021). Message-ID: details: https://hg.nginx.org/njs/rev/36dd0370b121 branches: changeset: 1673:36dd0370b121 user: Valentin Bartenev date: Fri Jul 09 12:03:11 2021 +0300 description: Unicode case tables updated to version 14.0.0 (May 2021). diffstat: src/njs_unicode_lower_case.h | 60 ++++++++++++++++++++++++++++++++++++++----- src/njs_unicode_upper_case.h | 36 +++++++++++++++++++++----- src/njs_utf8.c | 2 +- 3 files changed, 82 insertions(+), 16 deletions(-) diffs (184 lines): diff -r 45c470a2d710 -r 36dd0370b121 src/njs_unicode_lower_case.h --- a/src/njs_unicode_lower_case.h Tue Jun 29 17:08:23 2021 +0300 +++ b/src/njs_unicode_lower_case.h Fri Jul 09 12:03:11 2021 +0300 @@ -1,7 +1,7 @@ /* - * 33 128-bytes blocks, 979 pointers. - * 20330 bytes on 32-bit platforms, 24242 bytes on 64-bit platforms. + * 35 128-bytes blocks, 979 pointers. + * 21354 bytes on 32-bit platforms, 25266 bytes on 64-bit platforms. */ #define NJS_UNICODE_MAX_LOWER_CASE 0x1e921 @@ -457,7 +457,7 @@ static const uint32_t njs_unicode_lower 0x02c40, 0x02c41, 0x02c42, 0x02c43, 0x02c44, 0x02c45, 0x02c46, 0x02c47, 0x02c48, 0x02c49, 0x02c4a, 0x02c4b, 0x02c4c, 0x02c4d, 0x02c4e, 0x02c4f, 0x02c50, 0x02c51, 0x02c52, 0x02c53, 0x02c54, 0x02c55, 0x02c56, 0x02c57, - 0x02c58, 0x02c59, 0x02c5a, 0x02c5b, 0x02c5c, 0x02c5d, 0x02c5e, 0x02c2f, + 0x02c58, 0x02c59, 0x02c5a, 0x02c5b, 0x02c5c, 0x02c5d, 0x02c5e, 0x02c5f, 0x02c30, 0x02c31, 0x02c32, 0x02c33, 0x02c34, 0x02c35, 0x02c36, 0x02c37, 0x02c38, 0x02c39, 0x02c3a, 0x02c3b, 0x02c3c, 0x02c3d, 0x02c3e, 0x02c3f, 0x02c40, 0x02c41, 0x02c42, 0x02c43, 0x02c44, 0x02c45, 0x02c46, 0x02c47, @@ -570,10 +570,10 @@ static const uint32_t njs_unicode_lower 0x0a7a9, 0x0a7a9, 0x00266, 0x0025c, 0x00261, 0x0026c, 0x0026a, 0x0a7af, 0x0029e, 0x00287, 0x0029d, 0x0ab53, 0x0a7b5, 0x0a7b5, 0x0a7b7, 0x0a7b7, 0x0a7b9, 0x0a7b9, 0x0a7bb, 0x0a7bb, 0x0a7bd, 0x0a7bd, 0x0a7bf, 0x0a7bf, - 0x0a7c0, 0x0a7c1, 0x0a7c3, 0x0a7c3, 0x0a794, 0x00282, 0x01d8e, 0x0a7c8, + 0x0a7c1, 0x0a7c1, 0x0a7c3, 0x0a7c3, 0x0a794, 0x00282, 0x01d8e, 0x0a7c8, 0x0a7c8, 0x0a7ca, 0x0a7ca, 0x0a7cb, 0x0a7cc, 0x0a7cd, 0x0a7ce, 0x0a7cf, - 0x0a7d0, 0x0a7d1, 0x0a7d2, 0x0a7d3, 0x0a7d4, 0x0a7d5, 0x0a7d6, 0x0a7d7, - 0x0a7d8, 0x0a7d9, 0x0a7da, 0x0a7db, 0x0a7dc, 0x0a7dd, 0x0a7de, 0x0a7df, + 0x0a7d1, 0x0a7d1, 0x0a7d2, 0x0a7d3, 0x0a7d4, 0x0a7d5, 0x0a7d7, 0x0a7d7, + 0x0a7d9, 0x0a7d9, 0x0a7da, 0x0a7db, 0x0a7dc, 0x0a7dd, 0x0a7de, 0x0a7df, 0x0a7e0, 0x0a7e1, 0x0a7e2, 0x0a7e3, 0x0a7e4, 0x0a7e5, 0x0a7e6, 0x0a7e7, 0x0a7e8, 0x0a7e9, 0x0a7ea, 0x0a7eb, 0x0a7ec, 0x0a7ed, 0x0a7ee, 0x0a7ef, 0x0a7f0, 0x0a7f1, 0x0a7f2, 0x0a7f3, 0x0a7f4, 0x0a7f6, 0x0a7f6, 0x0a7f7, @@ -647,6 +647,50 @@ static const uint32_t njs_unicode_lower }; +static const uint32_t njs_unicode_lower_case_block_20a[128] + njs_aligned(64) = +{ + 0x10500, 0x10501, 0x10502, 0x10503, 0x10504, 0x10505, 0x10506, 0x10507, + 0x10508, 0x10509, 0x1050a, 0x1050b, 0x1050c, 0x1050d, 0x1050e, 0x1050f, + 0x10510, 0x10511, 0x10512, 0x10513, 0x10514, 0x10515, 0x10516, 0x10517, + 0x10518, 0x10519, 0x1051a, 0x1051b, 0x1051c, 0x1051d, 0x1051e, 0x1051f, + 0x10520, 0x10521, 0x10522, 0x10523, 0x10524, 0x10525, 0x10526, 0x10527, + 0x10528, 0x10529, 0x1052a, 0x1052b, 0x1052c, 0x1052d, 0x1052e, 0x1052f, + 0x10530, 0x10531, 0x10532, 0x10533, 0x10534, 0x10535, 0x10536, 0x10537, + 0x10538, 0x10539, 0x1053a, 0x1053b, 0x1053c, 0x1053d, 0x1053e, 0x1053f, + 0x10540, 0x10541, 0x10542, 0x10543, 0x10544, 0x10545, 0x10546, 0x10547, + 0x10548, 0x10549, 0x1054a, 0x1054b, 0x1054c, 0x1054d, 0x1054e, 0x1054f, + 0x10550, 0x10551, 0x10552, 0x10553, 0x10554, 0x10555, 0x10556, 0x10557, + 0x10558, 0x10559, 0x1055a, 0x1055b, 0x1055c, 0x1055d, 0x1055e, 0x1055f, + 0x10560, 0x10561, 0x10562, 0x10563, 0x10564, 0x10565, 0x10566, 0x10567, + 0x10568, 0x10569, 0x1056a, 0x1056b, 0x1056c, 0x1056d, 0x1056e, 0x1056f, + 0x10597, 0x10598, 0x10599, 0x1059a, 0x1059b, 0x1059c, 0x1059d, 0x1059e, + 0x1059f, 0x105a0, 0x105a1, 0x1057b, 0x105a3, 0x105a4, 0x105a5, 0x105a6, +}; + + +static const uint32_t njs_unicode_lower_case_block_20b[128] + njs_aligned(64) = +{ + 0x105a7, 0x105a8, 0x105a9, 0x105aa, 0x105ab, 0x105ac, 0x105ad, 0x105ae, + 0x105af, 0x105b0, 0x105b1, 0x1058b, 0x105b3, 0x105b4, 0x105b5, 0x105b6, + 0x105b7, 0x105b8, 0x105b9, 0x10593, 0x105bb, 0x105bc, 0x10596, 0x10597, + 0x10598, 0x10599, 0x1059a, 0x1059b, 0x1059c, 0x1059d, 0x1059e, 0x1059f, + 0x105a0, 0x105a1, 0x105a2, 0x105a3, 0x105a4, 0x105a5, 0x105a6, 0x105a7, + 0x105a8, 0x105a9, 0x105aa, 0x105ab, 0x105ac, 0x105ad, 0x105ae, 0x105af, + 0x105b0, 0x105b1, 0x105b2, 0x105b3, 0x105b4, 0x105b5, 0x105b6, 0x105b7, + 0x105b8, 0x105b9, 0x105ba, 0x105bb, 0x105bc, 0x105bd, 0x105be, 0x105bf, + 0x105c0, 0x105c1, 0x105c2, 0x105c3, 0x105c4, 0x105c5, 0x105c6, 0x105c7, + 0x105c8, 0x105c9, 0x105ca, 0x105cb, 0x105cc, 0x105cd, 0x105ce, 0x105cf, + 0x105d0, 0x105d1, 0x105d2, 0x105d3, 0x105d4, 0x105d5, 0x105d6, 0x105d7, + 0x105d8, 0x105d9, 0x105da, 0x105db, 0x105dc, 0x105dd, 0x105de, 0x105df, + 0x105e0, 0x105e1, 0x105e2, 0x105e3, 0x105e4, 0x105e5, 0x105e6, 0x105e7, + 0x105e8, 0x105e9, 0x105ea, 0x105eb, 0x105ec, 0x105ed, 0x105ee, 0x105ef, + 0x105f0, 0x105f1, 0x105f2, 0x105f3, 0x105f4, 0x105f5, 0x105f6, 0x105f7, + 0x105f8, 0x105f9, 0x105fa, 0x105fb, 0x105fc, 0x105fd, 0x105fe, 0x105ff, +}; + + static const uint32_t njs_unicode_lower_case_block_219[128] njs_aligned(64) = { @@ -1249,8 +1293,8 @@ static const uint32_t *njs_unicode_lowe NULL, njs_unicode_lower_case_block_208, njs_unicode_lower_case_block_209, - NULL, - NULL, + njs_unicode_lower_case_block_20a, + njs_unicode_lower_case_block_20b, NULL, NULL, NULL, diff -r 45c470a2d710 -r 36dd0370b121 src/njs_unicode_upper_case.h --- a/src/njs_unicode_upper_case.h Tue Jun 29 17:08:23 2021 +0300 +++ b/src/njs_unicode_upper_case.h Fri Jul 09 12:03:11 2021 +0300 @@ -1,7 +1,7 @@ /* - * 40 128-bytes blocks, 979 pointers. - * 23948 bytes on 32-bit platforms, 27860 bytes on 64-bit platforms. + * 41 128-bytes blocks, 979 pointers. + * 24460 bytes on 32-bit platforms, 28372 bytes on 64-bit platforms. */ #define NJS_UNICODE_MAX_UPPER_CASE 0x1e943 @@ -551,7 +551,7 @@ static const uint32_t njs_unicode_upper 0x02c10, 0x02c11, 0x02c12, 0x02c13, 0x02c14, 0x02c15, 0x02c16, 0x02c17, 0x02c18, 0x02c19, 0x02c1a, 0x02c1b, 0x02c1c, 0x02c1d, 0x02c1e, 0x02c1f, 0x02c20, 0x02c21, 0x02c22, 0x02c23, 0x02c24, 0x02c25, 0x02c26, 0x02c27, - 0x02c28, 0x02c29, 0x02c2a, 0x02c2b, 0x02c2c, 0x02c2d, 0x02c2e, 0x02c5f, + 0x02c28, 0x02c29, 0x02c2a, 0x02c2b, 0x02c2c, 0x02c2d, 0x02c2e, 0x02c2f, 0x02c60, 0x02c60, 0x02c62, 0x02c63, 0x02c64, 0x0023a, 0x0023e, 0x02c67, 0x02c67, 0x02c69, 0x02c69, 0x02c6b, 0x02c6b, 0x02c6d, 0x02c6e, 0x02c6f, 0x02c70, 0x02c71, 0x02c72, 0x02c72, 0x02c74, 0x02c75, 0x02c75, 0x02c77, @@ -680,10 +680,10 @@ static const uint32_t njs_unicode_upper 0x0a7a8, 0x0a7a8, 0x0a7aa, 0x0a7ab, 0x0a7ac, 0x0a7ad, 0x0a7ae, 0x0a7af, 0x0a7b0, 0x0a7b1, 0x0a7b2, 0x0a7b3, 0x0a7b4, 0x0a7b4, 0x0a7b6, 0x0a7b6, 0x0a7b8, 0x0a7b8, 0x0a7ba, 0x0a7ba, 0x0a7bc, 0x0a7bc, 0x0a7be, 0x0a7be, - 0x0a7c0, 0x0a7c1, 0x0a7c2, 0x0a7c2, 0x0a7c4, 0x0a7c5, 0x0a7c6, 0x0a7c7, + 0x0a7c0, 0x0a7c0, 0x0a7c2, 0x0a7c2, 0x0a7c4, 0x0a7c5, 0x0a7c6, 0x0a7c7, 0x0a7c7, 0x0a7c9, 0x0a7c9, 0x0a7cb, 0x0a7cc, 0x0a7cd, 0x0a7ce, 0x0a7cf, - 0x0a7d0, 0x0a7d1, 0x0a7d2, 0x0a7d3, 0x0a7d4, 0x0a7d5, 0x0a7d6, 0x0a7d7, - 0x0a7d8, 0x0a7d9, 0x0a7da, 0x0a7db, 0x0a7dc, 0x0a7dd, 0x0a7de, 0x0a7df, + 0x0a7d0, 0x0a7d0, 0x0a7d2, 0x0a7d3, 0x0a7d4, 0x0a7d5, 0x0a7d6, 0x0a7d6, + 0x0a7d8, 0x0a7d8, 0x0a7da, 0x0a7db, 0x0a7dc, 0x0a7dd, 0x0a7de, 0x0a7df, 0x0a7e0, 0x0a7e1, 0x0a7e2, 0x0a7e3, 0x0a7e4, 0x0a7e5, 0x0a7e6, 0x0a7e7, 0x0a7e8, 0x0a7e9, 0x0a7ea, 0x0a7eb, 0x0a7ec, 0x0a7ed, 0x0a7ee, 0x0a7ef, 0x0a7f0, 0x0a7f1, 0x0a7f2, 0x0a7f3, 0x0a7f4, 0x0a7f5, 0x0a7f5, 0x0a7f7, @@ -801,6 +801,28 @@ static const uint32_t njs_unicode_upper }; +static const uint32_t njs_unicode_upper_case_block_20b[128] + njs_aligned(64) = +{ + 0x10580, 0x10581, 0x10582, 0x10583, 0x10584, 0x10585, 0x10586, 0x10587, + 0x10588, 0x10589, 0x1058a, 0x1058b, 0x1058c, 0x1058d, 0x1058e, 0x1058f, + 0x10590, 0x10591, 0x10592, 0x10593, 0x10594, 0x10595, 0x10596, 0x10570, + 0x10571, 0x10572, 0x10573, 0x10574, 0x10575, 0x10576, 0x10577, 0x10578, + 0x10579, 0x1057a, 0x105a2, 0x1057c, 0x1057d, 0x1057e, 0x1057f, 0x10580, + 0x10581, 0x10582, 0x10583, 0x10584, 0x10585, 0x10586, 0x10587, 0x10588, + 0x10589, 0x1058a, 0x105b2, 0x1058c, 0x1058d, 0x1058e, 0x1058f, 0x10590, + 0x10591, 0x10592, 0x105ba, 0x10594, 0x10595, 0x105bd, 0x105be, 0x105bf, + 0x105c0, 0x105c1, 0x105c2, 0x105c3, 0x105c4, 0x105c5, 0x105c6, 0x105c7, + 0x105c8, 0x105c9, 0x105ca, 0x105cb, 0x105cc, 0x105cd, 0x105ce, 0x105cf, + 0x105d0, 0x105d1, 0x105d2, 0x105d3, 0x105d4, 0x105d5, 0x105d6, 0x105d7, + 0x105d8, 0x105d9, 0x105da, 0x105db, 0x105dc, 0x105dd, 0x105de, 0x105df, + 0x105e0, 0x105e1, 0x105e2, 0x105e3, 0x105e4, 0x105e5, 0x105e6, 0x105e7, + 0x105e8, 0x105e9, 0x105ea, 0x105eb, 0x105ec, 0x105ed, 0x105ee, 0x105ef, + 0x105f0, 0x105f1, 0x105f2, 0x105f3, 0x105f4, 0x105f5, 0x105f6, 0x105f7, + 0x105f8, 0x105f9, 0x105fa, 0x105fb, 0x105fc, 0x105fd, 0x105fe, 0x105ff, +}; + + static const uint32_t njs_unicode_upper_case_block_219[128] njs_aligned(64) = { @@ -1408,7 +1430,7 @@ static const uint32_t *njs_unicode_uppe njs_unicode_upper_case_block_208, njs_unicode_upper_case_block_209, NULL, - NULL, + njs_unicode_upper_case_block_20b, NULL, NULL, NULL, diff -r 45c470a2d710 -r 36dd0370b121 src/njs_utf8.c --- a/src/njs_utf8.c Tue Jun 29 17:08:23 2021 +0300 +++ b/src/njs_utf8.c Fri Jul 09 12:03:11 2021 +0300 @@ -9,7 +9,7 @@ /* * The njs_unicode_lower_case.h and njs_unicode_upper_case.h files are - * auto-generated from the UnicodeData.txt file version 13.0.0 (March 2020) + * auto-generated from the UnicodeData.txt file version 14.0.0 (May 2021) * provided by Unicode, Inc.: * * ./njs_unicode_lower_case.pl UnicodeData.txt From xeioex at nginx.com Fri Jul 9 19:37:08 2021 From: xeioex at nginx.com (Dmitry Volyntsev) Date: Fri, 09 Jul 2021 19:37:08 +0000 Subject: [njs] Modules: improved working with external prototypes. Message-ID: details: https://hg.nginx.org/njs/rev/92cb9b80cf8b branches: changeset: 1674:92cb9b80cf8b user: Dmitry Volyntsev date: Fri Jul 09 14:01:26 2021 +0000 description: Modules: improved working with external prototypes. This patch avoids relying on the order in which external prototypes are registered. Instead, the returned proto_id is expected to be stored somewhere. diffstat: nginx/ngx_http_js_module.c | 16 ++++++++++------ nginx/ngx_js.h | 3 --- nginx/ngx_js_fetch.c | 14 ++++++++------ nginx/ngx_stream_js_module.c | 12 ++++++++---- 4 files changed, 26 insertions(+), 19 deletions(-) diffs (149 lines): diff -r 36dd0370b121 -r 92cb9b80cf8b nginx/ngx_http_js_module.c --- a/nginx/ngx_http_js_module.c Fri Jul 09 12:03:11 2021 +0300 +++ b/nginx/ngx_http_js_module.c Fri Jul 09 14:01:26 2021 +0000 @@ -320,6 +320,9 @@ static ngx_http_output_header_filter_pt static ngx_http_output_body_filter_pt ngx_http_next_body_filter; +static njs_int_t ngx_http_js_request_proto_id; + + static njs_external_t ngx_http_js_ext_request[] = { { @@ -1114,7 +1117,7 @@ ngx_http_js_init_vm(ngx_http_request_t * } rc = njs_vm_external_create(ctx->vm, njs_value_arg(&ctx->request), - NGX_JS_PROTO_MAIN, r, 0); + ngx_http_js_request_proto_id, r, 0); if (rc != NJS_OK) { return NGX_ERROR; } @@ -3141,7 +3144,7 @@ ngx_http_js_subrequest_done(ngx_http_req } ret = njs_vm_external_create(ctx->vm, njs_value_arg(&reply), - NGX_JS_PROTO_MAIN, r, 0); + ngx_http_js_request_proto_id, r, 0); if (ret != NJS_OK) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "js subrequest reply creation failed"); @@ -3383,7 +3386,7 @@ ngx_http_js_init_main_conf(ngx_conf_t *c ssize_t n; ngx_fd_t fd; ngx_str_t *m, file; - njs_int_t rc, proto_id; + njs_int_t rc; njs_str_t text, path; ngx_uint_t i; njs_value_t *value; @@ -3542,9 +3545,10 @@ ngx_http_js_init_main_conf(ngx_conf_t *c } } - proto_id = njs_vm_external_prototype(jmcf->vm, ngx_http_js_ext_request, - njs_nitems(ngx_http_js_ext_request)); - if (proto_id < 0) { + ngx_http_js_request_proto_id = njs_vm_external_prototype(jmcf->vm, + ngx_http_js_ext_request, + njs_nitems(ngx_http_js_ext_request)); + if (ngx_http_js_request_proto_id < 0) { ngx_log_error(NGX_LOG_EMERG, cf->log, 0, "failed to add js request proto"); return NGX_CONF_ERROR; diff -r 36dd0370b121 -r 92cb9b80cf8b nginx/ngx_js.h --- a/nginx/ngx_js.h Fri Jul 09 12:03:11 2021 +0300 +++ b/nginx/ngx_js.h Fri Jul 09 14:01:26 2021 +0000 @@ -19,9 +19,6 @@ #define NGX_JS_STRING 1 #define NGX_JS_BUFFER 2 -#define NGX_JS_PROTO_MAIN 0 -#define NGX_JS_PROTO_RESPONSE 1 - typedef ngx_pool_t *(*ngx_external_pool_pt)(njs_vm_t *vm, njs_external_ptr_t e); typedef void (*ngx_js_event_handler_pt)(njs_external_ptr_t e, diff -r 36dd0370b121 -r 92cb9b80cf8b nginx/ngx_js_fetch.c --- a/nginx/ngx_js_fetch.c Fri Jul 09 12:03:11 2021 +0300 +++ b/nginx/ngx_js_fetch.c Fri Jul 09 14:01:26 2021 +0000 @@ -319,6 +319,9 @@ static njs_external_t ngx_js_ext_http_r }; +static njs_int_t ngx_http_js_fetch_proto_id; + + njs_int_t ngx_js_ext_fetch(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs, njs_index_t unused) @@ -1189,7 +1192,7 @@ ngx_js_http_process_body(ngx_js_http_t * if (size == http->http_parse.content_length_n) { ret = njs_vm_external_create(http->vm, njs_value_arg(&http->reply), - NGX_JS_PROTO_RESPONSE, http, 0); + ngx_http_js_fetch_proto_id, http, 0); if (ret != NJS_OK) { ngx_js_http_error(http, 0, "fetch object creation failed"); return NGX_ERROR; @@ -2212,11 +2215,10 @@ ngx_response_js_ext_type(njs_vm_t *vm, n ngx_int_t ngx_js_fetch_init(njs_vm_t *vm, ngx_log_t *log) { - njs_int_t proto_id; - - proto_id = njs_vm_external_prototype(vm, ngx_js_ext_http_response, - njs_nitems(ngx_js_ext_http_response)); - if (proto_id != NGX_JS_PROTO_RESPONSE) { + ngx_http_js_fetch_proto_id = njs_vm_external_prototype(vm, + ngx_js_ext_http_response, + njs_nitems(ngx_js_ext_http_response)); + if (ngx_http_js_fetch_proto_id < 0) { ngx_log_error(NGX_LOG_EMERG, log, 0, "failed to add js http.response proto"); return NGX_ERROR; diff -r 36dd0370b121 -r 92cb9b80cf8b nginx/ngx_stream_js_module.c --- a/nginx/ngx_stream_js_module.c Fri Jul 09 12:03:11 2021 +0300 +++ b/nginx/ngx_stream_js_module.c Fri Jul 09 14:01:26 2021 +0000 @@ -419,6 +419,9 @@ static njs_vm_meta_t ngx_stream_js_metas static ngx_stream_filter_pt ngx_stream_next_filter; +static njs_int_t ngx_stream_js_session_proto_id; + + static ngx_int_t ngx_stream_js_access_handler(ngx_stream_session_t *s) { @@ -757,7 +760,7 @@ ngx_stream_js_init_vm(ngx_stream_session } rc = njs_vm_external_create(ctx->vm, njs_value_arg(&ctx->args[0]), - NGX_JS_PROTO_MAIN, s, 0); + ngx_stream_js_session_proto_id, s, 0); if (rc != NJS_OK) { return NGX_ERROR; } @@ -1400,7 +1403,7 @@ ngx_stream_js_init_main_conf(ngx_conf_t ssize_t n; ngx_fd_t fd; ngx_str_t *m, file; - njs_int_t rc, proto_id; + njs_int_t rc; njs_str_t text, path; ngx_uint_t i; njs_value_t *value; @@ -1559,9 +1562,10 @@ ngx_stream_js_init_main_conf(ngx_conf_t } } - proto_id = njs_vm_external_prototype(jmcf->vm, ngx_stream_js_ext_session, + ngx_stream_js_session_proto_id = njs_vm_external_prototype(jmcf->vm, + ngx_stream_js_ext_session, njs_nitems(ngx_stream_js_ext_session)); - if (proto_id < 0) { + if (ngx_stream_js_session_proto_id < 0) { ngx_log_error(NGX_LOG_EMERG, cf->log, 0, "failed to add js request proto"); return NGX_CONF_ERROR; From xeioex at nginx.com Fri Jul 9 19:37:10 2021 From: xeioex at nginx.com (Dmitry Volyntsev) Date: Fri, 09 Jul 2021 19:37:10 +0000 Subject: [njs] Marking different external pointer with unique tag. Message-ID: details: https://hg.nginx.org/njs/rev/42fdcacfd131 branches: changeset: 1675:42fdcacfd131 user: Dmitry Volyntsev date: Fri Jul 09 19:14:23 2021 +0000 description: Marking different external pointer with unique tag. An external value has an arbitrary raw pointer associated with it. External values with different prototypes have different C-level structures. To ensure that only appropriate structures are fetched by njs_vm_external() the unique tag has to be provided during creation of external values. diffstat: nginx/ngx_http_js_module.c | 55 +++++++++++++++++++------------- nginx/ngx_js.c | 6 +- nginx/ngx_js_fetch.c | 19 ++++++----- nginx/ngx_stream_js_module.c | 16 ++++++--- src/njs.h | 5 ++- src/njs_extern.c | 21 +++++++++--- src/njs_shell.c | 71 +++++++++++++++++------------------------- src/njs_value.h | 8 ++++- src/test/njs_externals_test.c | 64 ++++++++++++++++++-------------------- src/test/njs_externals_test.h | 2 +- src/test/njs_unit_test.c | 23 +++++++++---- 11 files changed, 157 insertions(+), 133 deletions(-) diffs (908 lines): diff -r 92cb9b80cf8b -r 42fdcacfd131 nginx/ngx_http_js_module.c --- a/nginx/ngx_http_js_module.c Fri Jul 09 14:01:26 2021 +0000 +++ b/nginx/ngx_http_js_module.c Fri Jul 09 19:14:23 2021 +0000 @@ -1256,7 +1256,7 @@ ngx_http_js_ext_raw_header(njs_vm_t *vm, ngx_table_elt_t *header, *h; ngx_http_request_t *r; - r = njs_vm_external(vm, value); + r = njs_vm_external(vm, ngx_http_js_request_proto_id, value); if (r == NULL) { njs_value_undefined_set(retval); return NJS_DECLINED; @@ -1349,7 +1349,7 @@ ngx_http_js_ext_header_out(njs_vm_t *vm, { njs_str(""), ngx_http_js_header_generic }, }; - r = njs_vm_external(vm, value); + r = njs_vm_external(vm, ngx_http_js_request_proto_id, value); if (r == NULL) { if (retval != NULL) { njs_value_undefined_set(retval); @@ -1840,7 +1840,7 @@ ngx_http_js_ext_keys_header_out(njs_vm_t return NJS_ERROR; } - r = njs_vm_external(vm, value); + r = njs_vm_external(vm, ngx_http_js_request_proto_id, value); if (r == NULL) { return NJS_OK; } @@ -1885,7 +1885,7 @@ ngx_http_js_ext_status(njs_vm_t *vm, njs ngx_int_t n; ngx_http_request_t *r; - r = njs_vm_external(vm, value); + r = njs_vm_external(vm, ngx_http_js_request_proto_id, value); if (r == NULL) { njs_value_undefined_set(retval); return NJS_DECLINED; @@ -1912,7 +1912,8 @@ ngx_http_js_ext_send_header(njs_vm_t *vm { ngx_http_request_t *r; - r = njs_vm_external(vm, njs_arg(args, nargs, 0)); + r = njs_vm_external(vm, ngx_http_js_request_proto_id, + njs_argument(args, 0)); if (r == NULL) { njs_vm_error(vm, "\"this\" is not an external"); return NJS_ERROR; @@ -1945,7 +1946,8 @@ ngx_http_js_ext_send(njs_vm_t *vm, njs_v ngx_http_js_ctx_t *ctx; ngx_http_request_t *r; - r = njs_vm_external(vm, njs_argument(args, 0)); + r = njs_vm_external(vm, ngx_http_js_request_proto_id, + njs_argument(args, 0)); if (r == NULL) { njs_vm_error(vm, "\"this\" is not an external"); return NJS_ERROR; @@ -2033,7 +2035,8 @@ ngx_http_js_ext_send_buffer(njs_vm_t *vm static const njs_str_t last_key = njs_str("last"); static const njs_str_t flush_key = njs_str("flush"); - r = njs_vm_external(vm, njs_argument(args, 0)); + r = njs_vm_external(vm, ngx_http_js_request_proto_id, + njs_argument(args, 0)); if (r == NULL) { njs_vm_error(vm, "\"this\" is not an external"); return NJS_ERROR; @@ -2104,7 +2107,8 @@ ngx_http_js_ext_done(njs_vm_t *vm, njs_v ngx_http_js_ctx_t *ctx; ngx_http_request_t *r; - r = njs_vm_external(vm, njs_argument(args, 0)); + r = njs_vm_external(vm, ngx_http_js_request_proto_id, + njs_argument(args, 0)); if (r == NULL) { njs_vm_error(vm, "\"this\" is not an external"); return NJS_ERROR; @@ -2132,7 +2136,8 @@ ngx_http_js_ext_finish(njs_vm_t *vm, njs ngx_http_js_ctx_t *ctx; ngx_http_request_t *r; - r = njs_vm_external(vm, njs_arg(args, nargs, 0)); + r = njs_vm_external(vm, ngx_http_js_request_proto_id, + njs_argument(args, 0)); if (r == NULL) { njs_vm_error(vm, "\"this\" is not an external"); return NJS_ERROR; @@ -2162,7 +2167,8 @@ ngx_http_js_ext_return(njs_vm_t *vm, njs ngx_http_request_t *r; ngx_http_complex_value_t cv; - r = njs_vm_external(vm, njs_arg(args, nargs, 0)); + r = njs_vm_external(vm, ngx_http_js_request_proto_id, + njs_argument(args, 0)); if (r == NULL) { njs_vm_error(vm, "\"this\" is not an external"); return NJS_ERROR; @@ -2215,7 +2221,8 @@ ngx_http_js_ext_internal_redirect(njs_vm ngx_http_js_ctx_t *ctx; ngx_http_request_t *r; - r = njs_vm_external(vm, njs_arg(args, nargs, 0)); + r = njs_vm_external(vm, ngx_http_js_request_proto_id, + njs_argument(args, 0)); if (r == NULL) { njs_vm_error(vm, "\"this\" is not an external"); return NJS_ERROR; @@ -2256,7 +2263,7 @@ ngx_http_js_ext_get_http_version(njs_vm_ ngx_str_t v; ngx_http_request_t *r; - r = njs_vm_external(vm, value); + r = njs_vm_external(vm, ngx_http_js_request_proto_id, value); if (r == NULL) { njs_value_undefined_set(retval); return NJS_DECLINED; @@ -2302,7 +2309,7 @@ ngx_http_js_ext_get_remote_address(njs_v ngx_connection_t *c; ngx_http_request_t *r; - r = njs_vm_external(vm, value); + r = njs_vm_external(vm, ngx_http_js_request_proto_id, value); if (r == NULL) { njs_value_undefined_set(retval); return NJS_DECLINED; @@ -2328,7 +2335,7 @@ ngx_http_js_ext_get_request_body(njs_vm_ ngx_http_js_ctx_t *ctx; ngx_http_request_t *r; - r = njs_vm_external(vm, value); + r = njs_vm_external(vm, ngx_http_js_request_proto_id, value); if (r == NULL) { njs_value_undefined_set(retval); return NJS_DECLINED; @@ -2425,7 +2432,7 @@ ngx_http_js_ext_header_in(njs_vm_t *vm, { njs_str(""), ngx_http_js_header_generic }, }; - r = njs_vm_external(vm, value); + r = njs_vm_external(vm, ngx_http_js_request_proto_id, value); if (r == NULL) { if (retval != NULL) { njs_value_undefined_set(retval); @@ -2542,7 +2549,7 @@ ngx_http_js_ext_keys_header_in(njs_vm_t return NJS_ERROR; } - r = njs_vm_external(vm, value); + r = njs_vm_external(vm, ngx_http_js_request_proto_id, value); if (r == NULL) { return NJS_OK; } @@ -2559,7 +2566,7 @@ ngx_http_js_ext_get_arg(njs_vm_t *vm, nj ngx_str_t arg; ngx_http_request_t *r; - r = njs_vm_external(vm, value); + r = njs_vm_external(vm, ngx_http_js_request_proto_id, value); if (r == NULL) { njs_value_undefined_set(retval); return NJS_DECLINED; @@ -2595,7 +2602,7 @@ ngx_http_js_ext_keys_arg(njs_vm_t *vm, n return NJS_ERROR; } - r = njs_vm_external(vm, value); + r = njs_vm_external(vm, ngx_http_js_request_proto_id, value); if (r == NULL) { return NJS_OK; } @@ -2646,7 +2653,7 @@ ngx_http_js_ext_variables(njs_vm_t *vm, ngx_http_core_main_conf_t *cmcf; ngx_http_variable_value_t *vv; - r = njs_vm_external(vm, value); + r = njs_vm_external(vm, ngx_http_js_request_proto_id, value); if (r == NULL) { njs_value_undefined_set(retval); return NJS_DECLINED; @@ -2739,7 +2746,8 @@ ngx_http_js_promise_trampoline(njs_vm_t ngx_http_js_ctx_t *ctx; ngx_http_request_t *r; - r = njs_vm_external(vm, njs_argument(args, 1)); + r = njs_vm_external(vm, ngx_http_js_request_proto_id, + njs_arg(args, nargs, 1)); ctx = ngx_http_get_module_ctx(r->parent, ngx_http_js_module); ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, @@ -2823,7 +2831,8 @@ ngx_http_js_ext_subrequest(njs_vm_t *vm, static const njs_str_t body_key = njs_str("body"); static const njs_str_t detached_key = njs_str("detached"); - r = njs_vm_external(vm, njs_arg(args, nargs, 0)); + r = njs_vm_external(vm, ngx_http_js_request_proto_id, + njs_argument(args, 0)); if (r == NULL) { njs_vm_error(vm, "\"this\" is not an external"); return NJS_ERROR; @@ -3165,7 +3174,7 @@ ngx_http_js_ext_get_parent(njs_vm_t *vm, ngx_http_js_ctx_t *ctx; ngx_http_request_t *r; - r = njs_vm_external(vm, value); + r = njs_vm_external(vm, ngx_http_js_request_proto_id, value); if (r == NULL) { njs_value_undefined_set(retval); return NJS_DECLINED; @@ -3197,7 +3206,7 @@ ngx_http_js_ext_get_response_body(njs_vm ngx_http_js_ctx_t *ctx; ngx_http_request_t *r; - r = njs_vm_external(vm, value); + r = njs_vm_external(vm, ngx_http_js_request_proto_id, value); if (r == NULL) { njs_value_undefined_set(retval); return NJS_DECLINED; diff -r 92cb9b80cf8b -r 42fdcacfd131 nginx/ngx_js.c --- a/nginx/ngx_js.c Fri Jul 09 14:01:26 2021 +0000 +++ b/nginx/ngx_js.c Fri Jul 09 19:14:23 2021 +0000 @@ -173,7 +173,7 @@ ngx_js_ext_string(njs_vm_t *vm, njs_obje char *p; ngx_str_t *field; - p = njs_vm_external(vm, value); + p = njs_vm_external(vm, NJS_PROTO_ID_ANY, value); if (p == NULL) { njs_value_undefined_set(retval); return NJS_DECLINED; @@ -192,7 +192,7 @@ ngx_js_ext_uint(njs_vm_t *vm, njs_object char *p; ngx_uint_t field; - p = njs_vm_external(vm, value); + p = njs_vm_external(vm, NJS_PROTO_ID_ANY, value); if (p == NULL) { njs_value_undefined_set(retval); return NJS_DECLINED; @@ -237,7 +237,7 @@ ngx_js_ext_log(njs_vm_t *vm, njs_value_t ngx_connection_t *c; ngx_log_handler_pt handler; - p = njs_vm_external(vm, njs_arg(args, nargs, 0)); + p = njs_vm_external(vm, NJS_PROTO_ID_ANY, njs_argument(args, 0)); if (p == NULL) { njs_vm_error(vm, "\"this\" is not an external"); return NJS_ERROR; diff -r 92cb9b80cf8b -r 42fdcacfd131 nginx/ngx_js_fetch.c --- a/nginx/ngx_js_fetch.c Fri Jul 09 14:01:26 2021 +0000 +++ b/nginx/ngx_js_fetch.c Fri Jul 09 19:14:23 2021 +0000 @@ -345,7 +345,7 @@ ngx_js_ext_fetch(njs_vm_t *vm, njs_value static const njs_str_t body_size_key = njs_str("max_response_body_size"); static const njs_str_t method_key = njs_str("method"); - external = njs_vm_external(vm, njs_argument(args, 0)); + external = njs_vm_external(vm, NJS_PROTO_ID_ANY, njs_argument(args, 0)); if (external == NULL) { njs_vm_error(vm, "\"this\" is not an external"); return NJS_ERROR; @@ -1859,7 +1859,7 @@ ngx_response_js_ext_header_get(njs_vm_t ngx_js_http_t *http; ngx_table_elt_t *header, *h; - http = njs_vm_external(vm, value); + http = njs_vm_external(vm, ngx_http_js_fetch_proto_id, value); if (http == NULL) { njs_value_null_set(retval); return NJS_DECLINED; @@ -2011,7 +2011,7 @@ ngx_response_js_ext_keys(njs_vm_t *vm, n ngx_js_http_t *http; ngx_table_elt_t *h, *headers; - http = njs_vm_external(vm, value); + http = njs_vm_external(vm, ngx_http_js_fetch_proto_id, value); if (http == NULL) { njs_value_undefined_set(keys); return NJS_DECLINED; @@ -2067,7 +2067,8 @@ ngx_response_js_ext_body(njs_vm_t *vm, n ngx_js_http_t *http; njs_opaque_value_t retval; - http = njs_vm_external(vm, njs_argument(args, 0)); + http = njs_vm_external(vm, ngx_http_js_fetch_proto_id, + njs_argument(args, 0)); if (http == NULL) { njs_value_undefined_set(njs_vm_retval(vm)); return NJS_DECLINED; @@ -2124,7 +2125,7 @@ ngx_response_js_ext_body_used(njs_vm_t * { ngx_js_http_t *http; - http = njs_vm_external(vm, value); + http = njs_vm_external(vm, ngx_http_js_fetch_proto_id, value); if (http == NULL) { njs_value_undefined_set(retval); return NJS_DECLINED; @@ -2143,7 +2144,7 @@ ngx_response_js_ext_ok(njs_vm_t *vm, njs ngx_uint_t code; ngx_js_http_t *http; - http = njs_vm_external(vm, value); + http = njs_vm_external(vm, ngx_http_js_fetch_proto_id, value); if (http == NULL) { njs_value_undefined_set(retval); return NJS_DECLINED; @@ -2163,7 +2164,7 @@ ngx_response_js_ext_status(njs_vm_t *vm, { ngx_js_http_t *http; - http = njs_vm_external(vm, value); + http = njs_vm_external(vm, ngx_http_js_fetch_proto_id, value); if (http == NULL) { njs_value_undefined_set(retval); return NJS_DECLINED; @@ -2181,7 +2182,7 @@ ngx_response_js_ext_status_text(njs_vm_t { ngx_js_http_t *http; - http = njs_vm_external(vm, value); + http = njs_vm_external(vm, ngx_http_js_fetch_proto_id, value); if (http == NULL) { njs_value_undefined_set(retval); return NJS_DECLINED; @@ -2201,7 +2202,7 @@ ngx_response_js_ext_type(njs_vm_t *vm, n { ngx_js_http_t *http; - http = njs_vm_external(vm, value); + http = njs_vm_external(vm, ngx_http_js_fetch_proto_id, value); if (http == NULL) { njs_value_undefined_set(retval); return NJS_DECLINED; diff -r 92cb9b80cf8b -r 42fdcacfd131 nginx/ngx_stream_js_module.c --- a/nginx/ngx_stream_js_module.c Fri Jul 09 14:01:26 2021 +0000 +++ b/nginx/ngx_stream_js_module.c Fri Jul 09 19:14:23 2021 +0000 @@ -952,7 +952,7 @@ ngx_stream_js_ext_get_remote_address(njs ngx_connection_t *c; ngx_stream_session_t *s; - s = njs_vm_external(vm, value); + s = njs_vm_external(vm, ngx_stream_js_session_proto_id, value); if (s == NULL) { njs_value_undefined_set(retval); return NJS_DECLINED; @@ -974,7 +974,8 @@ ngx_stream_js_ext_done(njs_vm_t *vm, njs ngx_stream_js_ctx_t *ctx; ngx_stream_session_t *s; - s = njs_vm_external(vm, njs_arg(args, nargs, 0)); + s = njs_vm_external(vm, ngx_stream_js_session_proto_id, + njs_argument(args, 0)); if (s == NULL) { njs_vm_error(vm, "\"this\" is not an external"); return NJS_ERROR; @@ -1025,7 +1026,8 @@ ngx_stream_js_ext_on(njs_vm_t *vm, njs_v njs_vm_event_t *event; ngx_stream_session_t *s; - s = njs_vm_external(vm, njs_arg(args, nargs, 0)); + s = njs_vm_external(vm, ngx_stream_js_session_proto_id, + njs_argument(args, 0)); if (s == NULL) { njs_vm_error(vm, "\"this\" is not an external"); return NJS_ERROR; @@ -1072,7 +1074,8 @@ ngx_stream_js_ext_off(njs_vm_t *vm, njs_ njs_vm_event_t *event; ngx_stream_session_t *s; - s = njs_vm_external(vm, njs_arg(args, nargs, 0)); + s = njs_vm_external(vm, ngx_stream_js_session_proto_id, + njs_argument(args, 0)); if (s == NULL) { njs_vm_error(vm, "\"this\" is not an external"); return NJS_ERROR; @@ -1115,7 +1118,8 @@ ngx_stream_js_ext_send(njs_vm_t *vm, njs static const njs_str_t last_key = njs_str("last"); static const njs_str_t flush_key = njs_str("flush"); - s = njs_vm_external(vm, njs_arg(args, nargs, 0)); + s = njs_vm_external(vm, ngx_stream_js_session_proto_id, + njs_argument(args, 0)); if (s == NULL) { njs_vm_error(vm, "\"this\" is not an external"); return NJS_ERROR; @@ -1194,7 +1198,7 @@ ngx_stream_js_ext_variables(njs_vm_t *vm ngx_stream_core_main_conf_t *cmcf; ngx_stream_variable_value_t *vv; - s = njs_vm_external(vm, value); + s = njs_vm_external(vm, ngx_stream_js_session_proto_id, value); if (s == NULL) { njs_value_undefined_set(retval); return NJS_DECLINED; diff -r 92cb9b80cf8b -r 42fdcacfd131 src/njs.h --- a/src/njs.h Fri Jul 09 14:01:26 2021 +0000 +++ b/src/njs.h Fri Jul 09 19:14:23 2021 +0000 @@ -299,12 +299,14 @@ NJS_EXPORT njs_int_t njs_vm_start(njs_vm NJS_EXPORT njs_int_t njs_vm_add_path(njs_vm_t *vm, const njs_str_t *path); +#define NJS_PROTO_ID_ANY (-1) + NJS_EXPORT njs_int_t njs_vm_external_prototype(njs_vm_t *vm, const njs_external_t *definition, njs_uint_t n); NJS_EXPORT njs_int_t njs_vm_external_create(njs_vm_t *vm, njs_value_t *value, njs_int_t proto_id, njs_external_ptr_t external, njs_bool_t shared); NJS_EXPORT njs_external_ptr_t njs_vm_external(njs_vm_t *vm, - const njs_value_t *value); + njs_int_t proto_id, const njs_value_t *value); NJS_EXPORT uintptr_t njs_vm_meta(njs_vm_t *vm, njs_uint_t index); NJS_EXPORT njs_function_t *njs_vm_function_alloc(njs_vm_t *vm, @@ -381,6 +383,7 @@ NJS_EXPORT void njs_value_number_set(njs NJS_EXPORT uint8_t njs_value_bool(const njs_value_t *value); NJS_EXPORT double njs_value_number(const njs_value_t *value); NJS_EXPORT njs_function_t *njs_value_function(const njs_value_t *value); +NJS_EXPORT njs_int_t njs_value_external_tag(const njs_value_t *value); NJS_EXPORT uint16_t njs_vm_prop_magic16(njs_object_prop_t *prop); NJS_EXPORT uint32_t njs_vm_prop_magic32(njs_object_prop_t *prop); diff -r 92cb9b80cf8b -r 42fdcacfd131 src/njs_extern.c --- a/src/njs_extern.c Fri Jul 09 14:01:26 2021 +0000 +++ b/src/njs_extern.c Fri Jul 09 19:14:23 2021 +0000 @@ -179,7 +179,7 @@ njs_external_prop_handler(njs_vm_t *vm, *retval = *setval; } else { - external = njs_vm_external(vm, value); + external = njs_vm_external(vm, NJS_PROTO_ID_ANY, value); if (njs_slow_path(external == NULL)) { njs_value_undefined_set(retval); return NJS_OK; @@ -203,7 +203,7 @@ njs_external_prop_handler(njs_vm_t *vm, ov->object.__proto__ = &vm->prototypes[NJS_OBJ_TYPE_OBJECT].object; ov->object.slots = slots; - njs_set_data(&ov->value, external, NJS_DATA_TAG_EXTERNAL); + njs_set_data(&ov->value, external, njs_value_external_tag(value)); njs_set_object_value(retval, ov); } @@ -332,18 +332,18 @@ njs_vm_external_create(njs_vm_t *vm, njs ov->object.slots = slots; njs_set_object_value(value, ov); - njs_set_data(&ov->value, external, NJS_DATA_TAG_EXTERNAL); + njs_set_data(&ov->value, external, njs_make_tag(proto_id)); return NJS_OK; } njs_external_ptr_t -njs_vm_external(njs_vm_t *vm, const njs_value_t *value) +njs_vm_external(njs_vm_t *vm, njs_int_t proto_id, const njs_value_t *value) { njs_external_ptr_t external; - if (njs_fast_path(njs_is_object_data(value, NJS_DATA_TAG_EXTERNAL))) { + if (njs_fast_path(njs_is_object_data(value, njs_make_tag(proto_id)))) { external = njs_object_data(value); if (external == NULL) { external = vm->external; @@ -354,3 +354,14 @@ njs_vm_external(njs_vm_t *vm, const njs_ return NULL; } + + +njs_int_t +njs_value_external_tag(const njs_value_t *value) +{ + if (njs_is_object_data(value, njs_make_tag(NJS_PROTO_ID_ANY))) { + return njs_object_value(value)->data.magic32; + } + + return -1; +} diff -r 92cb9b80cf8b -r 42fdcacfd131 src/njs_shell.c --- a/src/njs_shell.c Fri Jul 09 14:01:26 2021 +0000 +++ b/src/njs_shell.c Fri Jul 09 19:14:23 2021 +0000 @@ -202,6 +202,9 @@ static njs_vm_ops_t njs_console_ops = { }; +static njs_int_t njs_console_proto_id; + + static njs_console_t njs_console; @@ -656,38 +659,6 @@ njs_console_init(njs_vm_t *vm, njs_conso } -static njs_value_t * -njs_external_add(njs_vm_t *vm, njs_external_t *definition, - njs_uint_t n, const njs_str_t *name, njs_external_ptr_t external) -{ - njs_int_t ret, proto_id; - njs_value_t *value; - - proto_id = njs_vm_external_prototype(vm, definition, n); - if (njs_slow_path(proto_id < 0)) { - njs_stderror("failed to add \"%V\" proto\n", name); - return NULL; - } - - value = njs_mp_zalloc(vm->mem_pool, sizeof(njs_opaque_value_t)); - if (njs_slow_path(value == NULL)) { - return NULL; - } - - ret = njs_vm_external_create(vm, value, proto_id, external, 0); - if (njs_slow_path(ret != NJS_OK)) { - return NULL; - } - - ret = njs_vm_bind(vm, name, value, 0); - if (njs_slow_path(ret != NJS_OK)) { - return NULL; - } - - return value; -} - - static njs_int_t njs_externals_init(njs_vm_t *vm, njs_console_t *console) { @@ -696,15 +667,31 @@ njs_externals_init(njs_vm_t *vm, njs_con static const njs_str_t console_name = njs_str("console"); static const njs_str_t print_name = njs_str("print"); - static const njs_value_t string_log = njs_string("log"); + static const njs_str_t console_log = njs_str("console.log"); - value = njs_external_add(vm, njs_ext_console, njs_nitems(njs_ext_console), - &console_name, console); + njs_console_proto_id = njs_vm_external_prototype(vm, njs_ext_console, + njs_nitems(njs_ext_console)); + if (njs_slow_path(njs_console_proto_id < 0)) { + njs_stderror("failed to add \"console\" proto\n"); + return NJS_ERROR; + } + + value = njs_mp_zalloc(vm->mem_pool, sizeof(njs_opaque_value_t)); if (njs_slow_path(value == NULL)) { return NJS_ERROR; } - ret = njs_value_property(vm, value, njs_value_arg(&string_log), &method); + ret = njs_vm_external_create(vm, value, njs_console_proto_id, console, 0); + if (njs_slow_path(ret != NJS_OK)) { + return NJS_ERROR; + } + + ret = njs_vm_bind(vm, &console_name, value, 0); + if (njs_slow_path(ret != NJS_OK)) { + return NJS_ERROR; + } + + ret = njs_vm_value(vm, &console_log, &method); if (njs_slow_path(ret != NJS_OK)) { return NJS_ERROR; } @@ -1169,13 +1156,13 @@ njs_ext_console_time(njs_vm_t *vm, njs_v njs_index_t unused) { njs_int_t ret; - njs_console_t *console; + njs_str_t name; njs_value_t *value; + njs_console_t *console; njs_timelabel_t *label; - njs_str_t name; njs_lvlhsh_query_t lhq; - console = njs_vm_external(vm, njs_arg(args, nargs, 0)); + console = njs_vm_external(vm, njs_console_proto_id, njs_argument(args, 0)); if (njs_slow_path(console == NULL)) { njs_type_error(vm, "external value is expected"); return NJS_ERROR; @@ -1244,15 +1231,15 @@ njs_ext_console_time_end(njs_vm_t *vm, n { uint64_t ns, ms; njs_int_t ret; - njs_console_t *console; + njs_str_t name; njs_value_t *value; + njs_console_t *console; njs_timelabel_t *label; - njs_str_t name; njs_lvlhsh_query_t lhq; ns = njs_time(); - console = njs_vm_external(vm, njs_arg(args, nargs, 0)); + console = njs_vm_external(vm, njs_console_proto_id, njs_argument(args, 0)); if (njs_slow_path(console == NULL)) { njs_type_error(vm, "external value is expected"); return NJS_ERROR; diff -r 92cb9b80cf8b -r 42fdcacfd131 src/njs_value.h --- a/src/njs_value.h Fri Jul 09 14:01:26 2021 +0000 +++ b/src/njs_value.h Fri Jul 09 19:14:23 2021 +0000 @@ -594,8 +594,14 @@ typedef struct { ((value)->type <= NJS_STRING) +#define njs_make_tag(proto_id) \ + (((njs_uint_t) proto_id << 8) | NJS_DATA_TAG_EXTERNAL) + + #define njs_is_data(value, tag) \ - ((value)->type == NJS_DATA && value->data.magic32 == (tag)) + ((value)->type == NJS_DATA \ + && ((tag) == njs_make_tag(NJS_PROTO_ID_ANY) \ + || value->data.magic32 == (tag))) #define njs_is_object(value) \ diff -r 92cb9b80cf8b -r 42fdcacfd131 src/test/njs_externals_test.c --- a/src/test/njs_externals_test.c Fri Jul 09 14:01:26 2021 +0000 +++ b/src/test/njs_externals_test.c Fri Jul 09 19:14:23 2021 +0000 @@ -11,7 +11,6 @@ typedef struct { njs_lvlhsh_t hash; - njs_int_t proto_id; uint32_t a; uint32_t d; @@ -27,6 +26,9 @@ typedef struct { } njs_unit_test_prop_t; +static njs_int_t njs_external_r_proto_id; + + static njs_int_t lvlhsh_unit_test_key_test(njs_lvlhsh_query_t *lhq, void *data) { @@ -121,7 +123,7 @@ njs_unit_test_r_uri(njs_vm_t *vm, njs_ob char *p; njs_str_t *field; - p = njs_vm_external(vm, value); + p = njs_vm_external(vm, njs_external_r_proto_id, value); if (p == NULL) { njs_value_undefined_set(retval); return NJS_DECLINED; @@ -145,7 +147,7 @@ njs_unit_test_r_a(njs_vm_t *vm, njs_obje njs_unit_test_req_t *r; u_char buf[16]; - r = njs_vm_external(vm, value); + r = njs_vm_external(vm, njs_external_r_proto_id, value); if (r == NULL) { njs_value_undefined_set(retval); return NJS_DECLINED; @@ -173,7 +175,7 @@ njs_unit_test_r_d(njs_vm_t *vm, njs_obje { njs_unit_test_req_t *r; - r = njs_vm_external(vm, value); + r = njs_vm_external(vm, njs_external_r_proto_id, value); if (r == NULL) { njs_value_undefined_set(retval); return NJS_DECLINED; @@ -211,7 +213,7 @@ njs_unit_test_r_vars(njs_vm_t *vm, njs_o njs_unit_test_req_t *r; njs_unit_test_prop_t *prop; - r = njs_vm_external(vm, value); + r = njs_vm_external(vm, njs_external_r_proto_id, value); if (r == NULL) { njs_value_undefined_set(retval); return NJS_DECLINED; @@ -352,7 +354,7 @@ njs_unit_test_r_method(njs_vm_t *vm, njs njs_str_t s; njs_unit_test_req_t *r; - r = njs_vm_external(vm, njs_arg(args, nargs, 0)); + r = njs_vm_external(vm, njs_external_r_proto_id, njs_argument(args, 0)); if (r == NULL) { njs_type_error(vm, "\"this\" is not an external"); return NJS_ERROR; @@ -377,7 +379,7 @@ njs_unit_test_r_create(njs_vm_t *vm, njs njs_int_t ret; njs_unit_test_req_t *r, *sr; - r = njs_vm_external(vm, njs_arg(args, nargs, 0)); + r = njs_vm_external(vm, njs_external_r_proto_id, njs_argument(args, 0)); if (r == NULL) { njs_type_error(vm, "\"this\" is not an external"); return NJS_ERROR; @@ -394,9 +396,8 @@ njs_unit_test_r_create(njs_vm_t *vm, njs return NJS_ERROR; } - sr->proto_id = r->proto_id; - - ret = njs_vm_external_create(vm, &vm->retval, sr->proto_id, sr, 0); + ret = njs_vm_external_create(vm, &vm->retval, njs_external_r_proto_id, + sr, 0); if (ret != NJS_OK) { return NJS_ERROR; } @@ -418,7 +419,7 @@ njs_unit_test_r_bind(njs_vm_t *vm, njs_v njs_str_t name; njs_unit_test_req_t *r; - r = njs_vm_external(vm, njs_arg(args, nargs, 0)); + r = njs_vm_external(vm, njs_external_r_proto_id, njs_argument(args, 0)); if (r == NULL) { njs_type_error(vm, "\"this\" is not an external"); return NJS_ERROR; @@ -679,45 +680,46 @@ static njs_unit_test_req_init_t njs_test static njs_int_t -njs_externals_init_internal(njs_vm_t *vm, njs_int_t proto_id, - njs_unit_test_req_init_t *init, njs_uint_t n, njs_bool_t shared) +njs_externals_init_internal(njs_vm_t *vm, njs_unit_test_req_init_t *init, + njs_uint_t n, njs_bool_t shared) { njs_int_t ret; njs_uint_t i, j; njs_unit_test_req_t *requests; njs_unit_test_prop_t *prop; - if (proto_id == -1) { - proto_id = njs_vm_external_prototype(vm, njs_unit_test_r_external, + if (shared) { + njs_external_r_proto_id = njs_vm_external_prototype(vm, + njs_unit_test_r_external, njs_nitems(njs_unit_test_r_external)); - if (njs_slow_path(proto_id < 0)) { + if (njs_slow_path(njs_external_r_proto_id < 0)) { njs_printf("njs_vm_external_prototype() failed\n"); - return -1; + return NJS_ERROR; } } requests = njs_mp_zalloc(vm->mem_pool, n * sizeof(njs_unit_test_req_t)); if (njs_slow_path(requests == NULL)) { - return -1; + return NJS_ERROR; } for (i = 0; i < n; i++) { requests[i] = init[i].request; - requests[i].proto_id = proto_id; ret = njs_vm_external_create(vm, njs_value_arg(&requests[i].value), - proto_id, &requests[i], shared); + njs_external_r_proto_id, &requests[i], + shared); if (njs_slow_path(ret != NJS_OK)) { njs_printf("njs_vm_external_create() failed\n"); - return -1; + return NJS_ERROR; } ret = njs_vm_bind(vm, &init[i].name, njs_value_arg(&requests[i].value), shared); if (njs_slow_path(ret != NJS_OK)) { njs_printf("njs_vm_bind() failed\n"); - return -1; + return NJS_ERROR; } for (j = 0; j < njs_nitems(init[i].props); j++) { @@ -726,36 +728,30 @@ njs_externals_init_internal(njs_vm_t *vm if (njs_slow_path(prop == NULL)) { njs_printf("lvlhsh_unit_test_alloc() failed\n"); - return -1; + return NJS_ERROR; } ret = lvlhsh_unit_test_add(vm->mem_pool, &requests[i], prop); if (njs_slow_path(ret != NJS_OK)) { njs_printf("lvlhsh_unit_test_add() failed\n"); - return -1; + return NJS_ERROR; } } } - return proto_id; + return NJS_OK; } njs_int_t njs_externals_shared_init(njs_vm_t *vm) { - return njs_externals_init_internal(vm, -1, njs_test_requests, 1, 1); + return njs_externals_init_internal(vm, njs_test_requests, 1, 1); } njs_int_t -njs_externals_init(njs_vm_t *vm, njs_int_t proto_id) +njs_externals_init(njs_vm_t *vm) { - proto_id = njs_externals_init_internal(vm, proto_id, &njs_test_requests[1], - 3, 0); - if (proto_id < 0) { - return NJS_ERROR; - } - - return NJS_OK; + return njs_externals_init_internal(vm, &njs_test_requests[1], 3, 0); } diff -r 92cb9b80cf8b -r 42fdcacfd131 src/test/njs_externals_test.h --- a/src/test/njs_externals_test.h Fri Jul 09 14:01:26 2021 +0000 +++ b/src/test/njs_externals_test.h Fri Jul 09 19:14:23 2021 +0000 @@ -9,7 +9,7 @@ njs_int_t njs_externals_shared_init(njs_vm_t *vm); -njs_int_t njs_externals_init(njs_vm_t *vm, njs_int_t proto_id); +njs_int_t njs_externals_init(njs_vm_t *vm); #endif /* _NJS_EXTERNALS_TEST_H_INCLUDED_ */ diff -r 92cb9b80cf8b -r 42fdcacfd131 src/test/njs_unit_test.c --- a/src/test/njs_unit_test.c Fri Jul 09 14:01:26 2021 +0000 +++ b/src/test/njs_unit_test.c Fri Jul 09 19:14:23 2021 +0000 @@ -20624,6 +20624,9 @@ static njs_unit_test_t njs_externals_te { njs_str("$r.create('XXX').uri"), njs_str("XXX") }, + { njs_str("$r.create.call([], 'XXX')"), + njs_str("TypeError: \"this\" is not an external") }, + { njs_str("var sr = $r.create('XXX'); sr.uri = 'YYY'; sr.uri"), njs_str("YYY") }, @@ -21198,9 +21201,9 @@ static njs_unit_test_t njs_shell_test[] " at eval (native)\n" " at main (:1)\n") }, - { njs_str("$r.method({}.a.a)" ENTER), + { njs_str("$shared.method({}.a.a)" ENTER), njs_str("TypeError: cannot get property \"a\" of undefined\n" - " at $r3.method (native)\n" + " at $shared.method (native)\n" " at main (:1)\n") }, { njs_str("new Function(\n\n@)" ENTER), @@ -21372,7 +21375,7 @@ njs_unit_test(njs_unit_test_t tests[], s { u_char *start, *end; njs_vm_t *vm, *nvm; - njs_int_t ret, proto_id; + njs_int_t ret; njs_str_t s; njs_uint_t i, repeat; njs_stat_t prev; @@ -21381,7 +21384,6 @@ njs_unit_test(njs_unit_test_t tests[], s vm = NULL; nvm = NULL; - proto_id = -1; prev = *stat; @@ -21405,8 +21407,8 @@ njs_unit_test(njs_unit_test_t tests[], s } if (opts->externals) { - proto_id = njs_externals_shared_init(vm); - if (proto_id < 0) { + ret = njs_externals_shared_init(vm); + if (ret != NJS_OK) { goto done; } } @@ -21435,7 +21437,7 @@ njs_unit_test(njs_unit_test_t tests[], s } if (opts->externals) { - ret = njs_externals_init(nvm, proto_id); + ret = njs_externals_init(nvm); if (ret != NJS_OK) { goto done; } @@ -21539,7 +21541,12 @@ njs_interactive_test(njs_unit_test_t tes } if (opts->externals) { - ret = njs_externals_init(vm, -1); + ret = njs_externals_shared_init(vm); + if (ret != NJS_OK) { + goto done; + } + + ret = njs_externals_init(vm); if (ret != NJS_OK) { goto done; } From maxim at nginx.com Mon Jul 12 13:16:23 2021 From: maxim at nginx.com (Maxim Konovalov) Date: Mon, 12 Jul 2021 16:16:23 +0300 Subject: join nginx developers In-Reply-To: References: Message-ID: Hi Daniil, On 05.07.2021 15:50, Daniil Leonov wrote: > Hi everyone! My name is Daniil. I am C developer. I want to join nginx > development. What are tasks at the moment? > This is great! There are plenty of opened issues in nginx trac here https://trac.nginx.org/ The team is also busy with the QUIC/HTTP/3 implementation and we would be grateful for additional testers or developers hands: https://quic.nginx.org/ I suppose you already seen the nginx dev guide and familiar with nginx internals: http://nginx.org/en/docs/dev/development_guide.html Thanks, Maxim -- Maxim Konovalov From bradley.meck at gmail.com Mon Jul 12 14:24:49 2021 From: bradley.meck at gmail.com (Bradley Farias) Date: Mon, 12 Jul 2021 09:24:49 -0500 Subject: Fwd: Proposal: Add .mjs file extension to known to be JS In-Reply-To: References: Message-ID: See Add .mjs file extension to known JS mime types by bmeck ? Pull Request #71 ? nginx/nginx (github.com) and the related Use .mjs for modules more consistently by mathiasbynens ? Pull Request #3810 ? whatwg/html (github.com) -------------- next part -------------- An HTML attachment was scrubbed... URL: From dnj0496 at gmail.com Mon Jul 12 19:47:46 2021 From: dnj0496 at gmail.com (Dk Jack) Date: Mon, 12 Jul 2021 12:47:46 -0700 Subject: body filter redirect Message-ID: Hi, In my module, I am trying to take actions based on the content of the body. To accomplish this, I am capturing the body using body file as shown in the example below: http://mdounin.ru/hg/ngx_http_catch_body_filter_module/file/tip/ngx_http_catch_body_filter_module.c This is working well. I can inspect the contents of the body and take different actions like rejecting requests etc. However, one of the actions I want to do is redirect the request based on the body content i.e if the content contains some string etc, then redirect the request i.e change the upstream/location etc. My question is, is it even possible to redirect a request in the body filter stage? Is there another way to do body capture/filter and still be able to redirect the request after inspecting the body? Any help, suggestions or sample code is appreciated. Thanks. Dk. -------------- next part -------------- An HTML attachment was scrubbed... URL: From mdounin at mdounin.ru Tue Jul 13 14:48:00 2021 From: mdounin at mdounin.ru (Maxim Dounin) Date: Tue, 13 Jul 2021 17:48:00 +0300 Subject: body filter redirect In-Reply-To: References: Message-ID: Hello! On Mon, Jul 12, 2021 at 12:47:46PM -0700, Dk Jack wrote: > Hi, > In my module, I am trying to take actions based on the content of the body. > To accomplish this, I am capturing the body using body file as shown in the > example below: > > http://mdounin.ru/hg/ngx_http_catch_body_filter_module/file/tip/ngx_http_catch_body_filter_module.c > > This is working well. I can inspect the contents of the body and take > different actions like rejecting requests etc. However, one of the actions > I want to do is redirect the request based on the body content i.e if the > content contains some string etc, then redirect the request i.e change the > upstream/location etc. My question is, is it even possible to redirect a > request in the body filter stage? Is there another way to do body > capture/filter and still be able to redirect the request after inspecting > the body? Any help, suggestions or sample code is appreciated. Thanks. It is generally too late to do any actions like "change the upstream/location etc" based on the body content, as the request body is usually read only when the location is already known and the upstream name is already obtained. Also consider "proxy_request_buffering off;" - reading the request body implies that nginx is sending the request body to the backend as well. That is, you can't really do more than modifying the request body or rejecting the request completely. You may, however, provide some variables from your body request body filter - and, if it's possible in your particular configuration, use these variables to do some conditional processing. Note thought that conditional processing needs to happen after the request body is read. As such, it is usually quite limited, especially when using standard modules, since the request body is usually read last. For example, with proxy the request body is read after the variables in the "proxy_pass" directive are evaluated, so even with "proxy_request_buffering on;" (the default) you cannot use the variables from your request body filter module to change the upstream. You can, however, use it to control headers in the upstream request by using "proxy_set_header" with appropriate variables (again, assuming buffered request body reading - for obvious reasons this won't work with "proxy_request_buffering off;"). More flexibility can be achieved by reading the request body earlier - for example, you can do this from your own module, or with embedded scripting such as perl or njs. -- Maxim Dounin http://mdounin.ru/ From xeioex at nginx.com Tue Jul 13 15:23:33 2021 From: xeioex at nginx.com (Dmitry Volyntsev) Date: Tue, 13 Jul 2021 15:23:33 +0000 Subject: [njs] Added fs flags missed in 5c6aa60224cb (0.1.15). Message-ID: details: https://hg.nginx.org/njs/rev/537f897451ef branches: changeset: 1676:537f897451ef user: hyeonisism date: Tue Jul 13 10:23:23 2021 +0900 description: Added fs flags missed in 5c6aa60224cb (0.1.15). This closes #405 issue on Github. diffstat: src/njs_fs.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diffs (12 lines): diff -r 42fdcacfd131 -r 537f897451ef src/njs_fs.c --- a/src/njs_fs.c Fri Jul 09 19:14:23 2021 +0000 +++ b/src/njs_fs.c Tue Jul 13 10:23:23 2021 +0900 @@ -112,6 +112,8 @@ static njs_fs_entry_t njs_flags_table[] { njs_str("w+"), O_TRUNC | O_CREAT | O_RDWR }, { njs_str("a"), O_APPEND | O_CREAT | O_WRONLY }, { njs_str("a+"), O_APPEND | O_CREAT | O_RDWR }, + { njs_str("as"), O_SYNC | O_APPEND | O_CREAT | O_WRONLY }, + { njs_str("as+"), O_SYNC | O_APPEND | O_CREAT | O_RDWR }, { njs_str("rs"), O_SYNC | O_RDONLY }, { njs_str("sr"), O_SYNC | O_RDONLY }, { njs_str("wx"), O_TRUNC | O_CREAT | O_EXCL | O_WRONLY }, From xeioex at nginx.com Tue Jul 13 15:23:34 2021 From: xeioex at nginx.com (Dmitry Volyntsev) Date: Tue, 13 Jul 2021 15:23:34 +0000 Subject: [njs] Added support for ArrayBuffer in njs_vm_value_to_bytes(). Message-ID: details: https://hg.nginx.org/njs/rev/e37a80fac86f branches: changeset: 1677:e37a80fac86f user: Dmitry Volyntsev date: Tue Jul 13 15:22:24 2021 +0000 description: Added support for ArrayBuffer in njs_vm_value_to_bytes(). diffstat: src/njs_vm.c | 22 +++++++++++++++++----- 1 files changed, 17 insertions(+), 5 deletions(-) diffs (44 lines): diff -r 537f897451ef -r e37a80fac86f src/njs_vm.c --- a/src/njs_vm.c Tue Jul 13 10:23:23 2021 +0900 +++ b/src/njs_vm.c Tue Jul 13 15:22:24 2021 +0000 @@ -1131,7 +1131,7 @@ njs_int_t njs_vm_value_to_bytes(njs_vm_t *vm, njs_str_t *dst, njs_value_t *src) { u_char *start; - size_t size; + size_t size, length, offset; njs_int_t ret; njs_value_t value; njs_typed_array_t *array; @@ -1147,15 +1147,27 @@ njs_vm_value_to_bytes(njs_vm_t *vm, njs_ switch (value.type) { case NJS_TYPED_ARRAY: case NJS_DATA_VIEW: - array = njs_typed_array(&value); - buffer = njs_typed_array_buffer(array); + case NJS_ARRAY_BUFFER: + + if (value.type != NJS_ARRAY_BUFFER) { + array = njs_typed_array(&value); + buffer = njs_typed_array_buffer(array); + offset = array->offset; + length = array->byte_length; + + } else { + buffer = njs_array_buffer(&value); + offset = 0; + length = buffer->size; + } + if (njs_slow_path(njs_is_detached_buffer(buffer))) { njs_type_error(vm, "detached buffer"); return NJS_ERROR; } - dst->start = &buffer->u.u8[array->offset]; - dst->length = array->byte_length; + dst->start = &buffer->u.u8[offset]; + dst->length = length; break; default: From mdounin at mdounin.ru Tue Jul 13 17:36:31 2021 From: mdounin at mdounin.ru (Maxim Dounin) Date: Tue, 13 Jul 2021 20:36:31 +0300 Subject: Fwd: Proposal: Add .mjs file extension to known to be JS In-Reply-To: References: Message-ID: Hello! On Mon, Jul 12, 2021 at 09:24:49AM -0500, Bradley Farias wrote: > See Add .mjs file extension to known JS mime types by bmeck ? Pull Request > #71 ? nginx/nginx (github.com) and > the related Use .mjs for modules more consistently by mathiasbynens ? Pull > Request #3810 ? whatwg/html (github.com) > Interestingly enough, the pull request in whatwg you are referencing claims that "on the web file extensions doesn't matter", yet your suggested change means exactly the opposite. For a mime.types change you think is needed, consider opening a ticket on trac.nginx.org. If/when there is a consensus that the change is needed, the change will be committed. For now the mjs extension does not seem to be widely used except by Node.js. -- Maxim Dounin http://mdounin.ru/ From bradley.meck at gmail.com Tue Jul 13 17:48:51 2021 From: bradley.meck at gmail.com (Bradley Farias) Date: Tue, 13 Jul 2021 12:48:51 -0500 Subject: Fwd: Proposal: Add .mjs file extension to known to be JS In-Reply-To: References: Message-ID: The proposal instructions on the nginx website state that it is for bug fixes and so it seems that would be the wrong place to put a proposal. I can do so and cross reference. To be clear; whatwg is using it in their specifications without any Node usage implied; if files are produced with that file extension by copy and pasting the specification examples (such as those in HTML Standard (whatwg.org) ), they would fail on nginx. There is also an IETF MIME update that should finally be published soon: draft-ietf-dispatch-javascript-mjs-09 - ECMAScript Media Types Updates . If the goal is not to be compatible, but only to apply to file extensions after they are popular, that seems a bit odd to me at least since it means knowing that upcoming things are potentially incompatible and willfully not preparing until after the problems occur. On Tue, Jul 13, 2021 at 12:36 PM Maxim Dounin wrote: > Hello! > > On Mon, Jul 12, 2021 at 09:24:49AM -0500, Bradley Farias wrote: > > > See Add .mjs file extension to known JS mime types by bmeck ? Pull > Request > > #71 ? nginx/nginx (github.com) > and > > the related Use .mjs for modules more consistently by mathiasbynens ? > Pull > > Request #3810 ? whatwg/html (github.com) > > > > Interestingly enough, the pull request in whatwg you are referencing > claims that "on the web file extensions doesn't matter", yet your > suggested change means exactly the opposite. > > For a mime.types change you think is needed, consider opening a > ticket on trac.nginx.org. If/when there is a consensus that the > change is needed, the change will be committed. For now the mjs > extension does not seem to be widely used except by Node.js. > > -- > Maxim Dounin > http://mdounin.ru/ > _______________________________________________ > nginx-devel mailing list > nginx-devel at nginx.org > http://mailman.nginx.org/mailman/listinfo/nginx-devel -------------- next part -------------- An HTML attachment was scrubbed... URL: From mdounin at mdounin.ru Tue Jul 13 20:34:56 2021 From: mdounin at mdounin.ru (Maxim Dounin) Date: Tue, 13 Jul 2021 23:34:56 +0300 Subject: Fwd: Proposal: Add .mjs file extension to known to be JS In-Reply-To: References: Message-ID: Hello! On Tue, Jul 13, 2021 at 12:48:51PM -0500, Bradley Farias wrote: > The proposal instructions on the nginx website state that it is for > bug fixes and so it seems that would be the wrong place to put a proposal. > I can do so and cross reference. Thanks for the ticket. > To be clear; whatwg is using it in their specifications without any Node > usage implied; if files are produced with that file extension by copy and > pasting the specification examples (such as those in HTML Standard > (whatwg.org) > ), > they would fail on nginx. Thanks for the details. That's the expected result of the change made to the specification, with the false rationale that extensions don't matter. > There is also an IETF MIME update that should > finally be published soon: draft-ietf-dispatch-javascript-mjs-09 - > ECMAScript Media Types Updates > . Looking forward for seeing it published. > If the goal is not to be compatible, but only to apply to file extensions > after they are popular, that seems a bit odd to me at least since it means > knowing that upcoming things are potentially incompatible and willfully not > preparing until after the problems occur. We are not trying to support every possible extension or MIME type out there in the default mime.types configuration snippet, so there are lots of "potentially incompatible" things at any given moment. On the other hand, every nginx user is free to configure any extensions and MIME types used by the particular server by using the "types" configuration directive, so "potentially incompatible" rather means "requires additional configuration", and this is expected to be good enough until it is clear that the particular extension or MIME type is popular enough to be added to default mime.types. -- Maxim Dounin http://mdounin.ru/ From dnj0496 at gmail.com Wed Jul 14 04:28:15 2021 From: dnj0496 at gmail.com (Dk Jack) Date: Tue, 13 Jul 2021 21:28:15 -0700 Subject: body filter redirect In-Reply-To: References: Message-ID: Hello Maxim, Thanks for responding. Can I get some clarification on what you mean by the statement below: "More flexibility can be achieved by reading the request body earlier - for example, you can do this from your own module, or with embedded scripting such as perl or njs." Are you suggesting that I use ngx_http_read_client_request_body api in my module? http://nginx.org/en/docs/dev/development_guide.html#http_request_body I had similar trouble using that API with redirection. Are there some tricks to getting it to work when using that API? Are there any reference implementations doing redirection after inspecting the request body? Thanks for your help! Dk. > Hello! > It is generally too late to do any actions like "change the > upstream/location etc" based on the body content, as the request > body is usually read only when the location is already known and > the upstream name is already obtained. Also consider > "proxy_request_buffering off;" - reading the request body implies > that nginx is sending the request body to the backend as well. > That is, you can't really do more than modifying the request body > or rejecting the request completely. > > You may, however, provide some variables from your body request > body filter - and, if it's possible in your particular > configuration, use these variables to do some conditional > processing. > > Note thought that conditional processing needs to happen after the > request body is read. As such, it is usually quite limited, > especially when using standard modules, since the request body is > usually read last. > > For example, with proxy the request body is read after the > variables in the "proxy_pass" directive are evaluated, so even > with "proxy_request_buffering on;" (the default) you cannot use > the variables from your request body filter module to change the > upstream. You can, however, use it to control headers in the > upstream request by using "proxy_set_header" with appropriate > variables (again, assuming buffered request body reading - for > obvious reasons this won't work with "proxy_request_buffering > off;"). > > More flexibility can be achieved by reading the request body > earlier - for example, you can do this from your own module, or > with embedded scripting such as perl or njs. > > -- > Maxim Dounin > http://mdounin.ru/ > _______________________________________________ > nginx-devel mailing list > nginx-devel at nginx.org > http://mailman.nginx.org/mailman/listinfo/nginx-devel > On Mon, Jul 12, 2021 at 12:47 PM Dk Jack wrote: > Hi, > In my module, I am trying to take actions based on the content of the > body. To accomplish this, I am capturing the body using body file as shown > in the example below: > > > http://mdounin.ru/hg/ngx_http_catch_body_filter_module/file/tip/ngx_http_catch_body_filter_module.c > > This is working well. I can inspect the contents of the body and take > different actions like rejecting requests etc. However, one of the actions > I want to do is redirect the request based on the body content i.e if the > content contains some string etc, then redirect the request i.e change the > upstream/location etc. My question is, is it even possible to redirect a > request in the body filter stage? Is there another way to do body > capture/filter and still be able to redirect the request after inspecting > the body? Any help, suggestions or sample code is appreciated. Thanks. > > Dk. > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From xeioex at nginx.com Wed Jul 14 13:19:52 2021 From: xeioex at nginx.com (Dmitry Volyntsev) Date: Wed, 14 Jul 2021 13:19:52 +0000 Subject: [njs] File flags table cleanup. Message-ID: details: https://hg.nginx.org/njs/rev/1cfcce81e4e9 branches: changeset: 1678:1cfcce81e4e9 user: Dmitry Volyntsev date: Wed Jul 14 13:18:56 2021 +0000 description: File flags table cleanup. diffstat: src/njs_fs.c | 29 +++++++++++------------------ 1 files changed, 11 insertions(+), 18 deletions(-) diffs (41 lines): diff -r e37a80fac86f -r 1cfcce81e4e9 src/njs_fs.c --- a/src/njs_fs.c Tue Jul 13 15:22:24 2021 +0000 +++ b/src/njs_fs.c Wed Jul 14 13:18:56 2021 +0000 @@ -106,26 +106,19 @@ static njs_int_t njs_fs_dirent_create(nj njs_value_t *type, njs_value_t *retval); static njs_fs_entry_t njs_flags_table[] = { + { njs_str("a"), O_APPEND | O_CREAT | O_WRONLY }, + { njs_str("a+"), O_APPEND | O_CREAT | O_RDWR }, + { njs_str("as"), O_APPEND | O_CREAT | O_SYNC | O_WRONLY }, + { njs_str("as+"), O_APPEND | O_CREAT | O_RDWR | O_SYNC }, + { njs_str("ax"), O_APPEND | O_CREAT | O_EXCL | O_WRONLY }, + { njs_str("ax+"), O_APPEND | O_CREAT | O_EXCL | O_RDWR }, { njs_str("r"), O_RDONLY }, { njs_str("r+"), O_RDWR }, - { njs_str("w"), O_TRUNC | O_CREAT | O_WRONLY }, - { njs_str("w+"), O_TRUNC | O_CREAT | O_RDWR }, - { njs_str("a"), O_APPEND | O_CREAT | O_WRONLY }, - { njs_str("a+"), O_APPEND | O_CREAT | O_RDWR }, - { njs_str("as"), O_SYNC | O_APPEND | O_CREAT | O_WRONLY }, - { njs_str("as+"), O_SYNC | O_APPEND | O_CREAT | O_RDWR }, - { njs_str("rs"), O_SYNC | O_RDONLY }, - { njs_str("sr"), O_SYNC | O_RDONLY }, - { njs_str("wx"), O_TRUNC | O_CREAT | O_EXCL | O_WRONLY }, - { njs_str("xw"), O_TRUNC | O_CREAT | O_EXCL | O_WRONLY }, - { njs_str("ax"), O_APPEND | O_CREAT | O_EXCL | O_WRONLY }, - { njs_str("xa"), O_APPEND | O_CREAT | O_EXCL | O_WRONLY }, - { njs_str("rs+"), O_SYNC | O_RDWR }, - { njs_str("sr+"), O_SYNC | O_RDWR }, - { njs_str("wx+"), O_TRUNC | O_CREAT | O_EXCL | O_RDWR }, - { njs_str("xw+"), O_TRUNC | O_CREAT | O_EXCL | O_RDWR }, - { njs_str("ax+"), O_APPEND | O_CREAT | O_EXCL | O_RDWR }, - { njs_str("xa+"), O_APPEND | O_CREAT | O_EXCL | O_RDWR }, + { njs_str("rs+"), O_RDWR | O_SYNC }, + { njs_str("w"), O_CREAT | O_TRUNC | O_WRONLY }, + { njs_str("w+"), O_CREAT | O_TRUNC | O_RDWR }, + { njs_str("wx"), O_CREAT | O_TRUNC | O_EXCL | O_WRONLY }, + { njs_str("wx+"), O_CREAT | O_TRUNC | O_EXCL | O_RDWR }, { njs_null_str, 0 } }; From xeioex at nginx.com Thu Jul 15 15:43:02 2021 From: xeioex at nginx.com (Dmitry Volyntsev) Date: Thu, 15 Jul 2021 15:43:02 +0000 Subject: [njs] Added generic AST traverser. Message-ID: details: https://hg.nginx.org/njs/rev/1ed302b68909 branches: changeset: 1679:1ed302b68909 user: Dmitry Volyntsev date: Thu Jul 15 14:51:57 2021 +0000 description: Added generic AST traverser. diffstat: src/njs_parser.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/njs_parser.h | 6 ++++ 2 files changed, 75 insertions(+), 0 deletions(-) diffs (102 lines): diff -r 1cfcce81e4e9 -r 1ed302b68909 src/njs_parser.c --- a/src/njs_parser.c Wed Jul 14 13:18:56 2021 +0000 +++ b/src/njs_parser.c Thu Jul 15 14:51:57 2021 +0000 @@ -8689,6 +8689,75 @@ njs_parser_node_error(njs_vm_t *vm, njs_ njs_int_t +njs_parser_traverse(njs_vm_t *vm, njs_parser_node_t *root, void *ctx, + njs_parser_traverse_cb_t cb) +{ + njs_int_t ret; + njs_arr_t *stack; + njs_parser_node_t *node, **ref; + + if (root == NULL) { + return NJS_OK; + } + + stack = njs_arr_create(vm->mem_pool, 8, sizeof(njs_parser_node_t *)); + if (njs_slow_path(stack == NULL)) { + return NJS_ERROR; + + } + + ref = njs_arr_add(stack); + if (njs_slow_path(ref == NULL)) { + goto failed; + } + + *ref = root; + + while (1) { + if (njs_arr_is_empty(stack)) { + break; + } + + ref = njs_arr_remove_last(stack); + node = *ref; + + ret = cb(vm, node, ctx); + if (njs_slow_path(ret != NJS_OK)) { + goto failed; + } + + if (node->left != NULL) { + ref = njs_arr_add(stack); + if (njs_slow_path(ref == NULL)) { + goto failed; + } + + *ref = node->left; + } + + if (node->right != NULL) { + ref = njs_arr_add(stack); + if (njs_slow_path(ref == NULL)) { + goto failed; + } + + *ref = node->right; + } + } + + njs_arr_destroy(stack); + + return NJS_OK; + +failed: + + njs_arr_destroy(stack); + + return NJS_ERROR; +} + + +njs_int_t njs_parser_serialize_ast(njs_parser_node_t *node, njs_chb_t *chain) { njs_int_t ret; diff -r 1cfcce81e4e9 -r 1ed302b68909 src/njs_parser.h --- a/src/njs_parser.h Wed Jul 14 13:18:56 2021 +0000 +++ b/src/njs_parser.h Thu Jul 15 14:51:57 2021 +0000 @@ -102,6 +102,10 @@ typedef struct { } njs_parser_rbtree_node_t; +typedef njs_int_t (*njs_parser_traverse_cb_t)(njs_vm_t *vm, + njs_parser_node_t *node, void *ctx); + + njs_int_t njs_parser_failed_state(njs_parser_t *parser, njs_lexer_token_t *token, njs_queue_link_t *current); @@ -128,6 +132,8 @@ void njs_parser_lexer_error(njs_parser_t void njs_parser_node_error(njs_vm_t *vm, njs_parser_node_t *node, njs_object_type_t type, const char *fmt, ...); +njs_int_t njs_parser_traverse(njs_vm_t *vm, njs_parser_node_t *root, + void *ctx, njs_parser_traverse_cb_t cb); njs_int_t njs_parser_serialize_ast(njs_parser_node_t *node, njs_chb_t *chain); From alexander.borisov at nginx.com Thu Jul 15 17:34:49 2021 From: alexander.borisov at nginx.com (Alexander Borisov) Date: Thu, 15 Jul 2021 17:34:49 +0000 Subject: [njs] Removed recursion from code generator. Message-ID: details: https://hg.nginx.org/njs/rev/efdc5f18195e branches: changeset: 1680:efdc5f18195e user: Alexander Borisov date: Thu Jul 15 20:32:40 2021 +0300 description: Removed recursion from code generator. diffstat: src/njs_generator.c | 3118 ++++++++++++++++++++++++++++++--------------- src/njs_generator.h | 10 + src/test/njs_unit_test.c | 53 +- 3 files changed, 2141 insertions(+), 1040 deletions(-) diffs (truncated from 4386 to 1000 lines): diff -r 1ed302b68909 -r efdc5f18195e src/njs_generator.c --- a/src/njs_generator.c Thu Jul 15 14:51:57 2021 +0000 +++ b/src/njs_generator.c Thu Jul 15 20:32:40 2021 +0300 @@ -12,6 +12,15 @@ typedef struct njs_generator_patch_s njs_generator_patch_t; +typedef enum { + NJS_GENERATOR_LOOP = 1, + NJS_GENERATOR_SWITCH = 2, + NJS_GENERATOR_BLOCK = 4, + NJS_GENERATOR_TRY = 8, +#define NJS_GENERATOR_ALL (NJS_GENERATOR_LOOP | NJS_GENERATOR_SWITCH) +} njs_generator_block_type_t; + + struct njs_generator_patch_s { /* * The jump_offset field points to jump offset field which contains a small @@ -26,15 +35,6 @@ struct njs_generator_patch_s { }; -typedef enum { - NJS_GENERATOR_LOOP = 1, - NJS_GENERATOR_SWITCH = 2, - NJS_GENERATOR_BLOCK = 4, - NJS_GENERATOR_TRY = 8, -#define NJS_GENERATOR_ALL (NJS_GENERATOR_LOOP | NJS_GENERATOR_SWITCH) -} njs_generator_block_type_t; - - struct njs_generator_block_s { njs_generator_block_type_t type; /* 4 bits */ njs_str_t label; @@ -54,12 +54,50 @@ struct njs_generator_block_s { }; -static njs_int_t njs_generator(njs_vm_t *vm, njs_generator_t *generator, - njs_parser_node_t *node); +typedef struct { + njs_generator_state_func_t state; + njs_queue_link_t link; + njs_parser_node_t *node; + void *context; +} njs_generator_stack_entry_t; + + +typedef struct { + njs_generator_patch_t *patch; + njs_generator_patch_t **last; + njs_vmcode_jump_t *jump; + njs_jump_off_t jump_offset; + njs_index_t index; +} njs_generator_switch_ctx_t; + + +typedef struct { + njs_jump_off_t jump_offset; + njs_jump_off_t loop_offset; + njs_vmcode_jump_t *jump; + njs_variable_t *var; + njs_index_t index; +} njs_generator_loop_ctx_t; + + +typedef struct { + njs_index_t exception_index; + njs_jump_off_t try_offset; + njs_jump_off_t catch_offset; + njs_generator_block_t *try_block; + njs_generator_block_t *catch_block; + njs_str_t try_cont_label; + njs_str_t try_exit_label; + njs_str_t catch_cont_label; + njs_str_t catch_exit_label; +} njs_generator_try_ctx_t; + + static u_char *njs_generate_reserve(njs_vm_t *vm, njs_generator_t *generator, size_t size); static njs_int_t njs_generate_code_map(njs_vm_t *vm, njs_generator_t *generator, njs_parser_node_t *node, u_char *code); + static njs_int_t njs_generate_name(njs_vm_t *vm, njs_generator_t *generator, njs_parser_node_t *node); static njs_int_t njs_generate_variable(njs_vm_t *vm, njs_generator_t *generator, @@ -67,26 +105,72 @@ static njs_int_t njs_generate_variable(n njs_variable_t **retvar); static njs_int_t njs_generate_var_statement(njs_vm_t *vm, njs_generator_t *generator, njs_parser_node_t *node); +static njs_int_t njs_generate_var_statement_after(njs_vm_t *vm, + njs_generator_t *generator, njs_parser_node_t *node); static njs_int_t njs_generate_let(njs_vm_t *vm, njs_generator_t *generator, njs_parser_node_t *node, njs_variable_t *var); static njs_int_t njs_generate_if_statement(njs_vm_t *vm, njs_generator_t *generator, njs_parser_node_t *node); +static njs_int_t njs_generate_if_statement_cond(njs_vm_t *vm, + njs_generator_t *generator, njs_parser_node_t *node); +static njs_int_t njs_generate_if_statement_then(njs_vm_t *vm, + njs_generator_t *generator, njs_parser_node_t *node); +static njs_int_t njs_generate_if_statement_else(njs_vm_t *vm, + njs_generator_t *generator, njs_parser_node_t *node); static njs_int_t njs_generate_cond_expression(njs_vm_t *vm, njs_generator_t *generator, njs_parser_node_t *node); +static njs_int_t njs_generate_cond_expression_handler(njs_vm_t *vm, + njs_generator_t *generator, njs_parser_node_t *node); +static njs_int_t njs_generate_cond_expression_true(njs_vm_t *vm, + njs_generator_t *generator, njs_parser_node_t *node); +static njs_int_t njs_generate_cond_expression_false(njs_vm_t *vm, + njs_generator_t *generator, njs_parser_node_t *node); static njs_int_t njs_generate_switch_statement(njs_vm_t *vm, njs_generator_t *generator, njs_parser_node_t *node); +static njs_int_t njs_generate_switch_expression(njs_vm_t *vm, + njs_generator_t *generator, njs_parser_node_t *swtch); +static njs_int_t njs_generate_switch_case(njs_vm_t *vm, + njs_generator_t *generator, njs_parser_node_t *swtch); +static njs_int_t njs_generate_switch_case_after(njs_vm_t *vm, + njs_generator_t *generator, njs_parser_node_t *branch); +static njs_int_t njs_generate_switch_case_end(njs_vm_t *vm, + njs_generator_t *generator, njs_parser_node_t *branch); +static njs_int_t njs_generate_switch_default(njs_vm_t *vm, + njs_generator_t *generator, njs_parser_node_t *branch); +static njs_int_t njs_generate_switch_end(njs_vm_t *vm, + njs_generator_t *generator, njs_parser_node_t *swtch); static njs_int_t njs_generate_while_statement(njs_vm_t *vm, njs_generator_t *generator, njs_parser_node_t *node); +static njs_int_t njs_generate_while_condition(njs_vm_t *vm, + njs_generator_t *generator, njs_parser_node_t *node); +static njs_int_t njs_generate_while_end(njs_vm_t *vm, + njs_generator_t *generator, njs_parser_node_t *node); static njs_int_t njs_generate_do_while_statement(njs_vm_t *vm, njs_generator_t *generator, njs_parser_node_t *node); +static njs_int_t njs_generate_do_while_condition(njs_vm_t *vm, + njs_generator_t *generator, njs_parser_node_t *node); +static njs_int_t njs_generate_do_while_end(njs_vm_t *vm, + njs_generator_t *generator, njs_parser_node_t *node); static njs_int_t njs_generate_for_statement(njs_vm_t *vm, njs_generator_t *generator, njs_parser_node_t *node); +static njs_int_t njs_generate_for_init(njs_vm_t *vm, njs_generator_t *generator, + njs_parser_node_t *node); +static njs_int_t njs_generate_for_body(njs_vm_t *vm, njs_generator_t *generator, + njs_parser_node_t *node); +static njs_int_t njs_generate_for_update(njs_vm_t *vm, + njs_generator_t *generator, njs_parser_node_t *node); +static njs_int_t njs_generate_for_end(njs_vm_t *vm, njs_generator_t *generator, + njs_parser_node_t *node); static njs_int_t njs_generate_for_let_update(njs_vm_t *vm, njs_generator_t *generator, njs_parser_node_t *node, size_t depth); static njs_int_t njs_generate_for_resolve_closure(njs_vm_t *vm, njs_parser_node_t *node, size_t depth); static njs_int_t njs_generate_for_in_statement(njs_vm_t *vm, njs_generator_t *generator, njs_parser_node_t *node); +static njs_int_t njs_generate_for_in_object(njs_vm_t *vm, + njs_generator_t *generator, njs_parser_node_t *node); +static njs_int_t njs_generate_for_in_body(njs_vm_t *vm, + njs_generator_t *generator, njs_parser_node_t *node); static njs_int_t njs_generate_start_block(njs_vm_t *vm, njs_generator_t *generator, njs_generator_block_type_t type, const njs_str_t *label); @@ -117,20 +201,40 @@ static njs_int_t njs_generate_statement( njs_generator_t *generator, njs_parser_node_t *node); static njs_int_t njs_generate_block_statement(njs_vm_t *vm, njs_generator_t *generator, njs_parser_node_t *node); +static njs_int_t njs_generate_block_statement_end(njs_vm_t *vm, + njs_generator_t *generator, njs_parser_node_t *node); static njs_int_t njs_generate_children(njs_vm_t *vm, njs_generator_t *generator, njs_parser_node_t *node); static njs_int_t njs_generate_stop_statement(njs_vm_t *vm, njs_generator_t *generator, njs_parser_node_t *node); +static njs_int_t njs_generate_stop_statement_end(njs_vm_t *vm, + njs_generator_t *generator, njs_parser_node_t *node); static njs_int_t njs_generate_comma_expression(njs_vm_t *vm, njs_generator_t *generator, njs_parser_node_t *node); +static njs_int_t njs_generate_comma_expression_end(njs_vm_t *vm, + njs_generator_t *generator, njs_parser_node_t *node); static njs_int_t njs_generate_assignment(njs_vm_t *vm, njs_generator_t *generator, njs_parser_node_t *node); +static njs_int_t njs_generate_assignment_name(njs_vm_t *vm, + njs_generator_t *generator, njs_parser_node_t *node); +static njs_int_t njs_generate_assignment_prop(njs_vm_t *vm, + njs_generator_t *generator, njs_parser_node_t *node); +static njs_int_t njs_generate_assignment_end(njs_vm_t *vm, + njs_generator_t *generator, njs_parser_node_t *node); static njs_int_t njs_generate_operation_assignment(njs_vm_t *vm, njs_generator_t *generator, njs_parser_node_t *node); +static njs_int_t njs_generate_operation_assignment_name(njs_vm_t *vm, + njs_generator_t *generator, njs_parser_node_t *node); +static njs_int_t njs_generate_operation_assignment_prop(njs_vm_t *vm, + njs_generator_t *generator, njs_parser_node_t *node); +static njs_int_t njs_generate_operation_assignment_end(njs_vm_t *vm, + njs_generator_t *generator, njs_parser_node_t *node); static njs_int_t njs_generate_object(njs_vm_t *vm, njs_generator_t *generator, njs_parser_node_t *node); static njs_int_t njs_generate_property_accessor(njs_vm_t *vm, njs_generator_t *generator, njs_parser_node_t *node); +static njs_int_t njs_generate_property_accessor_end(njs_vm_t *vm, + njs_generator_t *generator, njs_parser_node_t *node); static njs_int_t njs_generate_array(njs_vm_t *vm, njs_generator_t *generator, njs_parser_node_t *node); static njs_int_t njs_generate_function_expression(njs_vm_t *vm, @@ -141,41 +245,92 @@ static njs_int_t njs_generate_regexp(njs njs_parser_node_t *node); static njs_int_t njs_generate_template_literal(njs_vm_t *vm, njs_generator_t *generator, njs_parser_node_t *node); +static njs_int_t njs_generate_template_literal_end(njs_vm_t *vm, + njs_generator_t *generator, njs_parser_node_t *node); static njs_int_t njs_generate_test_jump_expression(njs_vm_t *vm, njs_generator_t *generator, njs_parser_node_t *node); +static njs_int_t njs_generate_test_jump_expression_after(njs_vm_t *vm, + njs_generator_t *generator, njs_parser_node_t *node); +static njs_int_t njs_generate_test_jump_expression_end(njs_vm_t *vm, + njs_generator_t *generator, njs_parser_node_t *node); static njs_int_t njs_generate_3addr_operation(njs_vm_t *vm, njs_generator_t *generator, njs_parser_node_t *node, njs_bool_t swap); +static njs_int_t njs_generate_3addr_operation_name(njs_vm_t *vm, + njs_generator_t *generator, njs_parser_node_t *node); +static njs_int_t njs_generate_3addr_operation_end(njs_vm_t *vm, + njs_generator_t *generator, njs_parser_node_t *node); static njs_int_t njs_generate_2addr_operation(njs_vm_t *vm, njs_generator_t *generator, njs_parser_node_t *node); +static njs_int_t njs_generate_2addr_operation_end(njs_vm_t *vm, + njs_generator_t *generator, njs_parser_node_t *node); static njs_int_t njs_generate_typeof_operation(njs_vm_t *vm, njs_generator_t *generator, njs_parser_node_t *node); +static njs_int_t njs_generate_typeof_operation_end(njs_vm_t *vm, + njs_generator_t *generator, njs_parser_node_t *node); static njs_int_t njs_generate_inc_dec_operation(njs_vm_t *vm, njs_generator_t *generator, njs_parser_node_t *node, njs_bool_t post); +static njs_int_t njs_generate_inc_dec_operation_prop(njs_vm_t *vm, + njs_generator_t *generator, njs_parser_node_t *node); static njs_int_t njs_generate_function_declaration(njs_vm_t *vm, njs_generator_t *generator, njs_parser_node_t *node); static njs_int_t njs_generate_function_scope(njs_vm_t *vm, njs_function_lambda_t *lambda, njs_parser_node_t *node, const njs_str_t *name); +static njs_int_t njs_generate_scope_end(njs_vm_t *vm, + njs_generator_t *generator, njs_parser_node_t *node); static int64_t njs_generate_lambda_variables(njs_vm_t *vm, njs_generator_t *generator, njs_parser_node_t *node); static njs_int_t njs_generate_return_statement(njs_vm_t *vm, njs_generator_t *generator, njs_parser_node_t *node); +static njs_int_t njs_generate_return_statement_end(njs_vm_t *vm, + njs_generator_t *generator, njs_parser_node_t *node); static njs_int_t njs_generate_function_call(njs_vm_t *vm, njs_generator_t *generator, njs_parser_node_t *node); +static njs_int_t njs_generate_function_call_arguments(njs_vm_t *vm, + njs_generator_t *generator, njs_parser_node_t *node); +static njs_int_t njs_generate_function_call_end(njs_vm_t *vm, + njs_generator_t *generator, njs_parser_node_t *node); static njs_int_t njs_generate_method_call(njs_vm_t *vm, njs_generator_t *generator, njs_parser_node_t *node); +static njs_int_t njs_generate_method_call_arguments(njs_vm_t *vm, + njs_generator_t *generator, njs_parser_node_t *node); +static njs_int_t njs_generate_method_call_end(njs_vm_t *vm, + njs_generator_t *generator, njs_parser_node_t *node); static njs_int_t njs_generate_call(njs_vm_t *vm, njs_generator_t *generator, njs_parser_node_t *node); static njs_int_t njs_generate_move_arguments(njs_vm_t *vm, njs_generator_t *generator, njs_parser_node_t *node); static njs_int_t njs_generate_try_statement(njs_vm_t *vm, njs_generator_t *generator, njs_parser_node_t *node); +static njs_int_t njs_generate_try_left(njs_vm_t *vm, njs_generator_t *generator, + njs_parser_node_t *node); +static njs_int_t njs_generate_try_catch(njs_vm_t *vm, + njs_generator_t *generator, njs_parser_node_t *node); +static njs_int_t njs_generate_try_finally(njs_vm_t *vm, + njs_generator_t *generator, njs_parser_node_t *node); +static njs_int_t njs_generate_try_end(njs_vm_t *vm, njs_generator_t *generator, + njs_parser_node_t *node); static njs_int_t njs_generate_throw_statement(njs_vm_t *vm, njs_generator_t *generator, njs_parser_node_t *node); +static njs_int_t njs_generate_throw_end(njs_vm_t *vm, + njs_generator_t *generator, njs_parser_node_t *node); static njs_int_t njs_generate_import_statement(njs_vm_t *vm, njs_generator_t *generator, njs_parser_node_t *node); +static njs_int_t njs_generate_import_statement_end(njs_vm_t *vm, + njs_generator_t *generator, njs_parser_node_t *node); static njs_int_t njs_generate_export_statement(njs_vm_t *vm, njs_generator_t *generator, njs_parser_node_t *node); +static njs_int_t njs_generate_export_statement_end(njs_vm_t *vm, + njs_generator_t *generator, njs_parser_node_t *node); +static njs_int_t njs_generate_wo_dest(njs_vm_t *vm, + njs_generator_t *generator, njs_parser_node_t *node); +static njs_int_t njs_generate_wo_dest_after(njs_vm_t *vm, + njs_generator_t *generator, njs_parser_node_t *node); +static njs_int_t njs_generate_global_reference(njs_vm_t *vm, + njs_generator_t *generator, njs_parser_node_t *node, njs_bool_t exception); +static njs_int_t njs_generate_reference_error(njs_vm_t *vm, + njs_generator_t *generator, njs_parser_node_t *node); + static njs_index_t njs_generate_dest_index(njs_vm_t *vm, njs_generator_t *generator, njs_parser_node_t *node); static njs_index_t njs_generate_object_dest_index(njs_vm_t *vm, @@ -186,14 +341,14 @@ static njs_index_t njs_generate_temp_ind njs_generator_t *generator, njs_parser_node_t *node); static njs_int_t njs_generate_children_indexes_release(njs_vm_t *vm, njs_generator_t *generator, njs_parser_node_t *node); +static njs_int_t njs_generate_children_indexes_release_pop(njs_vm_t *vm, + njs_generator_t *generator, njs_parser_node_t *node); static njs_int_t njs_generate_node_index_release(njs_vm_t *vm, njs_generator_t *generator, njs_parser_node_t *node); +static njs_int_t njs_generate_node_index_release_pop(njs_vm_t *vm, + njs_generator_t *generator, njs_parser_node_t *node); static njs_int_t njs_generate_index_release(njs_vm_t *vm, njs_generator_t *generator, njs_index_t index); -static njs_int_t njs_generate_global_reference(njs_vm_t *vm, - njs_generator_t *generator, njs_parser_node_t *node, njs_bool_t exception); -static njs_int_t njs_generate_reference_error(njs_vm_t *vm, - njs_generator_t *generator, njs_parser_node_t *node); #define njs_generate_code(generator, type, _code, _op, nargs, nd) \ @@ -278,11 +433,77 @@ static const njs_str_t return_label = n static const njs_str_t undef_label = { 0xffffffff, (u_char *) "" }; +njs_inline void +njs_generator_next(njs_generator_t *generator, njs_generator_state_func_t state, + njs_parser_node_t *node) +{ + generator->state = state; + generator->node = node; +} + + +njs_inline njs_int_t +njs_generator_after(njs_vm_t *vm, njs_generator_t *generator, + njs_queue_link_t *link, njs_parser_node_t *node, + njs_generator_state_func_t state, void *ctx, size_t size) +{ + njs_generator_stack_entry_t *entry; + + entry = njs_mp_alloc(vm->mem_pool, sizeof(njs_parser_stack_entry_t)); + if (njs_slow_path(entry == NULL)) { + return NJS_ERROR; + } + + entry->state = state; + entry->node = node; + entry->context = ctx; + + njs_queue_insert_before(link, &entry->link); + + if (size > 0) { + entry->context = njs_mp_alloc(vm->mem_pool, size); + if (njs_slow_path(entry->context == NULL)) { + return NJS_ERROR; + } + + memcpy(entry->context, ctx, size); + } + + return NJS_OK; +} + + +njs_inline njs_int_t +njs_generator_stack_pop(njs_vm_t *vm, njs_generator_t *generator, void *ctx) +{ + njs_queue_link_t *link; + njs_generator_stack_entry_t *entry; + + entry = njs_queue_link_data(njs_queue_first(&generator->stack), + njs_generator_stack_entry_t, link); + + link = njs_queue_first(&generator->stack); + njs_queue_remove(link); + + if (ctx != NULL) { + njs_mp_free(vm->mem_pool, ctx); + } + + generator->context = entry->context; + + njs_generator_next(generator, entry->state, entry->node); + + njs_mp_free(vm->mem_pool, entry); + + return NJS_OK; +} + + static njs_int_t njs_generate(njs_vm_t *vm, njs_generator_t *generator, njs_parser_node_t *node) { if (node == NULL) { - return NJS_OK; + return njs_generator_stack_pop(vm, generator, NULL); } switch (node->token_type) { @@ -420,11 +641,11 @@ njs_generate(njs_vm_t *vm, njs_generator return NJS_ERROR; } - return NJS_OK; + return njs_generator_stack_pop(vm, generator, NULL); case NJS_TOKEN_OBJECT_VALUE: node->index = node->u.object->index; - return NJS_OK; + return njs_generator_stack_pop(vm, generator, NULL); case NJS_TOKEN_OBJECT: return njs_generate_object(vm, generator, node); @@ -449,7 +670,7 @@ njs_generate(njs_vm_t *vm, njs_generator return njs_generate_template_literal(vm, generator, node); case NJS_TOKEN_EXTERNAL: - return NJS_OK; + return njs_generator_stack_pop(vm, generator, NULL); case NJS_TOKEN_NAME: case NJS_TOKEN_ARGUMENTS: @@ -490,40 +711,11 @@ njs_generate(njs_vm_t *vm, njs_generator } -njs_inline njs_int_t -njs_generator(njs_vm_t *vm, njs_generator_t *generator, njs_parser_node_t *node) -{ - njs_int_t ret; - - if (njs_slow_path(generator->count++ > NJS_GENERATE_MAX_DEPTH)) { - njs_range_error(vm, "Maximum call stack size exceeded"); - return NJS_ERROR; - } - - ret = njs_generate(vm, generator, node); - - generator->count--; - - return ret; -} - - static njs_int_t -njs_generate_wo_dest(njs_vm_t *vm, njs_generator_t *generator, +njs_generator_pop(njs_vm_t *vm, njs_generator_t *generator, njs_parser_node_t *node) { - njs_int_t ret; - njs_parser_scope_t *scope; - - scope = njs_function_scope(node->scope); - - scope->dest_disable = 1; - - ret = njs_generator(vm, generator, node); - - scope->dest_disable = 0; - - return ret; + return njs_generator_stack_pop(vm, generator, NULL); } @@ -625,6 +817,7 @@ static njs_int_t njs_generate_name(njs_vm_t *vm, njs_generator_t *generator, njs_parser_node_t *node) { + njs_int_t ret; njs_variable_t *var; njs_parser_scope_t *scope; njs_vmcode_variable_t *variable; @@ -632,7 +825,12 @@ njs_generate_name(njs_vm_t *vm, njs_gene var = njs_variable_reference(vm, node); if (njs_slow_path(var == NULL)) { - return njs_generate_global_reference(vm, generator, node, 1); + ret = njs_generate_global_reference(vm, generator, node, 1); + if (njs_slow_path(ret != NJS_OK)) { + return ret; + } + + return njs_generator_stack_pop(vm, generator, NULL); } if (var->function && var->type == NJS_VARIABLE_FUNCTION) { @@ -643,7 +841,7 @@ njs_generate_name(njs_vm_t *vm, njs_gene } if (var->init) { - return NJS_OK; + return njs_generator_stack_pop(vm, generator, NULL); } if (var->type == NJS_VARIABLE_LET || var->type == NJS_VARIABLE_CONST) { @@ -656,7 +854,7 @@ njs_generate_name(njs_vm_t *vm, njs_gene } } - return NJS_OK; + return njs_generator_stack_pop(vm, generator, NULL); } @@ -738,7 +936,6 @@ njs_generate_var_statement(njs_vm_t *vm, njs_int_t ret; njs_variable_t *var; njs_parser_node_t *lvalue, *expr; - njs_vmcode_move_t *move; lvalue = node->left; @@ -767,7 +964,7 @@ njs_generate_var_statement(njs_vm_t *vm, var->init = 1; - return NJS_OK; + return njs_generator_stack_pop(vm, generator, NULL); } if (var->type == NJS_VARIABLE_LET || var->type == NJS_VARIABLE_CONST) { @@ -776,15 +973,33 @@ njs_generate_var_statement(njs_vm_t *vm, return ret; } - ret = njs_generate_let(vm, generator, node, var); - if (njs_slow_path(ret != NJS_OK)) { - return ret; - } - } else { expr->dest = lvalue; - ret = njs_generator(vm, generator, expr); + njs_generator_next(generator, njs_generate, expr); + } + + return njs_generator_after(vm, generator, + njs_queue_first(&generator->stack), node, + njs_generate_var_statement_after, var, 0); +} + + +static njs_int_t +njs_generate_var_statement_after(njs_vm_t *vm, njs_generator_t *generator, + njs_parser_node_t *node) +{ + njs_int_t ret; + njs_variable_t *var; + njs_parser_node_t *lvalue, *expr; + njs_vmcode_move_t *move; + + lvalue = node->left; + expr = node->right; + var = generator->context; + + if (var->type == NJS_VARIABLE_LET || var->type == NJS_VARIABLE_CONST) { + ret = njs_generate_let(vm, generator, node, var); if (njs_slow_path(ret != NJS_OK)) { return ret; } @@ -804,7 +1019,7 @@ njs_generate_var_statement(njs_vm_t *vm, node->index = expr->index; node->temporary = expr->temporary; - return NJS_OK; + return njs_generator_stack_pop(vm, generator, NULL); } @@ -826,18 +1041,24 @@ static njs_int_t njs_generate_if_statement(njs_vm_t *vm, njs_generator_t *generator, njs_parser_node_t *node) { + /* The condition expression. */ + + njs_generator_next(generator, njs_generate, node->left); + + return njs_generator_after(vm, generator, + njs_queue_first(&generator->stack), node, + njs_generate_if_statement_cond, NULL, 0); +} + + +static njs_int_t +njs_generate_if_statement_cond(njs_vm_t *vm, njs_generator_t *generator, + njs_parser_node_t *node) +{ njs_int_t ret; - njs_jump_off_t jump_offset, label_offset; - njs_vmcode_jump_t *jump; + njs_jump_off_t jump_offset; njs_vmcode_cond_jump_t *cond_jump; - /* The condition expression. */ - - ret = njs_generator(vm, generator, node->left); - if (njs_slow_path(ret != NJS_OK)) { - return ret; - } - njs_generate_code(generator, njs_vmcode_cond_jump_t, cond_jump, NJS_VMCODE_IF_FALSE_JUMP, 2, node); cond_jump->cond = node->left->index; @@ -848,7 +1069,6 @@ njs_generate_if_statement(njs_vm_t *vm, } jump_offset = njs_code_offset(generator, cond_jump); - label_offset = jump_offset + offsetof(njs_vmcode_cond_jump_t, offset); if (node->right != NULL && node->right->token_type == NJS_TOKEN_BRANCHING) { @@ -856,22 +1076,12 @@ njs_generate_if_statement(njs_vm_t *vm, node = node->right; - ret = njs_generator(vm, generator, node->left); - if (njs_slow_path(ret != NJS_OK)) { - return ret; - } - - ret = njs_generate_node_index_release(vm, generator, node->left); - if (njs_slow_path(ret != NJS_OK)) { - return ret; - } - - njs_generate_code_jump(generator, jump, 0); - - njs_code_set_offset(generator, label_offset, jump_offset); - - jump_offset = njs_code_offset(generator, jump); - label_offset = jump_offset + offsetof(njs_vmcode_jump_t, offset); + njs_generator_next(generator, njs_generate, node->left); + + return njs_generator_after(vm, generator, + njs_queue_first(&generator->stack), node, + njs_generate_if_statement_then, + &jump_offset, sizeof(njs_jump_off_t)); } /* @@ -879,19 +1089,63 @@ njs_generate_if_statement(njs_vm_t *vm, * or the "else" branch in a case of "if/then/else" statement. */ - ret = njs_generator(vm, generator, node->right); + njs_generator_next(generator, njs_generate, node->right); + + return njs_generator_after(vm, generator, + njs_queue_first(&generator->stack), node, + njs_generate_if_statement_else, + &jump_offset, sizeof(njs_jump_off_t)); +} + + +static njs_int_t +njs_generate_if_statement_then(njs_vm_t *vm, njs_generator_t *generator, + njs_parser_node_t *node) +{ + njs_int_t ret; + njs_jump_off_t *jump_offset, label_offset; + njs_vmcode_jump_t *jump; + + ret = njs_generate_node_index_release(vm, generator, node->left); if (njs_slow_path(ret != NJS_OK)) { return ret; } + jump_offset = (njs_jump_off_t *) generator->context; + label_offset = *jump_offset + offsetof(njs_vmcode_cond_jump_t, offset); + + njs_generate_code_jump(generator, jump, 0); + njs_code_set_offset(generator, label_offset, *jump_offset); + + *jump_offset = njs_code_offset(generator, jump); + + njs_generator_next(generator, njs_generate, node->right); + + return njs_generator_after(vm, generator, + njs_queue_first(&generator->stack), node, + njs_generate_if_statement_else, + jump_offset, 0); +} + + +static njs_int_t +njs_generate_if_statement_else(njs_vm_t *vm, njs_generator_t *generator, + njs_parser_node_t *node) +{ + njs_int_t ret; + njs_jump_off_t *jump_offset, label_offset; + + jump_offset = (njs_jump_off_t *) generator->context; + label_offset = *jump_offset + offsetof(njs_vmcode_cond_jump_t, offset); + ret = njs_generate_node_index_release(vm, generator, node->right); if (njs_slow_path(ret != NJS_OK)) { return ret; } - njs_code_set_offset(generator, label_offset, jump_offset); - - return NJS_OK; + njs_code_set_offset(generator, label_offset, *jump_offset); + + return njs_generator_stack_pop(vm, generator, generator->context); } @@ -899,40 +1153,53 @@ static njs_int_t njs_generate_cond_expression(njs_vm_t *vm, njs_generator_t *generator, njs_parser_node_t *node) { - njs_int_t ret; - njs_jump_off_t jump_offset, cond_jump_offset; - njs_parser_node_t *branch; - njs_vmcode_move_t *move; - njs_vmcode_jump_t *jump; + njs_generator_next(generator, njs_generate, node->left); + + return njs_generator_after(vm, generator, + njs_queue_first(&generator->stack), node, + njs_generate_cond_expression_handler, NULL, 0); +} + + +static njs_int_t +njs_generate_cond_expression_handler(njs_vm_t *vm, njs_generator_t *generator, + njs_parser_node_t *node) +{ + njs_jump_off_t jump_offset; njs_vmcode_cond_jump_t *cond_jump; - /* The condition expression. */ - - ret = njs_generator(vm, generator, node->left); - if (njs_slow_path(ret != NJS_OK)) { - return ret; - } - njs_generate_code(generator, njs_vmcode_cond_jump_t, cond_jump, NJS_VMCODE_IF_FALSE_JUMP, 2, node); - cond_jump_offset = njs_code_offset(generator, cond_jump); + jump_offset = njs_code_offset(generator, cond_jump); cond_jump->cond = node->left->index; node->index = njs_generate_dest_index(vm, generator, node); if (njs_slow_path(node->index == NJS_INDEX_ERROR)) { - return node->index; - } + return NJS_ERROR; + } + + njs_generator_next(generator, njs_generate, node->right->left); + + return njs_generator_after(vm, generator, + njs_queue_first(&generator->stack), node, + njs_generate_cond_expression_true, + &jump_offset, sizeof(njs_jump_off_t)); +} + + +static njs_int_t +njs_generate_cond_expression_true(njs_vm_t *vm, njs_generator_t *generator, + njs_parser_node_t *node) +{ + njs_int_t ret; + njs_jump_off_t jump_offset; + njs_parser_node_t *branch; + njs_vmcode_move_t *move; + njs_vmcode_jump_t *jump; branch = node->right; - /* The "true" branch. */ - - ret = njs_generator(vm, generator, branch->left); - if (njs_slow_path(ret != NJS_OK)) { - return ret; - } - /* * Branches usually uses node->index as destination, however, * if branch expression is a literal, variable or assignment, @@ -953,28 +1220,41 @@ njs_generate_cond_expression(njs_vm_t *v jump_offset = njs_code_offset(generator, jump); njs_code_set_jump_offset(generator, njs_vmcode_cond_jump_t, - cond_jump_offset); - - /* The "false" branch. */ - - ret = njs_generator(vm, generator, branch->right); - if (njs_slow_path(ret != NJS_OK)) { - return ret; - } + *((njs_jump_off_t *) generator->context)); + + njs_generator_next(generator, njs_generate, branch->right); + + return njs_generator_after(vm, generator, + njs_queue_first(&generator->stack), node, + njs_generate_cond_expression_false, + &jump_offset, sizeof(njs_jump_off_t)); +} + + +static njs_int_t +njs_generate_cond_expression_false(njs_vm_t *vm, njs_generator_t *generator, + njs_parser_node_t *node) +{ + njs_int_t ret; + njs_parser_node_t *branch; + njs_vmcode_move_t *move; + + branch = node->right; if (node->index != branch->right->index) { njs_generate_code_move(generator, move, node->index, branch->right->index, node); } - njs_code_set_jump_offset(generator, njs_vmcode_cond_jump_t, jump_offset); + njs_code_set_jump_offset(generator, njs_vmcode_cond_jump_t, + *((njs_jump_off_t *) generator->context)); ret = njs_generate_node_index_release(vm, generator, branch->right); if (njs_slow_path(ret != NJS_OK)) { return ret; } - return NJS_OK; + return njs_generator_stack_pop(vm, generator, generator->context); } @@ -982,33 +1262,40 @@ static njs_int_t njs_generate_switch_statement(njs_vm_t *vm, njs_generator_t *generator, njs_parser_node_t *swtch) { - njs_int_t ret; - njs_jump_off_t jump_offset; - njs_index_t index; - njs_parser_node_t *node, *expr, *branch; - njs_vmcode_move_t *move; - njs_vmcode_jump_t *jump; - njs_generator_patch_t *patch, *next, *patches, **last; - njs_vmcode_equal_jump_t *equal; + njs_generator_switch_ctx_t ctx; /* The "switch" expression. */ + njs_generator_next(generator, njs_generate, swtch->left); + + return njs_generator_after(vm, generator, + njs_queue_first(&generator->stack), swtch, + njs_generate_switch_expression, + &ctx, sizeof(njs_generator_switch_ctx_t)); +} + + +static njs_int_t +njs_generate_switch_expression(njs_vm_t *vm, njs_generator_t *generator, + njs_parser_node_t *swtch) +{ + njs_int_t ret; + njs_parser_node_t *expr; + njs_vmcode_move_t *move; + njs_generator_switch_ctx_t *ctx; + + ctx = generator->context; + expr = swtch->left; - - ret = njs_generator(vm, generator, expr); - if (njs_slow_path(ret != NJS_OK)) { - return ret; - } - - index = expr->index; + ctx->index = expr->index; if (!expr->temporary) { - index = njs_generate_temp_index_get(vm, generator, swtch); - if (njs_slow_path(index == NJS_INDEX_ERROR)) { + ctx->index = njs_generate_temp_index_get(vm, generator, swtch); + if (njs_slow_path(ctx->index == NJS_INDEX_ERROR)) { return NJS_ERROR; } - njs_generate_code_move(generator, move, index, expr->index, swtch); + njs_generate_code_move(generator, move, ctx->index, expr->index, swtch); } ret = njs_generate_start_block(vm, generator, NJS_GENERATOR_SWITCH, @@ -1017,95 +1304,198 @@ njs_generate_switch_statement(njs_vm_t * return ret; } - patches = NULL; - last = &patches; - - for (branch = swtch->right; branch != NULL; branch = branch->left) { - - if (branch->token_type != NJS_TOKEN_DEFAULT) { - - /* The "case" expression. */ - - node = branch->right; - - ret = njs_generator(vm, generator, node->left); - if (njs_slow_path(ret != NJS_OK)) { - return ret; - } - - njs_generate_code(generator, njs_vmcode_equal_jump_t, equal, - NJS_VMCODE_IF_EQUAL_JUMP, 3, branch); - equal->offset = offsetof(njs_vmcode_equal_jump_t, offset); - equal->value1 = index; - equal->value2 = node->left->index; - - ret = njs_generate_node_index_release(vm, generator, node->left); - if (njs_slow_path(ret != NJS_OK)) { - return ret; - } - - patch = njs_mp_alloc(vm->mem_pool, sizeof(njs_generator_patch_t)); - if (njs_slow_path(patch == NULL)) { - return NJS_ERROR; - } - - patch->jump_offset = njs_code_offset(generator, equal) - + offsetof(njs_vmcode_equal_jump_t, offset); - patch->label = no_label; - - *last = patch; - last = &patch->next; + ctx->patch = NULL; + ctx->last = &ctx->patch; + + if (swtch->right != NULL) { + + /* The "case" expression. */ + + njs_generator_next(generator, njs_generate_switch_case, swtch->right); + + return njs_generator_after(vm, generator, + njs_queue_first(&generator->stack), swtch, + njs_generate_switch_case_end, ctx, 0); + } + + return njs_generate_switch_case_end(vm, generator, swtch); +} + + +static njs_int_t +njs_generate_switch_case(njs_vm_t *vm, njs_generator_t *generator, + njs_parser_node_t *branch) +{ + if (branch->token_type == NJS_TOKEN_DEFAULT) { + if (branch->left == NULL) { + return njs_generator_stack_pop(vm, generator, NULL); } - } + + branch = branch->left; + } + + njs_generator_next(generator, njs_generate, branch->right->left); + + return njs_generator_after(vm, generator, + njs_queue_first(&generator->stack), branch, + njs_generate_switch_case_after, + generator->context, 0); +} + + +static njs_int_t +njs_generate_switch_case_after(njs_vm_t *vm, njs_generator_t *generator, + njs_parser_node_t *branch) +{ + njs_int_t ret; + njs_parser_node_t *node; + njs_generator_patch_t *patch; + njs_vmcode_equal_jump_t *equal; + njs_generator_switch_ctx_t *ctx; + + ctx = generator->context; + node = branch->right; + + njs_generate_code(generator, njs_vmcode_equal_jump_t, equal, + NJS_VMCODE_IF_EQUAL_JUMP, 3, branch); + equal->offset = offsetof(njs_vmcode_equal_jump_t, offset); + equal->value1 = ctx->index; + equal->value2 = node->left->index; + + ret = njs_generate_node_index_release(vm, generator, node->left); + if (njs_slow_path(ret != NJS_OK)) { + return ret; + } + + patch = njs_mp_alloc(vm->mem_pool, sizeof(njs_generator_patch_t)); + if (njs_slow_path(patch == NULL)) { + return NJS_ERROR; From alexander.borisov at nginx.com Thu Jul 15 17:34:51 2021 From: alexander.borisov at nginx.com (Alexander Borisov) Date: Thu, 15 Jul 2021 17:34:51 +0000 Subject: [njs] Removed recursion from finding let closures. Message-ID: details: https://hg.nginx.org/njs/rev/20dec02c7283 branches: changeset: 1681:20dec02c7283 user: Alexander Borisov date: Thu Jul 15 20:32:43 2021 +0300 description: Removed recursion from finding let closures. diffstat: src/njs_generator.c | 100 +++++++++++++++++++-------------------------------- src/njs_generator.h | 2 - 2 files changed, 38 insertions(+), 64 deletions(-) diffs (187 lines): diff -r efdc5f18195e -r 20dec02c7283 src/njs_generator.c --- a/src/njs_generator.c Thu Jul 15 20:32:40 2021 +0300 +++ b/src/njs_generator.c Thu Jul 15 20:32:43 2021 +0300 @@ -162,9 +162,9 @@ static njs_int_t njs_generate_for_update static njs_int_t njs_generate_for_end(njs_vm_t *vm, njs_generator_t *generator, njs_parser_node_t *node); static njs_int_t njs_generate_for_let_update(njs_vm_t *vm, - njs_generator_t *generator, njs_parser_node_t *node, size_t depth); + njs_generator_t *generator, njs_parser_node_t *node); static njs_int_t njs_generate_for_resolve_closure(njs_vm_t *vm, - njs_parser_node_t *node, size_t depth); + njs_parser_node_t *node); static njs_int_t njs_generate_for_in_statement(njs_vm_t *vm, njs_generator_t *generator, njs_parser_node_t *node); static njs_int_t njs_generate_for_in_object(njs_vm_t *vm, @@ -424,9 +424,6 @@ static njs_int_t njs_generate_index_rele ##__VA_ARGS__) -#define NJS_GENERATE_MAX_DEPTH 4096 - - static const njs_str_t no_label = njs_str(""); static const njs_str_t return_label = njs_str("@return"); /* GCC and Clang complain about NULL argument passed to memcmp(). */ @@ -1692,7 +1689,7 @@ njs_generate_for_init(njs_vm_t *vm, njs_ * foreseen in order to generate optimized code for let updates. */ - ret = njs_generate_for_resolve_closure(vm, condition, generator->count); + ret = njs_generate_for_resolve_closure(vm, condition); if (njs_slow_path(ret != NJS_OK)) { return ret; } @@ -1736,12 +1733,12 @@ njs_generate_for_body(njs_vm_t *vm, njs_ init = node->left; update = node->right->right->right; - ret = njs_generate_for_resolve_closure(vm, update, generator->count); + ret = njs_generate_for_resolve_closure(vm, update); if (njs_slow_path(ret != NJS_OK)) { return ret; } - ret = njs_generate_for_let_update(vm, generator, init, generator->count); + ret = njs_generate_for_let_update(vm, generator, init); if (njs_slow_path(ret != NJS_OK)) { return ret; } @@ -1833,56 +1830,43 @@ njs_generate_for_end(njs_vm_t *vm, njs_g static njs_int_t njs_generate_for_let_update(njs_vm_t *vm, njs_generator_t *generator, - njs_parser_node_t *node, size_t depth) + njs_parser_node_t *node) { njs_parser_node_t *let; njs_vmcode_variable_t *code_var; njs_variable_reference_t *ref; - if (node == NULL) { - return NJS_OK; - } - - if (depth >= NJS_GENERATE_MAX_DEPTH) { - return NJS_ERROR; - } - - if (node->token_type != NJS_TOKEN_STATEMENT) { - return NJS_OK; - } - - let = node->right; - - if (let->token_type != NJS_TOKEN_LET - && let->token_type != NJS_TOKEN_CONST) - { - return NJS_OK; - } - - ref = &let->left->u.reference; - - if (ref->variable->closure) { - njs_generate_code(generator, njs_vmcode_variable_t, code_var, - NJS_VMCODE_LET_UPDATE, 0, let); - code_var->dst = let->left->index; - } - - return njs_generate_for_let_update(vm, generator, node->left, depth + 1); + while (node != NULL && node->token_type == NJS_TOKEN_STATEMENT) { + let = node->right; + + if (let->token_type != NJS_TOKEN_LET + && let->token_type != NJS_TOKEN_CONST) + { + return NJS_OK; + } + + ref = &let->left->u.reference; + + if (ref->variable->closure) { + njs_generate_code(generator, njs_vmcode_variable_t, code_var, + NJS_VMCODE_LET_UPDATE, 0, let); + code_var->dst = let->left->index; + } + + node = node->left; + } + + return NJS_OK; } static njs_int_t -njs_generate_for_resolve_closure(njs_vm_t *vm, njs_parser_node_t *node, - size_t depth) +njs_generate_for_resolve_closure_cb(njs_vm_t *vm, njs_parser_node_t *node, + void *unused) { - njs_int_t ret; njs_bool_t closure; njs_variable_t *var; - if (node == NULL) { - return NJS_OK; - } - if (node->token_type == NJS_TOKEN_NAME) { var = njs_variable_resolve(vm, node); @@ -1895,26 +1879,19 @@ njs_generate_for_resolve_closure(njs_vm_ } } - if (depth >= NJS_GENERATE_MAX_DEPTH) { - njs_range_error(vm, "Maximum call stack size exceeded"); - return NJS_ERROR; - } - - ret = njs_generate_for_resolve_closure(vm, node->left, depth + 1); - if (njs_slow_path(ret != NJS_OK)) { - return ret; - } - - ret = njs_generate_for_resolve_closure(vm, node->right, depth + 1); - if (njs_slow_path(ret != NJS_OK)) { - return ret; - } - return NJS_OK; } static njs_int_t +njs_generate_for_resolve_closure(njs_vm_t *vm, njs_parser_node_t *node) +{ + return njs_parser_traverse(vm, node, NULL, + njs_generate_for_resolve_closure_cb); +} + + +static njs_int_t njs_generate_for_in_statement(njs_vm_t *vm, njs_generator_t *generator, njs_parser_node_t *node) { @@ -2027,8 +2004,7 @@ njs_generate_for_in_body(njs_vm_t *vm, n /* The loop iterator. */ if (name != NULL) { - ret = njs_generate_for_let_update(vm, generator, foreach->left, - generator->count); + ret = njs_generate_for_let_update(vm, generator, foreach->left); if (njs_slow_path(ret != NJS_OK)) { return ret; } diff -r efdc5f18195e -r 20dec02c7283 src/njs_generator.h --- a/src/njs_generator.h Thu Jul 15 20:32:40 2021 +0300 +++ b/src/njs_generator.h Thu Jul 15 20:32:43 2021 +0300 @@ -35,8 +35,6 @@ struct njs_generator_s { /* Parsing Function() or eval(). */ uint8_t runtime; /* 1 bit */ - - njs_uint_t count; }; From alexander.borisov at nginx.com Thu Jul 15 17:34:53 2021 From: alexander.borisov at nginx.com (Alexander Borisov) Date: Thu, 15 Jul 2021 17:34:53 +0000 Subject: [njs] The maximum depth of nested functions is set to 128. Message-ID: details: https://hg.nginx.org/njs/rev/424dd99ada9a branches: changeset: 1682:424dd99ada9a user: Alexander Borisov date: Thu Jul 15 20:32:44 2021 +0300 description: The maximum depth of nested functions is set to 128. diffstat: src/njs_generator.c | 22 +++++++++++++++++----- src/njs_generator.h | 2 ++ src/test/njs_unit_test.c | 30 ++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 5 deletions(-) diffs (126 lines): diff -r 20dec02c7283 -r 424dd99ada9a src/njs_generator.c --- a/src/njs_generator.c Thu Jul 15 20:32:43 2021 +0300 +++ b/src/njs_generator.c Thu Jul 15 20:32:44 2021 +0300 @@ -10,6 +10,9 @@ #include +#define NJS_FUNCTION_MAX_DEPTH 128 + + typedef struct njs_generator_patch_s njs_generator_patch_t; typedef enum { @@ -275,7 +278,7 @@ static njs_int_t njs_generate_function_d njs_generator_t *generator, njs_parser_node_t *node); static njs_int_t njs_generate_function_scope(njs_vm_t *vm, njs_function_lambda_t *lambda, njs_parser_node_t *node, - const njs_str_t *name); + const njs_str_t *name, njs_uint_t depth); static njs_int_t njs_generate_scope_end(njs_vm_t *vm, njs_generator_t *generator, njs_parser_node_t *node); static int64_t njs_generate_lambda_variables(njs_vm_t *vm, @@ -3043,7 +3046,8 @@ njs_generate_function_expression(njs_vm_ return NJS_ERROR; } - ret = njs_generate_function_scope(vm, lambda, node, &lex_entry->name); + ret = njs_generate_function_scope(vm, lambda, node, &lex_entry->name, + generator->depth); if (njs_slow_path(ret != NJS_OK)) { return ret; } @@ -3078,7 +3082,7 @@ njs_generate_function(njs_vm_t *vm, njs_ name = module ? &njs_entry_module : &njs_entry_anonymous; - ret = njs_generate_function_scope(vm, lambda, node, name); + ret = njs_generate_function_scope(vm, lambda, node, name, generator->depth); if (njs_slow_path(ret != NJS_OK)) { return ret; } @@ -3577,7 +3581,8 @@ njs_generate_function_declaration(njs_vm return NJS_ERROR; } - ret = njs_generate_function_scope(vm, lambda, node, &lex_entry->name); + ret = njs_generate_function_scope(vm, lambda, node, &lex_entry->name, + generator->depth); if (njs_slow_path(ret != NJS_OK)) { return ret; } @@ -3599,7 +3604,7 @@ njs_generate_function_declaration(njs_vm static njs_int_t njs_generate_function_scope(njs_vm_t *vm, njs_function_lambda_t *lambda, - njs_parser_node_t *node, const njs_str_t *name) + njs_parser_node_t *node, const njs_str_t *name, njs_uint_t depth) { njs_arr_t *arr; njs_bool_t module; @@ -3609,6 +3614,13 @@ njs_generate_function_scope(njs_vm_t *vm njs_memzero(&generator, sizeof(njs_generator_t)); + if (++depth >= NJS_FUNCTION_MAX_DEPTH) { + njs_range_error(vm, "Maximum function nesting depth exceeded"); + return NJS_ERROR; + } + + generator.depth = depth; + node = node->right; code = njs_generate_scope(vm, &generator, node->scope, name); diff -r 20dec02c7283 -r 424dd99ada9a src/njs_generator.h --- a/src/njs_generator.h Thu Jul 15 20:32:43 2021 +0300 +++ b/src/njs_generator.h Thu Jul 15 20:32:44 2021 +0300 @@ -35,6 +35,8 @@ struct njs_generator_s { /* Parsing Function() or eval(). */ uint8_t runtime; /* 1 bit */ + + njs_uint_t depth; }; diff -r 20dec02c7283 -r 424dd99ada9a src/test/njs_unit_test.c --- a/src/test/njs_unit_test.c Thu Jul 15 20:32:43 2021 +0300 +++ b/src/test/njs_unit_test.c Thu Jul 15 20:32:44 2021 +0300 @@ -9590,6 +9590,36 @@ static njs_unit_test_t njs_test[] = "fn(1); arr"), njs_str("1,2,3,4,5,6") }, + /* Function nesting depth. */ + + { njs_str("() => () => () => () => () => () => () => () => () => () => () =>" + "() => () => () => () => () => () => () => () => () => () => () =>" + "() => () => () => () => () => () => () => () => () => () => () =>" + "() => () => () => () => () => () => () => () => () => () => () =>" + "() => () => () => () => () => () => () => () => () => () => () =>" + "() => () => () => () => () => () => () => () => () => () => () =>" + "() => () => () => () => () => () => () => () => () => () => () =>" + "() => () => () => () => () => () => () => () => () => () => () =>" + "() => () => () => () => () => () => () => () => () => () => () =>" + "() => () => () => () => () => () => () => () => () => () => () =>" + "() => () => () => () => () => () => () => () => () => () => () =>" + "() => () => () => () => () => () => 1"), + njs_str("[object Function]") }, + + { njs_str("() => () => () => () => () => () => () => () => () => () => () =>" + "() => () => () => () => () => () => () => () => () => () => () =>" + "() => () => () => () => () => () => () => () => () => () => () =>" + "() => () => () => () => () => () => () => () => () => () => () =>" + "() => () => () => () => () => () => () => () => () => () => () =>" + "() => () => () => () => () => () => () => () => () => () => () =>" + "() => () => () => () => () => () => () => () => () => () => () =>" + "() => () => () => () => () => () => () => () => () => () => () =>" + "() => () => () => () => () => () => () => () => () => () => () =>" + "() => () => () => () => () => () => () => () => () => () => () =>" + "() => () => () => () => () => () => () => () => () => () => () =>" + "() => () => () => () => () => () => () => 1"), + njs_str("RangeError: Maximum function nesting depth exceeded") }, + /* Recursive factorial. */ { njs_str("function f(a) {" From dnj0496 at gmail.com Fri Jul 16 03:41:35 2021 From: dnj0496 at gmail.com (Dk Jack) Date: Thu, 15 Jul 2021 20:41:35 -0700 Subject: body filter redirect In-Reply-To: References: Message-ID: Hello Maxim, could you please respond to my previous message. Thanks. Dk. On Tue, Jul 13, 2021 at 9:28 PM Dk Jack wrote: > Hello Maxim, > Thanks for responding. Can I get some clarification on what you mean by > the statement below: > > "More flexibility can be achieved by reading the request body > earlier - for example, you can do this from your own module, or > with embedded scripting such as perl or njs." > > Are you suggesting that I use ngx_http_read_client_request_body api in my > module? > > http://nginx.org/en/docs/dev/development_guide.html#http_request_body > > I had similar trouble using that API with redirection. Are there some > tricks to getting > it to work when using that API? Are there any reference implementations > doing > redirection after inspecting the request body? > Thanks for your help! > > Dk. > > > Hello! > > It is generally too late to do any actions like "change the > > upstream/location etc" based on the body content, as the request > > body is usually read only when the location is already known and > > the upstream name is already obtained. Also consider > > "proxy_request_buffering off;" - reading the request body implies > > that nginx is sending the request body to the backend as well. > > That is, you can't really do more than modifying the request body > > or rejecting the request completely. > > > > You may, however, provide some variables from your body request > > body filter - and, if it's possible in your particular > > configuration, use these variables to do some conditional > > processing. > > > > Note thought that conditional processing needs to happen after the > > request body is read. As such, it is usually quite limited, > > especially when using standard modules, since the request body is > > usually read last. > > > > For example, with proxy the request body is read after the > > variables in the "proxy_pass" directive are evaluated, so even > > with "proxy_request_buffering on;" (the default) you cannot use > > the variables from your request body filter module to change the > > upstream. You can, however, use it to control headers in the > > upstream request by using "proxy_set_header" with appropriate > > variables (again, assuming buffered request body reading - for > > obvious reasons this won't work with "proxy_request_buffering > > off;"). > > > > More flexibility can be achieved by reading the request body > > earlier - for example, you can do this from your own module, or > > with embedded scripting such as perl or njs. > > > > -- > > Maxim Dounin > > http://mdounin.ru/ > > _______________________________________________ > > nginx-devel mailing list > > nginx-devel at nginx.org > > http://mailman.nginx.org/mailman/listinfo/nginx-devel > > > On Mon, Jul 12, 2021 at 12:47 PM Dk Jack wrote: > >> Hi, >> In my module, I am trying to take actions based on the content of the >> body. To accomplish this, I am capturing the body using body file as shown >> in the example below: >> >> >> http://mdounin.ru/hg/ngx_http_catch_body_filter_module/file/tip/ngx_http_catch_body_filter_module.c >> >> This is working well. I can inspect the contents of the body and take >> different actions like rejecting requests etc. However, one of the actions >> I want to do is redirect the request based on the body content i.e if the >> content contains some string etc, then redirect the request i.e change the >> upstream/location etc. My question is, is it even possible to redirect a >> request in the body filter stage? Is there another way to do body >> capture/filter and still be able to redirect the request after inspecting >> the body? Any help, suggestions or sample code is appreciated. Thanks. >> >> Dk. >> >> >> -------------- next part -------------- An HTML attachment was scrubbed... URL: From mdounin at mdounin.ru Fri Jul 16 16:49:40 2021 From: mdounin at mdounin.ru (Maxim Dounin) Date: Fri, 16 Jul 2021 19:49:40 +0300 Subject: body filter redirect In-Reply-To: References: Message-ID: Hello! On Tue, Jul 13, 2021 at 09:28:15PM -0700, Dk Jack wrote: > Hello Maxim, > Thanks for responding. Can I get some clarification on what you mean by the > statement below: > > "More flexibility can be achieved by reading the request body > earlier - for example, you can do this from your own module, or > with embedded scripting such as perl or njs." > > Are you suggesting that I use ngx_http_read_client_request_body api in my > module? > > http://nginx.org/en/docs/dev/development_guide.html#http_request_body That's one of the possible solutions. > I had similar trouble using that API with redirection. Are there some > tricks to getting > it to work when using that API? Are there any reference implementations > doing > redirection after inspecting the request body? Refer to the mirror module to see how to restore request phases processing after reading the request body, it might be helpful. -- Maxim Dounin http://mdounin.ru/ From lcuminato at gmail.com Mon Jul 26 21:08:02 2021 From: lcuminato at gmail.com (Lucas Cuminato) Date: Mon, 26 Jul 2021 16:08:02 -0500 Subject: [nginx-quic] Segmentation offloading Message-ID: Hello, I was testing this feature the other day but unsure if it's doing the right thing. Nginx is generating 65k UDP datagrams which are then being fragmented at the IP layer. Reading the spec, rfc9000, it looks like IP fragmentation is not allowed (Section 14). "UDP datagrams MUST NOT be fragmented at the IP layer. In IPv4 IPv4 ], the Don't Fragment (DF) bit MUST be set if possible, to prevent fragmentation on the path." Also, it doesn't seem to be respecting the client's endpoint max_udp_payload_size. Can you please confirm if this is desired ? R, Lucas. -------------- next part -------------- An HTML attachment was scrubbed... URL: From vl at nginx.com Tue Jul 27 06:41:55 2021 From: vl at nginx.com (Vladimir Homutov) Date: Tue, 27 Jul 2021 09:41:55 +0300 Subject: [nginx-quic] Segmentation offloading In-Reply-To: References: Message-ID: On Mon, Jul 26, 2021 at 04:08:02PM -0500, Lucas Cuminato wrote: > Hello, > > I was testing this feature the other day but unsure if it's doing the right > thing. > Nginx is generating 65k UDP datagrams which are then being fragmented at > the IP layer. > Reading the spec, rfc9000, it looks like IP fragmentation is not allowed > (Section 14). > > "UDP datagrams MUST NOT be fragmented at the IP layer. In IPv4 > > IPv4 ], the > Don't Fragment (DF) bit MUST be set if possible, to > prevent fragmentation on the path." > > > Also, it doesn't seem to be respecting the client's endpoint > max_udp_payload_size. > > > Can you please confirm if this is desired ? Hi Lucas, thank you for the feedback. Of course, 65K datagrams is not something expected. It looks like GSO is not working properly in your case. The expected result is that kernel will split 65K buffer into smaller UDP datagrams of specified (segment) size, and this segment size respects QUIC settings. Do you see it in the wire? If yes, please share output of configure script, debug log [1], and output of 'nginx -T'. Are you running nginx on hardware directly or is it some virtual machine? NIC/interface details are valuable (ethtool -k , ip link show ). [1] http://nginx.org/en/docs/debugging_log.html