Skip to content

Commit

Permalink
HTTP: simplified check for subrequest from a subrequest.
Browse files Browse the repository at this point in the history
  • Loading branch information
xeioex committed Jun 29, 2024
1 parent 59bba97 commit a14be61
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions nginx/ngx_http_js_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
5 changes: 3 additions & 2 deletions nginx/t/js_subrequests.t
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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');
Expand Down

0 comments on commit a14be61

Please sign in to comment.