[njs] HTTP: improved r.parent property handler.

Dmitry Volyntsev xeioex at nginx.com
Tue Nov 26 11:15:49 UTC 2019


details:   https://hg.nginx.org/njs/rev/851550b92d9d
branches:  
changeset: 1257:851550b92d9d
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Mon Nov 25 17:54:58 2019 +0300
description:
HTTP: improved r.parent property handler.

Previously, r.parent handler threw an exception if it was called not for
a subrequest.  This is too restrictive, as it prevents any iterations
over all r properties (for example: JSON.stringify()).

Instead, "undefined" value is returned as it is already done for
r.requestBody when request body is unavailable.

diffstat:

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

diffs (14 lines):

diff -r 790caa744e0e -r 851550b92d9d nginx/ngx_http_js_module.c
--- a/nginx/ngx_http_js_module.c	Mon Nov 25 17:53:32 2019 +0300
+++ b/nginx/ngx_http_js_module.c	Mon Nov 25 17:54:58 2019 +0300
@@ -2091,8 +2091,8 @@ ngx_http_js_ext_get_parent(njs_vm_t *vm,
                     : NULL;
 
     if (ctx == NULL || ctx->vm != vm) {
-        njs_vm_error(vm, "parent can only be returned for a subrequest");
-        return NJS_ERROR;
+        njs_value_undefined_set(value);
+        return NJS_OK;
     }
 
     njs_value_assign(value, njs_value_arg(&ctx->request));


More information about the nginx-devel mailing list