aboutsummaryrefslogtreecommitdiff
path: root/src/http/modules/ngx_http_fastcgi_module.c
diff options
context:
space:
mode:
authorRoman Arutyunyan <arut@nginx.com>2014-11-19 17:33:23 +0300
committerRoman Arutyunyan <arut@nginx.com>2014-11-19 17:33:23 +0300
commit8898c97dbd493d1e8adcfaacdd6d19e8b471c2d3 (patch)
tree277572925380ec1e1ff31daf2ab1a2df9e032c4f /src/http/modules/ngx_http_fastcgi_module.c
parentbcf6b11a347303960003970614d1556c73bde4ae (diff)
downloadnginx-8898c97dbd493d1e8adcfaacdd6d19e8b471c2d3.tar.gz
nginx-8898c97dbd493d1e8adcfaacdd6d19e8b471c2d3.zip
Upstream: different header lists for cached and uncached requests.
The upstream modules remove and alter a number of client headers before sending the request to upstream. This set of headers is smaller or even empty when cache is disabled. It's still possible that a request in a cache-enabled location is uncached, for example, if cache entry counter is below min_uses. In this case it's better to alter a smaller set of headers and pass more client headers to backend unchanged. One of the benefits is enabling server-side byte ranges in such requests.
Diffstat (limited to 'src/http/modules/ngx_http_fastcgi_module.c')
-rw-r--r--src/http/modules/ngx_http_fastcgi_module.c63
1 files changed, 34 insertions, 29 deletions
diff --git a/src/http/modules/ngx_http_fastcgi_module.c b/src/http/modules/ngx_http_fastcgi_module.c
index 1e0043175..cc93570b1 100644
--- a/src/http/modules/ngx_http_fastcgi_module.c
+++ b/src/http/modules/ngx_http_fastcgi_module.c
@@ -25,6 +25,9 @@ typedef struct {
ngx_str_t index;
ngx_http_fastcgi_params_t params;
+#if (NGX_HTTP_CACHE)
+ ngx_http_fastcgi_params_t params_cache;
+#endif
ngx_array_t *params_source;
ngx_array_t *catch_stderr;
@@ -156,7 +159,8 @@ static void *ngx_http_fastcgi_create_loc_conf(ngx_conf_t *cf);
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_params_t *params);
+ ngx_http_fastcgi_loc_conf_t *conf, ngx_http_fastcgi_params_t *params,
+ ngx_keyval_t *default_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);
@@ -795,7 +799,11 @@ ngx_http_fastcgi_create_request(ngx_http_request_t *r)
flcf = ngx_http_get_module_loc_conf(r, ngx_http_fastcgi_module);
+#if (NGX_HTTP_CACHE)
+ params = r->upstream->cacheable ? &flcf->params_cache : &flcf->params;
+#else
params = &flcf->params;
+#endif
if (params->lengths) {
ngx_memzero(&le, sizeof(ngx_http_script_engine_t));
@@ -2420,6 +2428,7 @@ ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
ngx_http_fastcgi_loc_conf_t *conf = child;
size_t size;
+ ngx_int_t rc;
ngx_hash_init_t hash;
ngx_http_core_loc_conf_t *clcf;
@@ -2712,39 +2721,47 @@ ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
#endif
if (conf->params_source == NULL) {
- conf->params_source = prev->params_source;
-
+ conf->params = prev->params;
#if (NGX_HTTP_CACHE)
- if ((conf->upstream.cache == NULL) == (prev->upstream.cache == NULL))
+ conf->params_cache = prev->params_cache;
#endif
- {
- conf->params = prev->params;
- }
+ conf->params_source = prev->params_source;
}
- if (ngx_http_fastcgi_init_params(cf, conf, &conf->params) != NGX_OK) {
+ rc = ngx_http_fastcgi_init_params(cf, conf, &conf->params, NULL);
+ if (rc != NGX_OK) {
return NGX_CONF_ERROR;
}
+#if (NGX_HTTP_CACHE)
+
+ if (conf->upstream.cache) {
+ rc = ngx_http_fastcgi_init_params(cf, conf, &conf->params_cache,
+ ngx_http_fastcgi_cache_headers);
+ if (rc != NGX_OK) {
+ return NGX_CONF_ERROR;
+ }
+ }
+
+#endif
+
return NGX_CONF_OK;
}
static ngx_int_t
ngx_http_fastcgi_init_params(ngx_conf_t *cf, ngx_http_fastcgi_loc_conf_t *conf,
- ngx_http_fastcgi_params_t *params)
+ ngx_http_fastcgi_params_t *params, ngx_keyval_t *default_params)
{
u_char *p;
size_t size;
uintptr_t *code;
ngx_uint_t i, nsrc;
- ngx_array_t headers_names;
-#if (NGX_HTTP_CACHE)
- ngx_array_t params_merged;
-#endif
+ ngx_array_t headers_names, params_merged;
+ ngx_keyval_t *h;
ngx_hash_key_t *hk;
ngx_hash_init_t hash;
- ngx_http_upstream_param_t *src;
+ ngx_http_upstream_param_t *src, *s;
ngx_http_script_compile_t sc;
ngx_http_script_copy_code_t *copy;
@@ -2752,12 +2769,7 @@ ngx_http_fastcgi_init_params(ngx_conf_t *cf, ngx_http_fastcgi_loc_conf_t *conf,
return NGX_OK;
}
- if (conf->params_source == NULL
-#if (NGX_HTTP_CACHE)
- && (conf->upstream.cache == NULL)
-#endif
- )
- {
+ if (conf->params_source == NULL && default_params == NULL) {
params->hash.buckets = (void *) 1;
return NGX_OK;
}
@@ -2787,12 +2799,7 @@ ngx_http_fastcgi_init_params(ngx_conf_t *cf, ngx_http_fastcgi_loc_conf_t *conf,
nsrc = 0;
}
-#if (NGX_HTTP_CACHE)
-
- if (conf->upstream.cache) {
- ngx_keyval_t *h;
- ngx_http_upstream_param_t *s;
-
+ if (default_params) {
if (ngx_array_init(&params_merged, cf->temp_pool, 4,
sizeof(ngx_http_upstream_param_t))
!= NGX_OK)
@@ -2810,7 +2817,7 @@ ngx_http_fastcgi_init_params(ngx_conf_t *cf, ngx_http_fastcgi_loc_conf_t *conf,
*s = src[i];
}
- h = ngx_http_fastcgi_cache_headers;
+ h = default_params;
while (h->key.len) {
@@ -2841,8 +2848,6 @@ ngx_http_fastcgi_init_params(ngx_conf_t *cf, ngx_http_fastcgi_loc_conf_t *conf,
nsrc = params_merged.nelts;
}
-#endif
-
for (i = 0; i < nsrc; i++) {
if (src[i].key.len > sizeof("HTTP_") - 1