diff src/http/modules/ngx_http_uwsgi_module.c @ 5908:f8e80f8c7fc7

Upstream: moved header lists to separate structures. No functional changes.
author Roman Arutyunyan <arut@nginx.com>
date Wed, 19 Nov 2014 17:33:22 +0300
parents 195561ef367f
children 8d0cf26ce071
line wrap: on
line diff
--- a/src/http/modules/ngx_http_uwsgi_module.c
+++ b/src/http/modules/ngx_http_uwsgi_module.c
@@ -13,16 +13,20 @@
 
 
 typedef struct {
+    ngx_array_t               *flushes;
+    ngx_array_t               *lengths;
+    ngx_array_t               *values;
+    ngx_uint_t                 number;
+    ngx_hash_t                 hash;
+} ngx_http_uwsgi_params_t;
+
+
+typedef struct {
     ngx_http_upstream_conf_t   upstream;
 
-    ngx_array_t               *flushes;
-    ngx_array_t               *params_len;
-    ngx_array_t               *params;
+    ngx_http_uwsgi_params_t    params;
     ngx_array_t               *params_source;
 
-    ngx_hash_t                 headers_hash;
-    ngx_uint_t                 header_params;
-
     ngx_array_t               *uwsgi_lengths;
     ngx_array_t               *uwsgi_values;
 
@@ -63,7 +67,7 @@ static void *ngx_http_uwsgi_create_loc_c
 static char *ngx_http_uwsgi_merge_loc_conf(ngx_conf_t *cf, void *parent,
     void *child);
 static ngx_int_t ngx_http_uwsgi_init_params(ngx_conf_t *cf,
-    ngx_http_uwsgi_loc_conf_t *conf);
+    ngx_http_uwsgi_loc_conf_t *conf, ngx_http_uwsgi_params_t *params);
 
 static char *ngx_http_uwsgi_pass(ngx_conf_t *cf, ngx_command_t *cmd,
     void *conf);
@@ -779,6 +783,7 @@ ngx_http_uwsgi_create_request(ngx_http_r
     ngx_chain_t                  *cl, *body;
     ngx_list_part_t              *part;
     ngx_table_elt_t              *header, **ignored;
+    ngx_http_uwsgi_params_t      *params;
     ngx_http_script_code_pt       code;
     ngx_http_script_engine_t      e, le;
     ngx_http_uwsgi_loc_conf_t    *uwcf;
@@ -790,13 +795,15 @@ ngx_http_uwsgi_create_request(ngx_http_r
 
     uwcf = ngx_http_get_module_loc_conf(r, ngx_http_uwsgi_module);
 
-    if (uwcf->params_len) {
+    params = &uwcf->params;
+
+    if (params->lengths) {
         ngx_memzero(&le, sizeof(ngx_http_script_engine_t));
 
-        ngx_http_script_flush_no_cacheable_variables(r, uwcf->flushes);
+        ngx_http_script_flush_no_cacheable_variables(r, params->flushes);
         le.flushed = 1;
 
-        le.ip = uwcf->params_len->elts;
+        le.ip = params->lengths->elts;
         le.request = r;
 
         while (*(uintptr_t *) le.ip) {
@@ -825,7 +832,7 @@ ngx_http_uwsgi_create_request(ngx_http_r
         allocated = 0;
         lowcase_key = NULL;
 
-        if (uwcf->header_params) {
+        if (params->number) {
             n = 0;
             part = &r->headers_in.headers.part;
 
@@ -855,7 +862,7 @@ ngx_http_uwsgi_create_request(ngx_http_r
                 i = 0;
             }
 
-            if (uwcf->header_params) {
+            if (params->number) {
                 if (allocated < header[i].key.len) {
                     allocated = header[i].key.len + 16;
                     lowcase_key = ngx_pnalloc(r->pool, allocated);
@@ -880,7 +887,7 @@ ngx_http_uwsgi_create_request(ngx_http_r
                     lowcase_key[n] = ch;
                 }
 
-                if (ngx_hash_find(&uwcf->headers_hash, hash, lowcase_key, n)) {
+                if (ngx_hash_find(&params->hash, hash, lowcase_key, n)) {
                     ignored[header_params++] = &header[i];
                     continue;
                 }
@@ -919,15 +926,15 @@ ngx_http_uwsgi_create_request(ngx_http_r
     *b->last++ = (u_char) ((len >> 8) & 0xff);
     *b->last++ = (u_char) uwcf->modifier2;
 
-    if (uwcf->params_len) {
+    if (params->lengths) {
         ngx_memzero(&e, sizeof(ngx_http_script_engine_t));
 
-        e.ip = uwcf->params->elts;
+        e.ip = params->values->elts;
         e.pos = b->last;
         e.request = r;
         e.flushed = 1;
 
-        le.ip = uwcf->params_len->elts;
+        le.ip = params->lengths->elts;
 
         while (*(uintptr_t *) le.ip) {
 
@@ -1712,15 +1719,11 @@ ngx_http_uwsgi_merge_loc_conf(ngx_conf_t
         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) {
+    if (ngx_http_uwsgi_init_params(cf, conf, &conf->params) != NGX_OK) {
         return NGX_CONF_ERROR;
     }
 
@@ -1729,7 +1732,8 @@ ngx_http_uwsgi_merge_loc_conf(ngx_conf_t
 
 
 static ngx_int_t
-ngx_http_uwsgi_init_params(ngx_conf_t *cf, ngx_http_uwsgi_loc_conf_t *conf)
+ngx_http_uwsgi_init_params(ngx_conf_t *cf, ngx_http_uwsgi_loc_conf_t *conf,
+    ngx_http_uwsgi_params_t *params)
 {
     u_char                       *p;
     size_t                        size;
@@ -1745,7 +1749,7 @@ ngx_http_uwsgi_init_params(ngx_conf_t *c
     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;
     }
 
@@ -1755,17 +1759,17 @@ ngx_http_uwsgi_init_params(ngx_conf_t *c
 #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;
     }
 
@@ -1860,7 +1864,7 @@ ngx_http_uwsgi_init_params(ngx_conf_t *c
             }
         }
 
-        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;
@@ -1869,7 +1873,7 @@ ngx_http_uwsgi_init_params(ngx_conf_t *c
         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;
@@ -1883,7 +1887,7 @@ ngx_http_uwsgi_init_params(ngx_conf_t *c
                 + 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;
         }
@@ -1899,15 +1903,15 @@ ngx_http_uwsgi_init_params(ngx_conf_t *c
 
         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;
         }
@@ -1915,7 +1919,7 @@ ngx_http_uwsgi_init_params(ngx_conf_t *c
         *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;
         }
@@ -1923,16 +1927,16 @@ ngx_http_uwsgi_init_params(ngx_conf_t *c
         *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;