From 789762ff3d88a1c006babc7a8e7037e0976ad70f Mon Sep 17 00:00:00 2001 From: Zhidao HONG Date: Mon, 30 Jan 2023 11:16:01 +0800 Subject: NJS: adding the missing vm destruction. This commit fixed the njs memory leak happened in the config validation, updating and http requests. --- src/nxt_conf_validation.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'src/nxt_conf_validation.c') diff --git a/src/nxt_conf_validation.c b/src/nxt_conf_validation.c index bf8aa760..537a3fb7 100644 --- a/src/nxt_conf_validation.c +++ b/src/nxt_conf_validation.c @@ -1284,25 +1284,35 @@ nxt_conf_validate(nxt_conf_validation_t *vldt) vldt->tstr_state = nxt_tstr_state_new(vldt->pool, 1); if (nxt_slow_path(vldt->tstr_state == NULL)) { - return NXT_ERROR; + ret = NXT_ERROR; + goto fail; } ret = nxt_conf_vldt_type(vldt, NULL, vldt->conf, NXT_CONF_VLDT_OBJECT); if (ret != NXT_OK) { - return ret; + goto fail; } ret = nxt_conf_vldt_object(vldt, vldt->conf, nxt_conf_vldt_root_members); if (ret != NXT_OK) { - return ret; + goto fail; } ret = nxt_tstr_state_done(vldt->tstr_state, error); if (ret != NXT_OK) { - return nxt_conf_vldt_error(vldt, "%s", error); + ret = nxt_conf_vldt_error(vldt, "%s", error); + goto fail; } + nxt_tstr_state_release(vldt->tstr_state); + return NXT_OK; + +fail: + + nxt_tstr_state_release(vldt->tstr_state); + + return ret; } -- cgit From 0ebce31c9287cb97b626d61b62e83681b2864fe8 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Thu, 26 Jan 2023 15:07:12 +0100 Subject: HTTP: added route logging. - Configuration: added "/config/settings/http/log_route". Type: bool Default: false This adds configurability to the error log. It allows enabling and disabling logs related to how the router performs selection of the routes. - HTTP: logging request line. Log level: [notice] The request line is essential to understand which logs correspond to which request when reading the logs. - HTTP: logging route that's been discarded. Log level: [info] - HTTP: logging route whose action is selected. Log level: [notice] - HTTP: logging when "fallback" action is taken. Log level: [notice] Closes: Link: Link: Suggested-by: Timo Stark Suggested-by: Mark L Wood-Patrick Suggested-by: Liam Crilly Tested-by: Liam Crilly Acked-by: Artem Konev Cc: Andrew Clayton Cc: Andrei Zeliankou Reviewed-by: Zhidao Hong Signed-off-by: Alejandro Colomar --- src/nxt_conf_validation.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/nxt_conf_validation.c') diff --git a/src/nxt_conf_validation.c b/src/nxt_conf_validation.c index 537a3fb7..9169bcc9 100644 --- a/src/nxt_conf_validation.c +++ b/src/nxt_conf_validation.c @@ -344,6 +344,9 @@ static nxt_conf_vldt_object_t nxt_conf_vldt_http_members[] = { .type = NXT_CONF_VLDT_OBJECT, .validator = nxt_conf_vldt_object, .u.members = nxt_conf_vldt_static_members, + }, { + .name = nxt_string("log_route"), + .type = NXT_CONF_VLDT_BOOLEAN, }, NXT_CONF_VLDT_END -- cgit From 45c45eaeb4443ff4af9cc49e716bbd9d65596b02 Mon Sep 17 00:00:00 2001 From: Andrew Clayton Date: Thu, 30 Mar 2023 05:53:13 +0100 Subject: Add per-application logging. Currently when running in the foreground, unit application processes will send stdout to the current TTY and stderr to the unit log file. That behaviour won't change. When running as a daemon, unit application processes will send stdout to /dev/null and stderr to the unit log file. This commit allows to alter the latter case of unit running as a daemon, by allowing applications to redirect stdout and/or stderr to specific log files. This is done via two new application options, 'stdout' & 'stderr', e.g "applications": { "myapp": { ... "stdout": "/path/to/log/unit/app/stdout.log", "stderr": "/path/to/log/unit/app/stderr.log" } } These log files are created by the application processes themselves and thus the log directories need to be writable by the user (and or group) of the application processes. E.g $ sudo mkdir -p /path/to/log/unit/app $ sudo chown APP_USER /path/to/log/unit/app These need to be setup before starting unit with the above config. Currently these log files do not participate in log-file rotation (SIGUSR1), that may change in a future commit. In the meantime these logs can be rotated using the traditional copy/truncate method. NOTE: You may or may not see stuff printed to stdout as stdout was traditionally used by CGI applications to communicate with the webserver. Closes: Closes: Reviewed-by: Alejandro Colomar Signed-off-by: Andrew Clayton --- src/nxt_conf_validation.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/nxt_conf_validation.c') diff --git a/src/nxt_conf_validation.c b/src/nxt_conf_validation.c index 9169bcc9..6d798a81 100644 --- a/src/nxt_conf_validation.c +++ b/src/nxt_conf_validation.c @@ -1047,6 +1047,12 @@ static nxt_conf_vldt_object_t nxt_conf_vldt_common_members[] = { .type = NXT_CONF_VLDT_OBJECT, .validator = nxt_conf_vldt_isolation, .u.members = nxt_conf_vldt_app_isolation_members, + }, { + .name = nxt_string("stdout"), + .type = NXT_CONF_VLDT_STRING, + }, { + .name = nxt_string("stderr"), + .type = NXT_CONF_VLDT_STRING, }, NXT_CONF_VLDT_END -- cgit From 1a485fed6a8353ecc09e6c0f050e44c0a2d30419 Mon Sep 17 00:00:00 2001 From: Andrew Clayton Date: Sat, 18 Mar 2023 16:32:59 +0000 Subject: Allow to remove the version string in HTTP responses. Normally Unit responds to HTTP requests by including a header like Server: Unit/1.30.0 however it can sometimes be beneficial to withhold the version information and in this case just respond with Server: Unit This patch adds a new "settings.http" boolean option called server_version, which defaults to true, in which case the full version information is sent. However this can be set to false, e.g "settings": { "http": { "server_version": false } }, in which case Unit responds without the version information as the latter example above shows. Link: Closes: Reviewed-by: Alejandro Colomar Signed-off-by: Andrew Clayton --- src/nxt_conf_validation.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/nxt_conf_validation.c') diff --git a/src/nxt_conf_validation.c b/src/nxt_conf_validation.c index 6d798a81..9059b2b3 100644 --- a/src/nxt_conf_validation.c +++ b/src/nxt_conf_validation.c @@ -347,6 +347,9 @@ static nxt_conf_vldt_object_t nxt_conf_vldt_http_members[] = { }, { .name = nxt_string("log_route"), .type = NXT_CONF_VLDT_BOOLEAN, + }, { + .name = nxt_string("server_version"), + .type = NXT_CONF_VLDT_BOOLEAN, }, NXT_CONF_VLDT_END -- cgit From 14d6d97bacf9b06ba340ebd4211b2f1b6ad417dd Mon Sep 17 00:00:00 2001 From: Zhidao HONG Date: Thu, 20 Apr 2023 23:20:41 +0800 Subject: HTTP: added basic URI rewrite. This commit introduced the basic URI rewrite. It allows users to change request URI. Note the "rewrite" option ignores the contained query if any and the query from the request is preserverd. An example: "routes": [ { "match": { "uri": "/v1/test" }, "action": { "return": 200 } }, { "action": { "rewrite": "/v1$uri", "pass": "routes" } } ] Reviewed-by: Alejandro Colomar --- src/nxt_conf_validation.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'src/nxt_conf_validation.c') diff --git a/src/nxt_conf_validation.c b/src/nxt_conf_validation.c index 9059b2b3..c9aac790 100644 --- a/src/nxt_conf_validation.c +++ b/src/nxt_conf_validation.c @@ -669,6 +669,16 @@ static nxt_conf_vldt_object_t nxt_conf_vldt_match_members[] = { }; +static nxt_conf_vldt_object_t nxt_conf_vldt_action_common_members[] = { + { + .name = nxt_string("rewrite"), + .type = NXT_CONF_VLDT_STRING, + }, + + NXT_CONF_VLDT_END +}; + + static nxt_conf_vldt_object_t nxt_conf_vldt_pass_action_members[] = { { .name = nxt_string("pass"), @@ -677,7 +687,7 @@ static nxt_conf_vldt_object_t nxt_conf_vldt_pass_action_members[] = { .flags = NXT_CONF_VLDT_TSTR, }, - NXT_CONF_VLDT_END + NXT_CONF_VLDT_NEXT(nxt_conf_vldt_action_common_members) }; @@ -692,7 +702,7 @@ static nxt_conf_vldt_object_t nxt_conf_vldt_return_action_members[] = { .flags = NXT_CONF_VLDT_TSTR, }, - NXT_CONF_VLDT_END + NXT_CONF_VLDT_NEXT(nxt_conf_vldt_action_common_members) }; @@ -736,7 +746,7 @@ static nxt_conf_vldt_object_t nxt_conf_vldt_share_action_members[] = { #endif }, - NXT_CONF_VLDT_END + NXT_CONF_VLDT_NEXT(nxt_conf_vldt_action_common_members) }; @@ -747,7 +757,7 @@ static nxt_conf_vldt_object_t nxt_conf_vldt_proxy_action_members[] = { .validator = nxt_conf_vldt_proxy, }, - NXT_CONF_VLDT_END + NXT_CONF_VLDT_NEXT(nxt_conf_vldt_action_common_members) }; -- cgit From a3c3a29493798873ad04922bb2a7180b2ce267d5 Mon Sep 17 00:00:00 2001 From: Zhidao HONG Date: Mon, 8 May 2023 16:00:25 +0800 Subject: NJS: supported loadable modules. --- src/nxt_conf_validation.c | 74 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 61 insertions(+), 13 deletions(-) (limited to 'src/nxt_conf_validation.c') diff --git a/src/nxt_conf_validation.c b/src/nxt_conf_validation.c index c9aac790..8c75a9fe 100644 --- a/src/nxt_conf_validation.c +++ b/src/nxt_conf_validation.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -226,6 +227,13 @@ static nxt_int_t nxt_conf_vldt_cgroup_path(nxt_conf_validation_t *vldt, nxt_conf_value_t *value, void *data); #endif +#if (NXT_HAVE_NJS) +static nxt_int_t nxt_conf_vldt_js_module(nxt_conf_validation_t *vldt, + nxt_conf_value_t *value, void *data); +static nxt_int_t nxt_conf_vldt_js_module_element(nxt_conf_validation_t *vldt, + nxt_conf_value_t *value); +#endif + static nxt_conf_vldt_object_t nxt_conf_vldt_setting_members[]; static nxt_conf_vldt_object_t nxt_conf_vldt_http_members[]; @@ -297,6 +305,12 @@ static nxt_conf_vldt_object_t nxt_conf_vldt_setting_members[] = { .type = NXT_CONF_VLDT_OBJECT, .validator = nxt_conf_vldt_object, .u.members = nxt_conf_vldt_http_members, +#if (NXT_HAVE_NJS) + }, { + .name = nxt_string("js_module"), + .type = NXT_CONF_VLDT_STRING | NXT_CONF_VLDT_ARRAY, + .validator = nxt_conf_vldt_js_module, +#endif }, NXT_CONF_VLDT_END @@ -1306,35 +1320,26 @@ nxt_conf_validate(nxt_conf_validation_t *vldt) vldt->tstr_state = nxt_tstr_state_new(vldt->pool, 1); if (nxt_slow_path(vldt->tstr_state == NULL)) { - ret = NXT_ERROR; - goto fail; + return NXT_ERROR; } ret = nxt_conf_vldt_type(vldt, NULL, vldt->conf, NXT_CONF_VLDT_OBJECT); if (ret != NXT_OK) { - goto fail; + return ret; } ret = nxt_conf_vldt_object(vldt, vldt->conf, nxt_conf_vldt_root_members); if (ret != NXT_OK) { - goto fail; + return ret; } ret = nxt_tstr_state_done(vldt->tstr_state, error); if (ret != NXT_OK) { ret = nxt_conf_vldt_error(vldt, "%s", error); - goto fail; + return ret; } - nxt_tstr_state_release(vldt->tstr_state); - return NXT_OK; - -fail: - - nxt_tstr_state_release(vldt->tstr_state); - - return ret; } @@ -3241,6 +3246,49 @@ nxt_conf_vldt_server_weight(nxt_conf_validation_t *vldt, } +#if (NXT_HAVE_NJS) + +static nxt_int_t +nxt_conf_vldt_js_module(nxt_conf_validation_t *vldt, nxt_conf_value_t *value, + void *data) +{ + if (nxt_conf_type(value) == NXT_CONF_ARRAY) { + return nxt_conf_vldt_array_iterator(vldt, value, + &nxt_conf_vldt_js_module_element); + } + + /* NXT_CONF_STRING */ + + return nxt_conf_vldt_js_module_element(vldt, value); +} + + +static nxt_int_t +nxt_conf_vldt_js_module_element(nxt_conf_validation_t *vldt, + nxt_conf_value_t *value) +{ + nxt_str_t name; + nxt_conf_value_t *module; + + if (nxt_conf_type(value) != NXT_CONF_STRING) { + return nxt_conf_vldt_error(vldt, "The \"js_module\" array must " + "contain only string values."); + } + + nxt_conf_get_string(value, &name); + + module = nxt_script_info_get(&name); + if (module == NULL) { + return nxt_conf_vldt_error(vldt, "JS module \"%V\" is not found.", + &name); + } + + return NXT_OK; +} + +#endif + + typedef struct { nxt_str_t path; nxt_str_t format; -- cgit