[nginx] Upstream: moved header lists to separate structures.

Roman Arutyunyan arut at nginx.com
Wed Nov 19 14:38:01 UTC 2014


details:   http://hg.nginx.org/nginx/rev/f8e80f8c7fc7
branches:  
changeset: 5908:f8e80f8c7fc7
user:      Roman Arutyunyan <arut at nginx.com>
date:      Wed Nov 19 17:33:22 2014 +0300
description:
Upstream: moved header lists to separate structures.

No functional changes.

diffstat:

 src/http/modules/ngx_http_fastcgi_module.c |  85 ++++++++++++++-------------
 src/http/modules/ngx_http_proxy_module.c   |  91 ++++++++++++++++-------------
 src/http/modules/ngx_http_scgi_module.c    |  82 ++++++++++++++------------
 src/http/modules/ngx_http_uwsgi_module.c   |  84 ++++++++++++++-------------
 4 files changed, 182 insertions(+), 160 deletions(-)

diffs (truncated from 1050 to 300 lines):

diff -r 195561ef367f -r f8e80f8c7fc7 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:22 2014 +0300
@@ -11,22 +11,27 @@
 
 
 typedef struct {
+    ngx_array_t                   *flushes;
+    ngx_array_t                   *lengths;
+    ngx_array_t                   *values;
+    ngx_uint_t                     number;
+    ngx_hash_t                     hash;
+} ngx_http_fastcgi_params_t;
+
+
+typedef struct {
     ngx_http_upstream_conf_t       upstream;
 
     ngx_str_t                      index;
 
-    ngx_array_t                   *flushes;
-    ngx_array_t                   *params_len;
-    ngx_array_t                   *params;
+    ngx_http_fastcgi_params_t      params;
+
     ngx_array_t                   *params_source;
     ngx_array_t                   *catch_stderr;
 
     ngx_array_t                   *fastcgi_lengths;
     ngx_array_t                   *fastcgi_values;
 
-    ngx_hash_t                     headers_hash;
-    ngx_uint_t                     header_params;
-
     ngx_flag_t                     keep_conn;
 
 #if (NGX_HTTP_CACHE)
@@ -151,7 +156,7 @@ static void *ngx_http_fastcgi_create_loc
 static char *ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf,
     void *parent, void *child);
 static ngx_int_t ngx_http_fastcgi_init_params(ngx_conf_t *cf,
-    ngx_http_fastcgi_loc_conf_t *conf);
+    ngx_http_fastcgi_loc_conf_t *conf, ngx_http_fastcgi_params_t *params);
 
 static ngx_int_t ngx_http_fastcgi_script_name_variable(ngx_http_request_t *r,
     ngx_http_variable_value_t *v, uintptr_t data);
