[PATCH 5 of 5] Fixed fastcgi/scgi/uwsgi_param inheritance
Maxim Dounin
mdounin at mdounin.ru
Fri Nov 11 00:08:05 UTC 2011
# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1320965995 -10800
# Node ID 2bd4b516e87456f20d1ad85064348963a718db3a
# Parent 9512a3b65290db26bfc7b554e8b3ce8d13eb2458
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.
diff --git a/src/http/modules/ngx_http_fastcgi_module.c b/src/http/modules/ngx_http_fastcgi_module.c
--- 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
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
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)
-
- 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) {
+ && ((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->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
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++) {
-
- for (i = 0; i < conf->params_source->nelts; i++) {
+ if (ngx_array_init(¶ms_merged, cf->temp_pool, 4, sizeof(ngx_keyval_t))
+ != NGX_OK)
+ {
+ return NGX_ERROR;
+ }
+
+ for (i = 0; i < nsrc; i++) {
+
+ s = ngx_array_push(¶ms_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(¶ms_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
--- 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 *c
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 *c
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 *c
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(¶ms_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(¶ms_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(¶ms_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
--- 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 *
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 *
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 *
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(¶ms_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(¶ms_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(¶ms_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)
More information about the nginx-devel
mailing list