From f23297f57d984e85413e8ff902a80f0682889bc1 Mon Sep 17 00:00:00 2001 From: Dmitry Volyntsev Date: Fri, 5 Dec 2025 17:08:54 -0800 Subject: [PATCH] Modules: extracted config-time merging into separate function. This introduces ngx_js_merge_conftime_loc_conf() to handle merging of configuration-time properties. Normally ngx_js_merge_conf() does all the default value initialization for child location configurations. There is a special case for global "http" or "stream" configuration where the parent configuration needs to be initialized (so it can be reused by server configurations if no additional directives were defined in them). But parent configurations are not initialized by ngx_js_merge_conf(). Most of the ngx_js_loc_conf_t values are only used at runtime, so only configuration-time values need to be merged in the parent. The runtime values will be provided from the appropriate ngx_js_loc_conf_t during request processing. Previously, configuration-time merging was done inline. Extracting it into a dedicated function simplifies adding new configuration-time properties. --- nginx/ngx_js.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/nginx/ngx_js.c b/nginx/ngx_js.c index b0b64d97..c18e97d5 100644 --- a/nginx/ngx_js.c +++ b/nginx/ngx_js.c @@ -3597,6 +3597,17 @@ ngx_js_init_preload_vm(njs_vm_t *vm, ngx_js_loc_conf_t *conf) } +/* + * Merge configuration values used at configuration time. + */ +static void +ngx_js_merge_conftime_loc_conf(ngx_js_loc_conf_t *conf, + ngx_js_loc_conf_t *prev) +{ + ngx_conf_merge_uint_value(conf->type, prev->type, NGX_ENGINE_NJS); +} + + ngx_int_t ngx_js_merge_vm(ngx_conf_t *cf, ngx_js_loc_conf_t *conf, ngx_js_loc_conf_t *prev, @@ -3612,6 +3623,9 @@ ngx_js_merge_vm(ngx_conf_t *cf, ngx_js_loc_conf_t *conf, * special handling to preserve conf->engine * in the "http" or "stream" section to inherit it to all servers */ + + ngx_js_merge_conftime_loc_conf(prev, conf); + if (init_vm(cf, (ngx_js_loc_conf_t *) prev) != NGX_OK) { return NGX_ERROR; } @@ -4316,10 +4330,7 @@ ngx_js_merge_conf(ngx_conf_t *cf, void *parent, void *child, ngx_js_loc_conf_t *prev = parent; ngx_js_loc_conf_t *conf = child; - ngx_conf_merge_uint_value(conf->type, prev->type, NGX_ENGINE_NJS); - if (prev->type == NGX_CONF_UNSET_UINT) { - prev->type = NGX_ENGINE_NJS; - } + ngx_js_merge_conftime_loc_conf(conf, prev); ngx_conf_merge_msec_value(conf->timeout, prev->timeout, 60000); ngx_conf_merge_size_value(conf->reuse, prev->reuse, 128); -- 2.47.3