Welcome! Log In Create A New Profile

Advanced

[njs] HTTP: improved working with unknown methods in subrequest().

Dmitry Volyntsev
May 28, 2019 10:06AM
details: https://hg.nginx.org/njs/rev/6b7042a20523
branches:
changeset: 988:6b7042a20523
user: Dmitry Volyntsev <xeioex@nginx.com>
date: Tue May 28 17:04:33 2019 +0300
description:
HTTP: improved working with unknown methods in subrequest().

diffstat:

nginx/ngx_http_js_module.c | 25 ++++++++++++++-----------
1 files changed, 14 insertions(+), 11 deletions(-)

diffs (63 lines):

diff -r f6234460852a -r 6b7042a20523 nginx/ngx_http_js_module.c
--- a/nginx/ngx_http_js_module.c Tue May 28 15:57:35 2019 +0300
+++ b/nginx/ngx_http_js_module.c Tue May 28 17:04:33 2019 +0300
@@ -1728,7 +1728,7 @@ ngx_http_js_ext_subrequest(njs_vm_t *vm,
{
ngx_int_t rc;
nxt_str_t uri_arg, args_arg, method_name, body_arg;
- ngx_uint_t method, n, has_body;
+ ngx_uint_t method, methods_max, has_body;
njs_value_t *value;
njs_function_t *callback;
ngx_http_js_ctx_t *ctx;
@@ -1788,6 +1788,8 @@ ngx_http_js_ext_subrequest(njs_vm_t *vm,
callback = NULL;

method = 0;
+ methods_max = sizeof(methods) / sizeof(methods[0]);
+
args_arg.length = 0;
args_arg.start = NULL;
has_body = 0;
@@ -1827,9 +1829,7 @@ ngx_http_js_ext_subrequest(njs_vm_t *vm,
return NJS_ERROR;
}

- n = sizeof(methods) / sizeof(methods[0]);
-
- while (method < n) {
+ while (method < methods_max) {
if (method_name.length == methods[method].name.len
&& ngx_memcmp(method_name.start, methods[method].name.data,
method_name.length)
@@ -1840,11 +1840,6 @@ ngx_http_js_ext_subrequest(njs_vm_t *vm,

method++;
}
-
- if (method == n) {
- njs_vm_error(vm, "unknown method \"%V\"", &method_name);
- return NJS_ERROR;
- }
}

value = njs_vm_object_prop(vm, options, &body_key);
@@ -1875,8 +1870,16 @@ ngx_http_js_ext_subrequest(njs_vm_t *vm,
return NJS_ERROR;
}

- sr->method = methods[method].value;
- sr->method_name = methods[method].name;
+ if (method != methods_max) {
+ sr->method = methods[method].value;
+ sr->method_name = methods[method].name;
+
+ } else {
+ sr->method = NGX_HTTP_UNKNOWN;
+ sr->method_name.len = method_name.length;
+ sr->method_name.data = method_name.start;
+ }
+
sr->header_only = (sr->method == NGX_HTTP_HEAD) || (callback == NULL);

if (has_body) {
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] HTTP: improved working with unknown methods in subrequest().

Dmitry Volyntsev 365 May 28, 2019 10:06AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 328
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready