return NJS_ERROR;
}
+ if (r != njs_vm_external_ptr(vm)) {
+ njs_vm_type_error(vm, "cannot read body of another request");
+ return NJS_ERROR;
+ }
+
ctx = ngx_http_get_module_ctx(r, ngx_http_js_module);
event = njs_mp_zalloc(njs_vm_memory_pool(vm),
return NJS_ERROR;
}
+ if (r != njs_vm_external_ptr(vm)) {
+ njs_vm_type_error(vm, "cannot read body of another request");
+ return NJS_ERROR;
+ }
+
if (ngx_http_js_request_form_max_keys(vm, njs_arg(args, nargs, 1),
&max_keys)
!= NJS_OK)
return NGX_ERROR;
}
+ ngx_js_ctx_init((ngx_js_ctx_t *) ctx, r->connection->log);
+
ngx_http_set_ctx(r, ctx, ngx_http_js_module);
}
}
r = req->opaque.external;
+
+ if (r != JS_GetContextOpaque(cx)) {
+ return JS_ThrowTypeError(cx, "cannot read body of another request");
+ }
+
ctx = ngx_http_get_module_ctx(r, ngx_http_js_module);
if (r->request_body) {
}
r = req->opaque.external;
+
+ if (r != JS_GetContextOpaque(cx)) {
+ return JS_ThrowTypeError(cx, "cannot read body of another request");
+ }
+
ctx = ngx_http_get_module_ctx(r, ngx_http_js_module);
if (r->request_body) {
return NGX_ERROR;
}
+ ngx_js_ctx_init((ngx_js_ctx_t *) sctx, r->connection->log);
+
ngx_http_set_ctx(r, sctx, ngx_http_js_module);
ngx_qjs_arg(sctx->response_body) = JS_UNDEFINED;
js_import test.js;
js_set $retval test.variable;
+ js_set $reply_uri test.reply_uri;
+ js_var $read_result;
server {
listen 127.0.0.1:8080;
location /variable {
return 200 $retval;
}
+
+ location /access_read {
+ js_access test.access_read;
+ js_content test.read_result;
+ }
+
+ location /content_read {
+ js_content test.content_read;
+ }
+
+ location /reply_variable {
+ js_content test.reply_variable;
+ }
}
}
r.setReturnValue('own result');
}
- export default {content, child, variable};
+ function read_reply(reply) {
+ return ['readRequestText', 'readRequestForm'].map(method => {
+ try {
+ reply[method]();
+ return 'accepted';
+ } catch (e) {
+ return e instanceof TypeError ? 'rejected' : e.name;
+ }
+ }).join(',');
+ }
+
+ async function access_read(r) {
+ const reply = await r.subrequest('/native');
+ r.variables.read_result = read_reply(reply);
+ }
+
+ function read_result(r) {
+ r.return(200, r.variables.read_result);
+ }
+
+ async function content_read(r) {
+ const reply = await r.subrequest('/native');
+ r.return(200, read_reply(reply));
+ }
+
+ function reply_uri(r) {
+ return r.uri;
+ }
+
+ async function reply_variable(r) {
+ const reply = await r.subrequest('/native');
+ r.return(200, reply.variables.reply_uri);
+ }
+
+ export default {content, child, variable, access_read, read_result,
+ content_read, reply_uri, reply_variable};
EOF
-$t->try_run('no njs available')->plan(19);
+$t->try_run('no njs available')->plan(22);
for my $scope ('zero', 'reuse') {
for my $mode ('parent', 'shape', 'args', 'parent_set') {
}
like(http_get('/variable'), qr/own result$/m, 'own async js_set result');
+like(http_get('/access_read'), qr/rejected,rejected$/m,
+ 'reply body read in access handler');
+like(http_get('/content_read'), qr/rejected,rejected$/m,
+ 'reply body read in content handler');
+like(http_get('/reply_variable'), qr/\/native$/m, 'reply js_set variable');
###############################################################################