@@ -780,6 +785,7 @@ ngx_http_fastcgi_create_request(ngx_http
     ngx_http_script_code_pt       code;
     ngx_http_script_engine_t      e, le;
     ngx_http_fastcgi_header_t    *h;
+    ngx_http_fastcgi_params_t    *params;
     ngx_http_fastcgi_loc_conf_t  *flcf;
     ngx_http_script_len_code_pt   lcode;
 
@@ -789,13 +795,15 @@ ngx_http_fastcgi_create_request(ngx_http
 
     flcf = ngx_http_get_module_loc_conf(r, ngx_http_fastcgi_module);
 
-    if (flcf->params_len) {
+    params = &flcf->params;
+
+    if (params->lengths) {
         ngx_memzero(&le, sizeof(ngx_http_script_engine_t));
 
-        ngx_http_script_flush_no_cacheable_variables(r, flcf->flushes);
+        ngx_http_script_flush_no_cacheable_variables(r, params->flushes);
         le.flushed = 1;
 
-        le.ip = flcf->params_len->elts;
+        le.ip = params->lengths->elts;
         le.request = r;
 
         while (*(uintptr_t *) le.ip) {
@@ -824,7 +832,7 @@ ngx_http_fastcgi_create_request(ngx_http
         allocated = 0;
         lowcase_key = NULL;
 
-        if (flcf->header_params) {
+        if (params->number) {
             n = 0;
             part = &r->headers_in.headers.part;
 
@@ -854,7 +862,7 @@ ngx_http_fastcgi_create_request(ngx_http
                 i = 0;
             }
 
-            if (flcf->header_params) {
+            if (params->number) {
                 if (allocated < header[i].key.len) {
                     allocated = header[i].key.len + 16;
                     lowcase_key = ngx_pnalloc(r->pool, allocated);
@@ -879,7 +887,7 @@ ngx_http_fastcgi_create_request(ngx_http
                     lowcase_key[n] = ch;
                 }
 
-                if (ngx_hash_find(&flcf->headers_hash, hash, lowcase_key, n)) {
+                if (ngx_hash_find(&params->hash, hash, lowcase_key, n)) {
                     ignored[header_params++] = &header[i];
                     continue;
                 }
@@ -949,15 +957,15 @@ ngx_http_fastcgi_create_request(ngx_http
                      + sizeof(ngx_http_fastcgi_header_t);
 
 
-    if (flcf->params_len) {
+    if (params->lengths) {
         ngx_memzero(&e, sizeof(ngx_http_script_engine_t));
 
-        e.ip = flcf->params->elts;
+        e.ip = params->values->elts;
         e.pos = b->last;
         e.request = r;
         e.flushed = 1;
 
-        le.ip = flcf->params_len->elts;
+        le.ip = params->lengths->elts;
 
         while (*(uintptr_t *) le.ip) {
 
@@ -2710,15 +2718,11 @@ ngx_http_fastcgi_merge_loc_conf(ngx_conf
         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) {
+    if (ngx_http_fastcgi_init_params(cf, conf, &conf->params) != NGX_OK) {
         return NGX_CONF_ERROR;
     }
 
@@ -2727,7 +2731,8 @@ ngx_http_fastcgi_merge_loc_conf(ngx_conf
 
 
 static ngx_int_t
-ngx_http_fastcgi_init_params(ngx_conf_t *cf, ngx_http_fastcgi_loc_conf_t *conf)
+ngx_http_fastcgi_init_params(ngx_conf_t *cf, ngx_http_fastcgi_loc_conf_t *conf,
+    ngx_http_fastcgi_params_t *params)
 {
     u_char                       *p;
     size_t                        size;
@@ -2743,7 +2748,7 @@ ngx_http_fastcgi_init_params(ngx_conf_t 
     ngx_http_script_compile_t     sc;
     ngx_http_script_copy_code_t  *copy;
 
-    if (conf->headers_hash.buckets) {
+    if (params->hash.buckets) {
         return NGX_OK;
     }
 
@@ -2753,17 +2758,17 @@ ngx_http_fastcgi_init_params(ngx_conf_t 
 #endif
        )
     {
-        conf->headers_hash.buckets = (void *) 1;
+        params->hash.buckets = (void *) 1;
         return NGX_OK;
     }
 
-    conf->params_len = ngx_array_create(cf->pool, 64, 1);
-    if (conf->params_len == NULL) {
+    params->lengths = ngx_array_create(cf->pool, 64, 1);
+    if (params->lengths == NULL) {
         return NGX_ERROR;
     }
 
-    conf->params = ngx_array_create(cf->pool, 512, 1);
-    if (conf->params == NULL) {
+    params->values = ngx_array_create(cf->pool, 512, 1);
+    if (params->values == NULL) {
         return NGX_ERROR;
     }
 
@@ -2858,7 +2863,7 @@ ngx_http_fastcgi_init_params(ngx_conf_t 
             }
         }
 
-        copy = ngx_array_push_n(conf->params_len,
+        copy = ngx_array_push_n(params->lengths,
                                 sizeof(ngx_http_script_copy_code_t));
         if (copy == NULL) {
             return NGX_ERROR;
@@ -2867,7 +2872,7 @@ ngx_http_fastcgi_init_params(ngx_conf_t 
         copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code;
         copy->len = src[i].key.len;
 
-        copy = ngx_array_push_n(conf->params_len,
+        copy = ngx_array_push_n(params->lengths,
                                 sizeof(ngx_http_script_copy_code_t));
         if (copy == NULL) {
             return NGX_ERROR;
@@ -2881,7 +2886,7 @@ ngx_http_fastcgi_init_params(ngx_conf_t 
                 + src[i].key.len + sizeof(uintptr_t) - 1)
                & ~(sizeof(uintptr_t) - 1);
 
-        copy = ngx_array_push_n(conf->params, size);
+        copy = ngx_array_push_n(params->values, size);
         if (copy == NULL) {
             return NGX_ERROR;
         }
@@ -2897,15 +2902,15 @@ ngx_http_fastcgi_init_params(ngx_conf_t 
 
         sc.cf = cf;
         sc.source = &src[i].value;
-        sc.flushes = &conf->flushes;
-        sc.lengths = &conf->params_len;
-        sc.values = &conf->params;
+        sc.flushes = &params->flushes;
+        sc.lengths = &params->lengths;
+        sc.values = &params->values;
 
         if (ngx_http_script_compile(&sc) != NGX_OK) {
             return NGX_ERROR;
         }
 
-        code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t));
+        code = ngx_array_push_n(params->lengths, sizeof(uintptr_t));
         if (code == NULL) {
             return NGX_ERROR;
         }
@@ -2913,7 +2918,7 @@ ngx_http_fastcgi_init_params(ngx_conf_t 
         *code = (uintptr_t) NULL;
 
 
-        code = ngx_array_push_n(conf->params, sizeof(uintptr_t));
+        code = ngx_array_push_n(params->values, sizeof(uintptr_t));
         if (code == NULL) {
             return NGX_ERROR;
         }
@@ -2921,16 +2926,16 @@ ngx_http_fastcgi_init_params(ngx_conf_t 
         *code = (uintptr_t) NULL;
     }
 
-    code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t));
+    code = ngx_array_push_n(params->lengths, sizeof(uintptr_t));
     if (code == NULL) {
         return NGX_ERROR;
     }
 
     *code = (uintptr_t) NULL;
 
-    conf->header_params = headers_names.nelts;
-
-    hash.hash = &conf->headers_hash;
+    params->number = headers_names.nelts;
+
+    hash.hash = &params->hash;
     hash.key = ngx_hash_key_lc;
     hash.max_size = 512;
     hash.bucket_size = 64;
diff -r 195561ef367f -r f8e80f8c7fc7 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:22 2014 +0300
@@ -40,15 +40,21 @@ typedef struct {
 
 
 typedef struct {
+    ngx_array_t                   *flushes;
+    ngx_array_t                   *lengths;
+    ngx_array_t                   *values;
+    ngx_hash_t                     hash;
+} ngx_http_proxy_headers_t;
+
+
+typedef struct {
     ngx_http_upstream_conf_t       upstream;
 
-    ngx_array_t                   *flushes;
+    ngx_array_t                   *body_flushes;
     ngx_array_t                   *body_set_len;
     ngx_array_t                   *body_set;
-    ngx_array_t                   *headers_set_len;
-    ngx_array_t                   *headers_set;
-    ngx_hash_t                     headers_set_hash;
-
+
+    ngx_http_proxy_headers_t       headers;
     ngx_array_t                   *headers_source;
 
     ngx_array_t                   *proxy_lengths;
@@ -147,7 +153,7 @@ static void *ngx_http_proxy_create_loc_c
 static char *ngx_http_proxy_merge_loc_conf(ngx_conf_t *cf,
     void *parent, void *child);
 static ngx_int_t ngx_http_proxy_init_headers(ngx_conf_t *cf,
-    ngx_http_proxy_loc_conf_t *conf);
+    ngx_http_proxy_loc_conf_t *conf, ngx_http_proxy_headers_t *headers);
 
 static char *ngx_http_proxy_pass(ngx_conf_t *cf, ngx_command_t *cmd,
     void *conf);
@@ -1080,6 +1086,7 @@ ngx_http_proxy_create_request(ngx_http_r
     ngx_http_upstream_t          *u;
     ngx_http_proxy_ctx_t         *ctx;
     ngx_http_script_code_pt       code;
+    ngx_http_proxy_headers_t     *headers;
     ngx_http_script_engine_t      e, le;



More information about the nginx-devel mailing list