[nginx] Core: ngx_conf_set_keyval_slot() now accepts NGX_CONF_UNSET_PTR.

Maxim Dounin mdounin at mdounin.ru
Thu Oct 22 15:02:04 UTC 2020


details:   https://hg.nginx.org/nginx/rev/485dba3e2a01
branches:  
changeset: 7728:485dba3e2a01
user:      Maxim Dounin <mdounin at mdounin.ru>
date:      Thu Oct 22 18:00:20 2020 +0300
description:
Core: ngx_conf_set_keyval_slot() now accepts NGX_CONF_UNSET_PTR.

With this change, it is now possible to use ngx_conf_merge_ptr_value()
to merge keyval arrays.  This change actually follows much earlier
changes in ngx_conf_merge_ptr_value() and ngx_conf_set_str_array_slot()
in 1452:cd586e963db0 (0.6.10) and 1701:40d004d95d88 (0.6.22).

To preserve compatibility with existing 3rd party modules, both NULL
and NGX_CONF_UNSET_PTR are accepted for now.

diffstat:

 src/core/ngx_conf_file.c                 |  2 +-
 src/http/modules/ngx_http_grpc_module.c  |  8 +++++---
 src/http/modules/ngx_http_proxy_module.c |  8 +++++---
 3 files changed, 11 insertions(+), 7 deletions(-)

diffs (81 lines):

diff -r f1e6f65ddfeb -r 485dba3e2a01 src/core/ngx_conf_file.c
--- a/src/core/ngx_conf_file.c	Tue Oct 13 07:44:09 2020 +0300
+++ b/src/core/ngx_conf_file.c	Thu Oct 22 18:00:20 2020 +0300
@@ -1137,7 +1137,7 @@ ngx_conf_set_keyval_slot(ngx_conf_t *cf,
 
     a = (ngx_array_t **) (p + cmd->offset);
 
-    if (*a == NULL) {
+    if (*a == NGX_CONF_UNSET_PTR || *a == NULL) {
         *a = ngx_array_create(cf->pool, 4, sizeof(ngx_keyval_t));
         if (*a == NULL) {
             return NGX_CONF_ERROR;
diff -r f1e6f65ddfeb -r 485dba3e2a01 src/http/modules/ngx_http_grpc_module.c
--- a/src/http/modules/ngx_http_grpc_module.c	Tue Oct 13 07:44:09 2020 +0300
+++ b/src/http/modules/ngx_http_grpc_module.c	Thu Oct 22 18:00:20 2020 +0300
@@ -4324,7 +4324,6 @@ ngx_http_grpc_create_loc_conf(ngx_conf_t
      *     conf->upstream.hide_headers_hash = { NULL, 0 };
      *     conf->upstream.ssl_name = NULL;
      *
-     *     conf->headers_source = NULL;
      *     conf->headers.lengths = NULL;
      *     conf->headers.values = NULL;
      *     conf->headers.hash = { NULL, 0 };
@@ -4377,6 +4376,8 @@ ngx_http_grpc_create_loc_conf(ngx_conf_t
     conf->upstream.pass_trailers = 1;
     conf->upstream.preserve_output = 1;
 
+    conf->headers_source = NGX_CONF_UNSET_PTR;
+
     ngx_str_set(&conf->upstream.module, "grpc");
 
     return conf;
@@ -4507,9 +4508,10 @@ ngx_http_grpc_merge_loc_conf(ngx_conf_t 
         clcf->handler = ngx_http_grpc_handler;
     }
 
-    if (conf->headers_source == NULL) {
+    ngx_conf_merge_ptr_value(conf->headers_source, prev->headers_source, NULL);
+
+    if (conf->headers_source == prev->headers_source) {
         conf->headers = prev->headers;
-        conf->headers_source = prev->headers_source;
         conf->host_set = prev->host_set;
     }
 
diff -r f1e6f65ddfeb -r 485dba3e2a01 src/http/modules/ngx_http_proxy_module.c
--- a/src/http/modules/ngx_http_proxy_module.c	Tue Oct 13 07:44:09 2020 +0300
+++ b/src/http/modules/ngx_http_proxy_module.c	Thu Oct 22 18:00:20 2020 +0300
@@ -3268,7 +3268,6 @@ ngx_http_proxy_create_loc_conf(ngx_conf_
      *     conf->method = NULL;
      *     conf->location = NULL;
      *     conf->url = { 0, NULL };
-     *     conf->headers_source = NULL;
      *     conf->headers.lengths = NULL;
      *     conf->headers.values = NULL;
      *     conf->headers.hash = { NULL, 0 };
@@ -3346,6 +3345,8 @@ ngx_http_proxy_create_loc_conf(ngx_conf_
     /* "proxy_cyclic_temp_file" is disabled */
     conf->upstream.cyclic_temp_file = 0;
 
+    conf->headers_source = NGX_CONF_UNSET_PTR;
+
     conf->redirect = NGX_CONF_UNSET;
     conf->upstream.change_buffering = 1;
 
@@ -3819,12 +3820,13 @@ ngx_http_proxy_merge_loc_conf(ngx_conf_t
         }
     }
 
-    if (conf->headers_source == NULL) {
+    ngx_conf_merge_ptr_value(conf->headers_source, prev->headers_source, NULL);
+
+    if (conf->headers_source == prev->headers_source) {
         conf->headers = prev->headers;
 #if (NGX_HTTP_CACHE)
         conf->headers_cache = prev->headers_cache;
 #endif
-        conf->headers_source = prev->headers_source;
     }
 
     rc = ngx_http_proxy_init_headers(cf, conf, &conf->headers,


More information about the nginx-devel mailing list