[njs] HTTP: added r.internal property.

Dmitry Volyntsev xeioex at nginx.com
Fri Aug 26 00:49:12 UTC 2022


details:   https://hg.nginx.org/njs/rev/43b31a943c08
branches:  
changeset: 1935:43b31a943c08
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Thu Aug 25 16:57:28 2022 -0700
description:
HTTP: added r.internal property.

diffstat:

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

diffs (54 lines):

diff -r e023db05004f -r 43b31a943c08 nginx/ngx_http_js_module.c
--- a/nginx/ngx_http_js_module.c	Wed Aug 24 17:04:58 2022 -0700
+++ b/nginx/ngx_http_js_module.c	Thu Aug 25 16:57:28 2022 -0700
@@ -174,6 +174,9 @@ static njs_int_t ngx_http_js_ext_interna
 static njs_int_t ngx_http_js_ext_get_http_version(njs_vm_t *vm,
     njs_object_prop_t *prop, njs_value_t *value, njs_value_t *setval,
     njs_value_t *retval);
+static njs_int_t ngx_http_js_ext_internal(njs_vm_t *vm,
+    njs_object_prop_t *prop, njs_value_t *value, njs_value_t *setval,
+    njs_value_t *retval);
 static njs_int_t ngx_http_js_ext_get_remote_address(njs_vm_t *vm,
     njs_object_prop_t *prop, njs_value_t *value, njs_value_t *setval,
     njs_value_t *retval);
@@ -534,6 +537,15 @@ static njs_external_t  ngx_http_js_ext_r
     },
 
     {
+        .flags = NJS_EXTERN_PROPERTY,
+        .name.string = njs_str("internal"),
+        .enumerable = 1,
+        .u.property = {
+            .handler = ngx_http_js_ext_internal,
+        }
+    },
+
+    {
         .flags = NJS_EXTERN_METHOD,
         .name.string = njs_str("internalRedirect"),
         .writable = 1,
@@ -2504,6 +2516,24 @@ ngx_http_js_ext_get_http_version(njs_vm_
 
 
 static njs_int_t
+ngx_http_js_ext_internal(njs_vm_t *vm, njs_object_prop_t *prop,
+    njs_value_t *value, njs_value_t *setval, njs_value_t *retval)
+{
+    ngx_http_request_t  *r;
+
+    r = njs_vm_external(vm, ngx_http_js_request_proto_id, value);
+    if (r == NULL) {
+        njs_value_undefined_set(retval);
+        return NJS_DECLINED;
+    }
+
+    njs_value_boolean_set(retval, r->internal);
+
+    return NJS_OK;
+}
+
+
+static njs_int_t
 ngx_http_js_ext_get_remote_address(njs_vm_t *vm, njs_object_prop_t *prop,
     njs_value_t *value, njs_value_t *setval, njs_value_t *retval)
 {



More information about the nginx-devel mailing list