diff src/http/modules/ngx_http_scgi_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_scgi_module.c
+++ b/src/http/modules/ngx_http_scgi_module.c
@@ -12,16 +12,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_scgi_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_scgi_params_t     params;
     ngx_array_t               *params_source;
 
-    ngx_hash_t                 headers_hash;
-    ngx_uint_t                 header_params;
-
     ngx_array_t               *scgi_lengths;
     ngx_array_t               *scgi_values;
 
@@ -44,7 +48,7 @@ static void *ngx_http_scgi_create_loc_co
 static char *ngx_http_scgi_merge_loc_conf(ngx_conf_t *cf, void *parent,
     void *child);
 static ngx_int_t ngx_http_scgi_init_params(ngx_conf_t *cf,
-    ngx_http_scgi_loc_conf_t *conf);
+    ngx_http_scgi_loc_conf_t *conf, ngx_http_scgi_params_t *params);
 
 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,
@@ -579,6 +583,7 @@ ngx_http_scgi_create_request(ngx_http_re
     ngx_chain_t                  *cl, *body;
     ngx_list_part_t              *part;
     ngx_table_elt_t              *header, **ignored;
+    ngx_http_scgi_params_t       *params;
     ngx_http_script_code_pt       code;
     ngx_http_script_engine_t      e, le;
     ngx_http_scgi_loc_conf_t     *scf;
@@ -603,13 +608,15 @@ ngx_http_scgi_create_request(ngx_http_re
 
     scf = ngx_http_get_module_loc_conf(r, ngx_http_scgi_module);
 
-    if (scf->params_len) {
+    params = &scf->params;
+
+    if (params->lengths) {
         ngx_memzero(&le, sizeof(ngx_http_script_engine_t));
 
-        ngx_http_script_flush_no_cacheable_variables(r, scf->flushes);
+        ngx_http_script_flush_no_cacheable_variables(r, params->flushes);
         le.flushed = 1;
 
-        le.ip = scf->params_len->elts;
+        le.ip = params->lengths->elts;
         le.request = r;
 
         while (*(uintptr_t *) le.ip) {
@@ -638,7 +645,7 @@ ngx_http_scgi_create_request(ngx_http_re
         allocated = 0;
         lowcase_key = NULL;
 
-        if (scf->header_params) {
+        if (params->number) {
             n = 0;
             part = &r->headers_in.headers.part;
 
@@ -668,7 +675,7 @@ ngx_http_scgi_create_request(ngx_http_re
                 i = 0;
             }
 
-            if (scf->header_params) {
+            if (params->number) {
                 if (allocated < header[i].key.len) {
                     allocated = header[i].key.len + 16;
                     lowcase_key = ngx_pnalloc(r->pool, allocated);
@@ -693,7 +700,7 @@ ngx_http_scgi_create_request(ngx_http_re
                     lowcase_key[n] = ch;
                 }
 
-                if (ngx_hash_find(&scf->headers_hash, hash, lowcase_key, n)) {
+                if (ngx_hash_find(&params->hash, hash, lowcase_key, n)) {
                     ignored[header_params++] = &header[i];
                     continue;
                 }
@@ -721,15 +728,15 @@ ngx_http_scgi_create_request(ngx_http_re
     b->last = ngx_sprintf(b->last, "%ui:CONTENT_LENGTH%Z%V%Z",
                           len, &content_length);
 
-    if (scf->params_len) {
+    if (params->lengths) {
         ngx_memzero(&e, sizeof(ngx_http_script_engine_t));
 
-        e.ip = scf->params->elts;
+        e.ip = params->values->elts;
         e.pos = b->last;
         e.request = r;
         e.flushed = 1;
 
-        le.ip = scf->params_len->elts;
+        le.ip = params->lengths->elts;
 
         while (*(uintptr_t *) le.ip) {
 
@@ -1450,15 +1457,11 @@ ngx_http_scgi_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_scgi_init_params(cf, conf) != NGX_OK) {
+    if (ngx_http_scgi_init_params(cf, conf, &conf->params) != NGX_OK) {
         return NGX_CONF_ERROR;
     }
 
@@ -1467,7 +1470,8 @@ ngx_http_scgi_merge_loc_conf(ngx_conf_t 
 
 
 static ngx_int_t
-ngx_http_scgi_init_params(ngx_conf_t *cf, ngx_http_scgi_loc_conf_t *conf)
+ngx_http_scgi_init_params(ngx_conf_t *cf, ngx_http_scgi_loc_conf_t *conf,
+    ngx_http_scgi_params_t *params)
 {
     u_char                       *p;
     size_t                        size;
@@ -1483,7 +1487,7 @@ ngx_http_scgi_init_params(ngx_conf_t *cf
     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;
     }
 
@@ -1493,17 +1497,17 @@ ngx_http_scgi_init_params(ngx_conf_t *cf
 #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;
     }
 
@@ -1598,7 +1602,7 @@ ngx_http_scgi_init_params(ngx_conf_t *cf
             }
         }
 
-        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;
@@ -1607,7 +1611,7 @@ ngx_http_scgi_init_params(ngx_conf_t *cf
         copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code;
         copy->len = src[i].key.len + 1;
 
-        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;
@@ -1621,7 +1625,7 @@ ngx_http_scgi_init_params(ngx_conf_t *cf
                 + src[i].key.len + 1 + 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;
         }
@@ -1637,15 +1641,15 @@ ngx_http_scgi_init_params(ngx_conf_t *cf
 
         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;
         }
@@ -1653,7 +1657,7 @@ ngx_http_scgi_init_params(ngx_conf_t *cf
         *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;
         }
@@ -1661,16 +1665,16 @@ ngx_http_scgi_init_params(ngx_conf_t *cf
         *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;
+    params->number = headers_names.nelts;
 
-    hash.hash = &conf->headers_hash;
+    hash.hash = &params->hash;
     hash.key = ngx_hash_key_lc;
     hash.max_size = 512;
     hash.bucket_size = 64;