[njs] Modules: returning undefined value for absent values.
Dmitry Volyntsev
xeioex at nginx.com
Tue Mar 26 12:53:46 UTC 2019
details: https://hg.nginx.org/njs/rev/b758915e2406
branches:
changeset: 842:b758915e2406
user: Dmitry Volyntsev <xeioex at nginx.com>
date: Tue Mar 26 14:51:03 2019 +0300
description:
Modules: returning undefined value for absent values.
Instead of empty string.
diffstat:
nginx/ngx_http_js_module.c | 17 +++++++++++------
nginx/ngx_stream_js_module.c | 3 ++-
2 files changed, 13 insertions(+), 7 deletions(-)
diffs (68 lines):
diff -r e3ee3a2d9994 -r b758915e2406 nginx/ngx_http_js_module.c
--- a/nginx/ngx_http_js_module.c Mon Mar 25 17:51:19 2019 +0300
+++ b/nginx/ngx_http_js_module.c Tue Mar 26 14:51:03 2019 +0300
@@ -922,7 +922,8 @@ ngx_http_js_ext_get_header_out(njs_vm_t
h = ngx_http_js_get_header(&r->headers_out.headers.part, v->start,
v->length);
if (h == NULL) {
- return njs_vm_value_string_set(vm, value, NULL, 0);
+ njs_value_undefined_set(value);
+ return NJS_OK;
}
return njs_vm_value_string_set(vm, value, h->value.data, h->value.len);
@@ -1433,8 +1434,8 @@ ngx_http_js_ext_get_request_body(njs_vm_
}
if (r->request_body == NULL || r->request_body->bufs == NULL) {
- njs_vm_error(vm, "request body is unavailable");
- return NJS_ERROR;
+ njs_value_undefined_set(value);
+ return NJS_OK;
}
if (r->request_body->temp_file) {
@@ -1502,7 +1503,8 @@ ngx_http_js_ext_get_header_in(njs_vm_t *
h = ngx_http_js_get_header(&r->headers_in.headers.part, v->start,
v->length);
if (h == NULL) {
- return njs_vm_value_string_set(vm, value, NULL, 0);
+ njs_value_undefined_set(value);
+ return NJS_OK;
}
return njs_vm_value_string_set(vm, value, h->value.data, h->value.len);
@@ -1531,7 +1533,9 @@ ngx_http_js_ext_get_arg(njs_vm_t *vm, nj
return njs_vm_value_string_set(vm, value, arg.data, arg.len);
}
- return njs_vm_value_string_set(vm, value, NULL, 0);
+ njs_value_undefined_set(value);
+
+ return NJS_OK;
}
@@ -1620,7 +1624,8 @@ ngx_http_js_ext_get_variable(njs_vm_t *v
vv = ngx_http_get_variable(r, &name, key);
if (vv == NULL || vv->not_found) {
- return njs_vm_value_string_set(vm, value, NULL, 0);
+ njs_value_undefined_set(value);
+ return NJS_OK;
}
return njs_vm_value_string_set(vm, value, vv->data, vv->len);
diff -r e3ee3a2d9994 -r b758915e2406 nginx/ngx_stream_js_module.c
--- a/nginx/ngx_stream_js_module.c Mon Mar 25 17:51:19 2019 +0300
+++ b/nginx/ngx_stream_js_module.c Tue Mar 26 14:51:03 2019 +0300
@@ -1203,7 +1203,8 @@ ngx_stream_js_ext_get_variable(njs_vm_t
vv = ngx_stream_get_variable(s, &name, key);
if (vv == NULL || vv->not_found) {
- return njs_vm_value_string_set(vm, value, NULL, 0);
+ njs_value_undefined_set(value);
+ return NJS_OK;
}
return njs_vm_value_string_set(vm, value, vv->data, vv->len);
More information about the nginx-devel
mailing list