Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nginx/nginx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxim Dounin <mdounin@mdounin.ru>2011-11-14 17:26:18 +0400
committerMaxim Dounin <mdounin@mdounin.ru>2011-11-14 17:26:18 +0400
commit030523dff05c997bcba1ca421f7dcddd4575ded1 (patch)
treee58058c651156f2a94d2152fa110700af59d309c
parentca01f46103a8767496fe1c0dfc4cf88da51d01eb (diff)
Fixed fastcgi/scgi/uwsgi_param inheritance.
The following problems were fixed: 1. Directive fastcgi_cache affected headers sent to backends in unrelated servers / locations (see ticket #45). 2. If-Unmodified-Since, If-Match and If-Range headers were sent to backends if fastcgi_cache was used. 3. Cache-related headers were sent to backends if there were no fastcgi_param directives and fastcgi_cache was used at server level.
-rw-r--r--src/http/modules/ngx_http_fastcgi_module.c88
-rw-r--r--src/http/modules/ngx_http_scgi_module.c88
-rw-r--r--src/http/modules/ngx_http_uwsgi_module.c88
3 files changed, 174 insertions, 90 deletions
diff --git a/src/http/modules/ngx_http_fastcgi_module.c b/src/http/modules/ngx_http_fastcgi_module.c
index 77e45ea7d..2dc56c76b 100644
--- a/src/http/modules/ngx_http_fastcgi_module.c
+++ b/src/http/modules/ngx_http_fastcgi_module.c
@@ -2365,8 +2365,11 @@ ngx_http_fastcgi_merge_params(ngx_conf_t *cf,
u_char *p;
size_t size;
uintptr_t *code;
- ngx_uint_t i;
+ ngx_uint_t i, nsrc;
ngx_array_t headers_names;
+#if (NGX_HTTP_CACHE)
+ ngx_array_t params_merged;
+#endif
ngx_keyval_t *src;
ngx_hash_key_t *hk;
ngx_hash_init_t hash;
@@ -2374,36 +2377,32 @@ ngx_http_fastcgi_merge_params(ngx_conf_t *cf,
ngx_http_script_copy_code_t *copy;
if (conf->params_source == NULL) {
- conf->flushes = prev->flushes;
- conf->params_len = prev->params_len;
- conf->params = prev->params;
conf->params_source = prev->params_source;
- conf->headers_hash = prev->headers_hash;
+ 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;
- if (conf->params_source == NULL) {
-
- if ((conf->upstream.cache == NULL)
- == (prev->upstream.cache == NULL))
- {
- return NGX_OK;
- }
-
- /* 6 is a number of ngx_http_fastcgi_cache_headers entries */
- conf->params_source = ngx_array_create(cf->pool, 6,
- sizeof(ngx_keyval_t));
- if (conf->params_source == NULL) {
- return NGX_ERROR;
- }
- }
-#else
-
- if (conf->params_source == NULL) {
return NGX_OK;
}
+ }
+ if (conf->params_source == NULL
+#if (NGX_HTTP_CACHE)
+ && (conf->upstream.cache == NULL)
#endif
+ )
+ {
+ conf->headers_hash.buckets = (void *) 1;
+ return NGX_OK;
}
conf->params_len = ngx_array_create(cf->pool, 64, 1);
@@ -2422,39 +2421,68 @@ ngx_http_fastcgi_merge_params(ngx_conf_t *cf,
return NGX_ERROR;
}
- src = conf->params_source->elts;
+ if (conf->params_source) {
+ src = conf->params_source->elts;
+ nsrc = conf->params_source->nelts;
+
+ } else {
+ src = NULL;
+ nsrc = 0;
+ }
#if (NGX_HTTP_CACHE)
if (conf->upstream.cache) {
ngx_keyval_t *h, *s;
- for (h = ngx_http_fastcgi_cache_headers; h->key.len; h++) {
+ if (ngx_array_init(&params_merged, cf->temp_pool, 4, sizeof(ngx_keyval_t))
+ != NGX_OK)
+ {
+ return NGX_ERROR;
+ }
- for (i = 0; i < conf->params_source->nelts; i++) {
+ for (i = 0; i < nsrc; i++) {
+
+ s = ngx_array_push(&params_merged);
+ if (s == NULL) {
+ return NGX_ERROR;
+ }
+
+ *s = src[i];
+ }
+
+ h = ngx_http_fastcgi_cache_headers;
+
+ while (h->key.len) {
+
+ src = params_merged.elts;
+ nsrc = params_merged.nelts;
+
+ for (i = 0; i < nsrc; i++) {
if (ngx_strcasecmp(h->key.data, src[i].key.data) == 0) {
goto next;
}
}
- s = ngx_array_push(conf->params_source);
+ s = ngx_array_push(&params_merged);
if (s == NULL) {
return NGX_ERROR;
}
*s = *h;
- src = conf->params_source->elts;
-
next:
h++;
}
+
+ src = params_merged.elts;
+ nsrc = params_merged.nelts;
}
#endif
- for (i = 0; i < conf->params_source->nelts; i++) {
+ for (i = 0; i < nsrc; i++) {
if (src[i].key.len > sizeof("HTTP_") - 1
&& ngx_strncmp(src[i].key.data, "HTTP_", sizeof("HTTP_") - 1) == 0)
diff --git a/src/http/modules/ngx_http_scgi_module.c b/src/http/modules/ngx_http_scgi_module.c
index e815490f7..1feac713b 100644
--- a/src/http/modules/ngx_http_scgi_module.c
+++ b/src/http/modules/ngx_http_scgi_module.c
@@ -1316,8 +1316,11 @@ ngx_http_scgi_merge_params(ngx_conf_t *cf, ngx_http_scgi_loc_conf_t *conf,
u_char *p;
size_t size;
uintptr_t *code;
- ngx_uint_t i;
+ ngx_uint_t i, nsrc;
ngx_array_t headers_names;
+#if (NGX_HTTP_CACHE)
+ ngx_array_t params_merged;
+#endif
ngx_keyval_t *src;
ngx_hash_key_t *hk;
ngx_hash_init_t hash;
@@ -1325,36 +1328,32 @@ ngx_http_scgi_merge_params(ngx_conf_t *cf, ngx_http_scgi_loc_conf_t *conf,
ngx_http_script_copy_code_t *copy;
if (conf->params_source == NULL) {
- conf->flushes = prev->flushes;
- conf->params_len = prev->params_len;
- conf->params = prev->params;
conf->params_source = prev->params_source;
- conf->headers_hash = prev->headers_hash;
+ 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;
- if (conf->params_source == NULL) {
-
- if ((conf->upstream.cache == NULL)
- == (prev->upstream.cache == NULL))
- {
- return NGX_OK;
- }
-
- /* 6 is a number of ngx_http_scgi_cache_headers entries */
- conf->params_source = ngx_array_create(cf->pool, 6,
- sizeof(ngx_keyval_t));
- if (conf->params_source == NULL) {
- return NGX_ERROR;
- }
- }
-#else
-
- if (conf->params_source == NULL) {
return NGX_OK;
}
+ }
+ if (conf->params_source == NULL
+#if (NGX_HTTP_CACHE)
+ && (conf->upstream.cache == NULL)
#endif
+ )
+ {
+ conf->headers_hash.buckets = (void *) 1;
+ return NGX_OK;
}
conf->params_len = ngx_array_create(cf->pool, 64, 1);
@@ -1373,39 +1372,68 @@ ngx_http_scgi_merge_params(ngx_conf_t *cf, ngx_http_scgi_loc_conf_t *conf,
return NGX_ERROR;
}
- src = conf->params_source->elts;
+ if (conf->params_source) {
+ src = conf->params_source->elts;
+ nsrc = conf->params_source->nelts;
+
+ } else {
+ src = NULL;
+ nsrc = 0;
+ }
#if (NGX_HTTP_CACHE)
if (conf->upstream.cache) {
ngx_keyval_t *h, *s;
- for (h = ngx_http_scgi_cache_headers; h->key.len; h++) {
+ if (ngx_array_init(&params_merged, cf->temp_pool, 4, sizeof(ngx_keyval_t))
+ != NGX_OK)
+ {
+ return NGX_ERROR;
+ }
- for (i = 0; i < conf->params_source->nelts; i++) {
+ for (i = 0; i < nsrc; i++) {
+
+ s = ngx_array_push(&params_merged);
+ if (s == NULL) {
+ return NGX_ERROR;
+ }
+
+ *s = src[i];
+ }
+
+ h = ngx_http_scgi_cache_headers;
+
+ while (h->key.len) {
+
+ src = params_merged.elts;
+ nsrc = params_merged.nelts;
+
+ for (i = 0; i < nsrc; i++) {
if (ngx_strcasecmp(h->key.data, src[i].key.data) == 0) {
goto next;
}
}
- s = ngx_array_push(conf->params_source);
+ s = ngx_array_push(&params_merged);
if (s == NULL) {
return NGX_ERROR;
}
*s = *h;
- src = conf->params_source->elts;
-
next:
h++;
}
+
+ src = params_merged.elts;
+ nsrc = params_merged.nelts;
}
#endif
- for (i = 0; i < conf->params_source->nelts; i++) {
+ for (i = 0; i < nsrc; i++) {
if (src[i].key.len > sizeof("HTTP_") - 1
&& ngx_strncmp(src[i].key.data, "HTTP_", sizeof("HTTP_") - 1) == 0)
diff --git a/src/http/modules/ngx_http_uwsgi_module.c b/src/http/modules/ngx_http_uwsgi_module.c
index 70c314213..d60812932 100644
--- a/src/http/modules/ngx_http_uwsgi_module.c
+++ b/src/http/modules/ngx_http_uwsgi_module.c
@@ -1374,8 +1374,11 @@ ngx_http_uwsgi_merge_params(ngx_conf_t *cf, ngx_http_uwsgi_loc_conf_t *conf,
u_char *p;
size_t size;
uintptr_t *code;
- ngx_uint_t i;
+ ngx_uint_t i, nsrc;
ngx_array_t headers_names;
+#if (NGX_HTTP_CACHE)
+ ngx_array_t params_merged;
+#endif
ngx_keyval_t *src;
ngx_hash_key_t *hk;
ngx_hash_init_t hash;
@@ -1383,36 +1386,32 @@ ngx_http_uwsgi_merge_params(ngx_conf_t *cf, ngx_http_uwsgi_loc_conf_t *conf,
ngx_http_script_copy_code_t *copy;
if (conf->params_source == NULL) {
- conf->flushes = prev->flushes;
- conf->params_len = prev->params_len;
- conf->params = prev->params;
conf->params_source = prev->params_source;
- conf->headers_hash = prev->headers_hash;
+ 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;
- if (conf->params_source == NULL) {
-
- if ((conf->upstream.cache == NULL)
- == (prev->upstream.cache == NULL))
- {
- return NGX_OK;
- }
-
- /* 6 is a number of ngx_http_uwsgi_cache_headers entries */
- conf->params_source = ngx_array_create(cf->pool, 6,
- sizeof(ngx_keyval_t));
- if (conf->params_source == NULL) {
- return NGX_ERROR;
- }
- }
-#else
-
- if (conf->params_source == NULL) {
return NGX_OK;
}
+ }
+ if (conf->params_source == NULL
+#if (NGX_HTTP_CACHE)
+ && (conf->upstream.cache == NULL)
#endif
+ )
+ {
+ conf->headers_hash.buckets = (void *) 1;
+ return NGX_OK;
}
conf->params_len = ngx_array_create(cf->pool, 64, 1);
@@ -1431,39 +1430,68 @@ ngx_http_uwsgi_merge_params(ngx_conf_t *cf, ngx_http_uwsgi_loc_conf_t *conf,
return NGX_ERROR;
}
- src = conf->params_source->elts;
+ if (conf->params_source) {
+ src = conf->params_source->elts;
+ nsrc = conf->params_source->nelts;
+
+ } else {
+ src = NULL;
+ nsrc = 0;
+ }
#if (NGX_HTTP_CACHE)
if (conf->upstream.cache) {
ngx_keyval_t *h, *s;
- for (h = ngx_http_uwsgi_cache_headers; h->key.len; h++) {
+ if (ngx_array_init(&params_merged, cf->temp_pool, 4, sizeof(ngx_keyval_t))
+ != NGX_OK)
+ {
+ return NGX_ERROR;
+ }
- for (i = 0; i < conf->params_source->nelts; i++) {
+ for (i = 0; i < nsrc; i++) {
+
+ s = ngx_array_push(&params_merged);
+ if (s == NULL) {
+ return NGX_ERROR;
+ }
+
+ *s = src[i];
+ }
+
+ h = ngx_http_uwsgi_cache_headers;
+
+ while (h->key.len) {
+
+ src = params_merged.elts;
+ nsrc = params_merged.nelts;
+
+ for (i = 0; i < nsrc; i++) {
if (ngx_strcasecmp(h->key.data, src[i].key.data) == 0) {
goto next;
}
}
- s = ngx_array_push(conf->params_source);
+ s = ngx_array_push(&params_merged);
if (s == NULL) {
return NGX_ERROR;
}
*s = *h;
- src = conf->params_source->elts;
-
next:
h++;
}
+
+ src = params_merged.elts;
+ nsrc = params_merged.nelts;
}
#endif
- for (i = 0; i < conf->params_source->nelts; i++) {
+ for (i = 0; i < nsrc; i++) {
if (src[i].key.len > sizeof("HTTP_") - 1
&& ngx_strncmp(src[i].key.data, "HTTP_", sizeof("HTTP_") - 1) == 0)