From bad395417628362c05138ad4d10e5150c74d4899 Mon Sep 17 00:00:00 2001 From: Dmitry Volyntsev Date: Wed, 12 Jun 2024 23:31:08 -0700 Subject: [PATCH] HTTP: simplified check for subrequest from a subrequest. --- nginx/ngx_http_js_module.c | 4 ++-- nginx/t/js_subrequests.t | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/nginx/ngx_http_js_module.c b/nginx/ngx_http_js_module.c index 5c8c0480a..260cd497f 100644 --- a/nginx/ngx_http_js_module.c +++ b/nginx/ngx_http_js_module.c @@ -3153,7 +3153,7 @@ ngx_http_js_ext_subrequest(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs, 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, njs_object_prop_t *prop, 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 --git a/nginx/t/js_subrequests.t b/nginx/t/js_subrequests.t index f1937c9cb..4a58d6f3c 100644 --- a/nginx/t/js_subrequests.t +++ b/nginx/t/js_subrequests.t @@ -590,6 +590,9 @@ local $TODO = 'not yet' unless has_version('0.8.5'); 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'), 'failed to convert options.args') > 0, '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');