[nginx] Upstream: moved header initializations to separate funct...

Roman Arutyunyan arut at nginx.com
Wed Nov 19 14:37:59 UTC 2014


details:   http://hg.nginx.org/nginx/rev/195561ef367f
branches:  
changeset: 5907:195561ef367f
user:      Roman Arutyunyan <arut at nginx.com>
date:      Wed Nov 19 17:33:21 2014 +0300
description:
Upstream: moved header initializations to separate functions.

No functional changes.

diffstat:

 src/http/modules/ngx_http_fastcgi_module.c |  44 ++++++++++++++---------------
 src/http/modules/ngx_http_proxy_module.c   |  39 ++++++++++++-------------
 src/http/modules/ngx_http_scgi_module.c    |  44 ++++++++++++++---------------
 src/http/modules/ngx_http_uwsgi_module.c   |  44 ++++++++++++++---------------
 4 files changed, 82 insertions(+), 89 deletions(-)

diffs (298 lines):

diff -r 548f704c1907 -r 195561ef367f src/http/modules/ngx_http_fastcgi_module.c
--- a/src/http/modules/ngx_http_fastcgi_module.c	Wed Nov 19 17:33:21 2014 +0300
+++ b/src/http/modules/ngx_http_fastcgi_module.c	Wed Nov 19 17:33:21 2014 +0300
@@ -150,8 +150,8 @@ static ngx_int_t ngx_http_fastcgi_add_va
 static void *ngx_http_fastcgi_create_loc_conf(ngx_conf_t *cf);
 static char *ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf,
     void *parent, void *child);
-static ngx_int_t ngx_http_fastcgi_merge_params(ngx_conf_t *cf,
-    ngx_http_fastcgi_loc_conf_t *conf, ngx_http_fastcgi_loc_conf_t *prev);
+static ngx_int_t ngx_http_fastcgi_init_params(ngx_conf_t *cf,
+    ngx_http_fastcgi_loc_conf_t *conf);
 
 static ngx_int_t ngx_http_fastcgi_script_name_variable(ngx_http_request_t *r,
     ngx_http_variable_value_t *v, uintptr_t data);
@@ -2703,7 +2703,22 @@ ngx_http_fastcgi_merge_loc_conf(ngx_conf
     }
 #endif
 
