ctx = ngx_http_get_module_ctx(r, ngx_http_js_module);
- njs_vm_retval_set(ctx->vm, njs_value_arg(&ctx->args[1]));
+ njs_vm_retval_set(vm, njs_value_arg(&ctx->args[1]));
return NJS_OK;
}
ngx_uint_t cb_index, method, n, has_body;
njs_value_t *arg2, *options, *value;
njs_function_t *callback;
+ ngx_http_js_ctx_t *ctx;
ngx_http_request_t *r, *sr;
ngx_http_request_body_t *rb;
r = njs_value_data(njs_argument(args, 0));
+ ctx = ngx_http_get_module_ctx(r, ngx_http_js_module);
+
+ if (ctx->vm != vm) {
+ njs_vm_error(vm, "subrequest can only be created for "
+ "the primary request");
+ return NJS_ERROR;
+ }
+
if (njs_vm_value_to_ext_string(vm, &uri_arg, njs_argument(args, 1), 0)
== NJS_ERROR)
{
r = (ngx_http_request_t *) obj;
- ctx = ngx_http_get_module_ctx(r->parent, ngx_http_js_module);
+ ctx = r->parent ? ngx_http_get_module_ctx(r->parent, ngx_http_js_module)
+ : NULL;
- if (ctx == NULL) {
- njs_vm_error(vm, "failed to get the parent context");
+ if (ctx == NULL || ctx->vm != vm) {
+ njs_vm_error(vm, "parent can only be returned for a subrequest");
return NJS_ERROR;
}
- njs_vm_retval_set(ctx->vm, njs_value_arg(&ctx->args[0]));
+ njs_vm_retval_set(vm, njs_value_arg(&ctx->args[0]));
return NJS_OK;
}