[njs] HTTP: simplified check for subrequest from a subrequest.

noreply at nginx.com noreply at nginx.com
Sat Jun 29 02:52:06 UTC 2024


details:   https://hg.nginx.org/njs/rev/8b182df14819
branches:  
changeset: 2361:8b182df14819
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Wed Jun 12 23:31:08 2024 -0700
description:
HTTP: simplified check for subrequest from a subrequest.

diffstat:

 nginx/ngx_http_js_module.c |  4 ++--
 nginx/t/js_subrequests.t   |  5 +++--
 2 files changed, 5 insertions(+), 4 deletions(-)

diffs (43 lines):

diff -r 5b5f45340f9f -r 8b182df14819 nginx/ngx_http_js_module.c
--- a/nginx/ngx_http_js_module.c	Mon Jun 17 21:35:02 2024 -0700
+++ b/nginx/ngx_http_js_module.c	Wed Jun 12 23:31:08 2024 -0700
@@ -3153,7 +3153,7 @@ ngx_http_js_ext_subrequest(njs_vm_t *vm,
 
     ctx = ngx_http_get_module_ctx(r, ngx_http_js_module);
 
-    if (ctx->vm != vm) {
+    if (r->main != r) {
         njs_vm_error(vm, "subrequest can only be created for "
                          "the primary request");
         return NJS_ERROR;
@@ -3511,7 +3511,7 @@ ngx_http_js_ext_get_parent(njs_vm_t *vm,
     ctx = r->parent ? ngx_http_get_module_ctx(r->parent, ngx_http_js_module)
                     : NULL;
 
-    if (ctx == NULL || ctx->vm != vm) {
+    if (ctx == NULL) {
         njs_value_undefined_set(retval);
         return NJS_DECLINED;
     }
diff -r 5b5f45340f9f -r 8b182df14819 nginx/t/js_subrequests.t
--- a/nginx/t/js_subrequests.t	Mon Jun 17 21:35:02 2024 -0700
+++ b/nginx/t/js_subrequests.t	Wed Jun 12 23:31:08 2024 -0700
@@ -590,6 +590,9 @@ local $TODO = 'not yet' unless has_versi
 
 http_get('/sr_error_in_callback');
 
+ok(index($t->read_file('error.log'), 'subrequest can only be created for') > 0,
+   'subrequest creation failed');
+
 }
 
 $t->stop();
@@ -602,8 +605,6 @@ ok(index($t->read_file('error.log'), 'fa
 	'subrequest invalid args exception');
 ok(index($t->read_file('error.log'), 'too big subrequest response') > 0,
 	'subrequest too large body');
-ok(index($t->read_file('error.log'), 'subrequest creation failed') > 0,
-	'subrequest creation failed');
 ok(index($t->read_file('error.log'),
 		'js subrequest: failed to get the parent context') > 0,
 	'zero parent ctx');


More information about the nginx-devel mailing list