-    if (ngx_http_fastcgi_merge_params(cf, conf, prev) != NGX_OK) {
+    if (conf->params_source == NULL) {
+        conf->params_source = prev->params_source;
+
+#if (NGX_HTTP_CACHE)
+        if ((conf->upstream.cache == NULL) == (prev->upstream.cache == NULL))
+#endif
+        {
+            conf->flushes = prev->flushes;
+            conf->params_len = prev->params_len;
+            conf->params = prev->params;
+            conf->headers_hash = prev->headers_hash;
+            conf->header_params = prev->header_params;
+        }
+    }
+
+    if (ngx_http_fastcgi_init_params(cf, conf) != NGX_OK) {
         return NGX_CONF_ERROR;
     }
 
@@ -2712,8 +2727,7 @@ ngx_http_fastcgi_merge_loc_conf(ngx_conf
 
 
 static ngx_int_t
-ngx_http_fastcgi_merge_params(ngx_conf_t *cf,
-    ngx_http_fastcgi_loc_conf_t *conf, ngx_http_fastcgi_loc_conf_t *prev)
+ngx_http_fastcgi_init_params(ngx_conf_t *cf, ngx_http_fastcgi_loc_conf_t *conf)
 {
     u_char                       *p;
     size_t                        size;
@@ -2729,24 +2743,8 @@ ngx_http_fastcgi_merge_params(ngx_conf_t
     ngx_http_script_compile_t     sc;
     ngx_http_script_copy_code_t  *copy;
 
-    if (conf->params_source == NULL) {
-        conf->params_source = prev->params_source;
-
-        if (prev->headers_hash.buckets
-#if (NGX_HTTP_CACHE)
-            && ((conf->upstream.cache == NULL)
-                == (prev->upstream.cache == NULL))
-#endif
-           )
-        {
-            conf->flushes = prev->flushes;
-            conf->params_len = prev->params_len;
-            conf->params = prev->params;
-            conf->headers_hash = prev->headers_hash;
-            conf->header_params = prev->header_params;
-
-            return NGX_OK;
-        }
+    if (conf->headers_hash.buckets) {
+        return NGX_OK;
     }
 
     if (conf->params_source == NULL
diff -r 548f704c1907 -r 195561ef367f src/http/modules/ngx_http_proxy_module.c
--- a/src/http/modules/ngx_http_proxy_module.c	Wed Nov 19 17:33:21 2014 +0300
+++ b/src/http/modules/ngx_http_proxy_module.c	Wed Nov 19 17:33:21 2014 +0300
@@ -146,8 +146,8 @@ static ngx_int_t ngx_http_proxy_add_vari
 static void *ngx_http_proxy_create_loc_conf(ngx_conf_t *cf);
 static char *ngx_http_proxy_merge_loc_conf(ngx_conf_t *cf,
     void *parent, void *child);
-static ngx_int_t ngx_http_proxy_merge_headers(ngx_conf_t *cf,
-    ngx_http_proxy_loc_conf_t *conf, ngx_http_proxy_loc_conf_t *prev);
+static ngx_int_t ngx_http_proxy_init_headers(ngx_conf_t *cf,
+    ngx_http_proxy_loc_conf_t *conf);
 
 static char *ngx_http_proxy_pass(ngx_conf_t *cf, ngx_command_t *cmd,
     void *conf);
@@ -3015,7 +3015,21 @@ ngx_http_proxy_merge_loc_conf(ngx_conf_t
         }
     }
 
-    if (ngx_http_proxy_merge_headers(cf, conf, prev) != NGX_OK) {
+    if (conf->headers_source == NULL) {
+        conf->flushes = prev->flushes;
+        conf->headers_set_len = prev->headers_set_len;
+        conf->headers_set = prev->headers_set;
+        conf->headers_set_hash = prev->headers_set_hash;
+        conf->headers_source = prev->headers_source;
+    }
+
+#if (NGX_HTTP_CACHE)
+    if ((conf->upstream.cache == NULL) != (prev->upstream.cache == NULL)) {
+        conf->headers_set_hash.buckets = NULL;
+    }
+#endif
+
+    if (ngx_http_proxy_init_headers(cf, conf) != NGX_OK) {
         return NGX_CONF_ERROR;
     }
 
@@ -3024,8 +3038,7 @@ ngx_http_proxy_merge_loc_conf(ngx_conf_t
 
 
 static ngx_int_t
-ngx_http_proxy_merge_headers(ngx_conf_t *cf, ngx_http_proxy_loc_conf_t *conf,
-    ngx_http_proxy_loc_conf_t *prev)
+ngx_http_proxy_init_headers(ngx_conf_t *cf, ngx_http_proxy_loc_conf_t *conf)
 {
     u_char                       *p;
     size_t                        size;
@@ -3038,24 +3051,10 @@ ngx_http_proxy_merge_headers(ngx_conf_t 
     ngx_http_script_compile_t     sc;
     ngx_http_script_copy_code_t  *copy;
 
-    if (conf->headers_source == NULL) {
-        conf->flushes = prev->flushes;
-        conf->headers_set_len = prev->headers_set_len;
-        conf->headers_set = prev->headers_set;
-        conf->headers_set_hash = prev->headers_set_hash;
-        conf->headers_source = prev->headers_source;
-    }
-
-    if (conf->headers_set_hash.buckets
-#if (NGX_HTTP_CACHE)
-        && ((conf->upstream.cache == NULL) == (prev->upstream.cache == NULL))
-#endif
-       )
-    {
+    if (conf->headers_set_hash.buckets) {
         return NGX_OK;
     }
 
-
     if (ngx_array_init(&headers_names, cf->temp_pool, 4, sizeof(ngx_hash_key_t))
         != NGX_OK)
     {
diff -r 548f704c1907 -r 195561ef367f src/http/modules/ngx_http_scgi_module.c
--- a/src/http/modules/ngx_http_scgi_module.c	Wed Nov 19 17:33:21 2014 +0300
+++ b/src/http/modules/ngx_http_scgi_module.c	Wed Nov 19 17:33:21 2014 +0300
@@ -43,8 +43,8 @@ static void ngx_http_scgi_finalize_reque
 static void *ngx_http_scgi_create_loc_conf(ngx_conf_t *cf);
 static char *ngx_http_scgi_merge_loc_conf(ngx_conf_t *cf, void *parent,
     void *child);
-static ngx_int_t ngx_http_scgi_merge_params(ngx_conf_t *cf,
-    ngx_http_scgi_loc_conf_t *conf, ngx_http_scgi_loc_conf_t *prev);
+static ngx_int_t ngx_http_scgi_init_params(ngx_conf_t *cf,
+    ngx_http_scgi_loc_conf_t *conf);
 
 static char *ngx_http_scgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
 static char *ngx_http_scgi_store(ngx_conf_t *cf, ngx_command_t *cmd,
@@ -1443,7 +1443,22 @@ ngx_http_scgi_merge_loc_conf(ngx_conf_t 
         }
     }
 
-    if (ngx_http_scgi_merge_params(cf, conf, prev) != NGX_OK) {
+    if (conf->params_source == NULL) {
+        conf->params_source = prev->params_source;
+
+#if (NGX_HTTP_CACHE)
+        if ((conf->upstream.cache == NULL) == (prev->upstream.cache == NULL))
+#endif
+        {
+            conf->flushes = prev->flushes;
+            conf->params_len = prev->params_len;
+            conf->params = prev->params;
+            conf->headers_hash = prev->headers_hash;
+            conf->header_params = prev->header_params;
+        }
+    }
+
+    if (ngx_http_scgi_init_params(cf, conf) != NGX_OK) {
         return NGX_CONF_ERROR;
     }
 
@@ -1452,8 +1467,7 @@ ngx_http_scgi_merge_loc_conf(ngx_conf_t 
 
 
 static ngx_int_t
-ngx_http_scgi_merge_params(ngx_conf_t *cf, ngx_http_scgi_loc_conf_t *conf,
-    ngx_http_scgi_loc_conf_t *prev)
+ngx_http_scgi_init_params(ngx_conf_t *cf, ngx_http_scgi_loc_conf_t *conf)
 {
     u_char                       *p;
     size_t                        size;
@@ -1469,24 +1483,8 @@ ngx_http_scgi_merge_params(ngx_conf_t *c
     ngx_http_script_compile_t     sc;
     ngx_http_script_copy_code_t  *copy;
 
-    if (conf->params_source == NULL) {
-        conf->params_source = prev->params_source;
-
-        if (prev->headers_hash.buckets
-#if (NGX_HTTP_CACHE)
-            && ((conf->upstream.cache == NULL)
-                == (prev->upstream.cache == NULL))
-#endif
-           )
-        {
-            conf->flushes = prev->flushes;
-            conf->params_len = prev->params_len;
-            conf->params = prev->params;
-            conf->headers_hash = prev->headers_hash;
-            conf->header_params = prev->header_params;
-
-            return NGX_OK;
-        }
+    if (conf->headers_hash.buckets) {
+        return NGX_OK;
     }
 
     if (conf->params_source == NULL
diff -r 548f704c1907 -r 195561ef367f src/http/modules/ngx_http_uwsgi_module.c
--- a/src/http/modules/ngx_http_uwsgi_module.c	Wed Nov 19 17:33:21 2014 +0300
+++ b/src/http/modules/ngx_http_uwsgi_module.c	Wed Nov 19 17:33:21 2014 +0300
@@ -62,8 +62,8 @@ static void ngx_http_uwsgi_finalize_requ
 static void *ngx_http_uwsgi_create_loc_conf(ngx_conf_t *cf);
 static char *ngx_http_uwsgi_merge_loc_conf(ngx_conf_t *cf, void *parent,
     void *child);
-static ngx_int_t ngx_http_uwsgi_merge_params(ngx_conf_t *cf,
-    ngx_http_uwsgi_loc_conf_t *conf, ngx_http_uwsgi_loc_conf_t *prev);
+static ngx_int_t ngx_http_uwsgi_init_params(ngx_conf_t *cf,
+    ngx_http_uwsgi_loc_conf_t *conf);
 
 static char *ngx_http_uwsgi_pass(ngx_conf_t *cf, ngx_command_t *cmd,
     void *conf);
@@ -1705,7 +1705,22 @@ ngx_http_uwsgi_merge_loc_conf(ngx_conf_t
     ngx_conf_merge_uint_value(conf->modifier1, prev->modifier1, 0);
     ngx_conf_merge_uint_value(conf->modifier2, prev->modifier2, 0);
 
-    if (ngx_http_uwsgi_merge_params(cf, conf, prev) != NGX_OK) {
+    if (conf->params_source == NULL) {
+        conf->params_source = prev->params_source;
+
+#if (NGX_HTTP_CACHE)
+        if ((conf->upstream.cache == NULL) == (prev->upstream.cache == NULL))
+#endif
+        {
+            conf->flushes = prev->flushes;
+            conf->params_len = prev->params_len;
+            conf->params = prev->params;
+            conf->headers_hash = prev->headers_hash;
+            conf->header_params = prev->header_params;
+        }
+    }
+
+    if (ngx_http_uwsgi_init_params(cf, conf) != NGX_OK) {
         return NGX_CONF_ERROR;
     }
 
@@ -1714,8 +1729,7 @@ ngx_http_uwsgi_merge_loc_conf(ngx_conf_t
 
 
 static ngx_int_t
-ngx_http_uwsgi_merge_params(ngx_conf_t *cf, ngx_http_uwsgi_loc_conf_t *conf,
-    ngx_http_uwsgi_loc_conf_t *prev)
+ngx_http_uwsgi_init_params(ngx_conf_t *cf, ngx_http_uwsgi_loc_conf_t *conf)
 {
     u_char                       *p;
     size_t                        size;
@@ -1731,24 +1745,8 @@ ngx_http_uwsgi_merge_params(ngx_conf_t *
     ngx_http_script_compile_t     sc;
     ngx_http_script_copy_code_t  *copy;
 
-    if (conf->params_source == NULL) {
-        conf->params_source = prev->params_source;
-
-        if (prev->headers_hash.buckets
-#if (NGX_HTTP_CACHE)
-            && ((conf->upstream.cache == NULL)
-                == (prev->upstream.cache == NULL))
-#endif
-           )
-        {
-            conf->flushes = prev->flushes;
-            conf->params_len = prev->params_len;
-            conf->params = prev->params;
-            conf->headers_hash = prev->headers_hash;
-            conf->header_params = prev->header_params;
-
-            return NGX_OK;
-        }
+    if (conf->headers_hash.buckets) {
+        return NGX_OK;
     }
 
     if (conf->params_source == NULL



More information about the nginx-devel mailing list