aboutsummaryrefslogtreecommitdiff
path: root/src/http/modules/ngx_http_fastcgi_module.c
diff options
context:
space:
mode:
authorValentin Bartenev <vbart@nginx.com>2014-12-22 12:59:09 +0300
committerValentin Bartenev <vbart@nginx.com>2014-12-22 12:59:09 +0300
commit7817df480eb4b3ddee56129b67b1fb697b367861 (patch)
treeffd87843e6c833adda02110cdb346f288df3b951 /src/http/modules/ngx_http_fastcgi_module.c
parentb24ad4200807ff7071987ea6bc86dd164c1a1ede (diff)
downloadnginx-7817df480eb4b3ddee56129b67b1fb697b367861.tar.gz
nginx-7817df480eb4b3ddee56129b67b1fb697b367861.zip
Upstream: added variables support to proxy_cache and friends.
Diffstat (limited to 'src/http/modules/ngx_http_fastcgi_module.c')
-rw-r--r--src/http/modules/ngx_http_fastcgi_module.c78
1 files changed, 70 insertions, 8 deletions
diff --git a/src/http/modules/ngx_http_fastcgi_module.c b/src/http/modules/ngx_http_fastcgi_module.c
index 39e9cd0aa..1bf4ac332 100644
--- a/src/http/modules/ngx_http_fastcgi_module.c
+++ b/src/http/modules/ngx_http_fastcgi_module.c
@@ -11,6 +11,11 @@
typedef struct {
+ ngx_array_t caches; /* ngx_http_file_cache_t * */
+} ngx_http_fastcgi_main_conf_t;
+
+
+typedef struct {
ngx_array_t *flushes;
ngx_array_t *lengths;
ngx_array_t *values;
@@ -155,6 +160,7 @@ static void ngx_http_fastcgi_finalize_request(ngx_http_request_t *r,
ngx_int_t rc);
static ngx_int_t ngx_http_fastcgi_add_variables(ngx_conf_t *cf);
+static void *ngx_http_fastcgi_create_main_conf(ngx_conf_t *cf);
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);
@@ -368,8 +374,8 @@ static ngx_command_t ngx_http_fastcgi_commands[] = {
{ ngx_string("fastcgi_cache_path"),
NGX_HTTP_MAIN_CONF|NGX_CONF_2MORE,
ngx_http_file_cache_set_slot,
- 0,
- 0,
+ NGX_HTTP_MAIN_CONF_OFFSET,
+ offsetof(ngx_http_fastcgi_main_conf_t, caches),
&ngx_http_fastcgi_module },
{ ngx_string("fastcgi_cache_bypass"),
@@ -536,7 +542,7 @@ static ngx_http_module_t ngx_http_fastcgi_module_ctx = {
ngx_http_fastcgi_add_variables, /* preconfiguration */
NULL, /* postconfiguration */
- NULL, /* create main configuration */
+ ngx_http_fastcgi_create_main_conf, /* create main configuration */
NULL, /* init main configuration */
NULL, /* create server configuration */
@@ -635,10 +641,13 @@ static ngx_path_init_t ngx_http_fastcgi_temp_path = {
static ngx_int_t
ngx_http_fastcgi_handler(ngx_http_request_t *r)
{
- ngx_int_t rc;
- ngx_http_upstream_t *u;
- ngx_http_fastcgi_ctx_t *f;
- ngx_http_fastcgi_loc_conf_t *flcf;
+ ngx_int_t rc;
+ ngx_http_upstream_t *u;
+ ngx_http_fastcgi_ctx_t *f;
+ ngx_http_fastcgi_loc_conf_t *flcf;
+#if (NGX_HTTP_CACHE)
+ ngx_http_fastcgi_main_conf_t *fmcf;
+#endif
if (ngx_http_upstream_create(r) != NGX_OK) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
@@ -667,8 +676,12 @@ ngx_http_fastcgi_handler(ngx_http_request_t *r)
u->conf = &flcf->upstream;
#if (NGX_HTTP_CACHE)
+ fmcf = ngx_http_get_module_main_conf(r, ngx_http_fastcgi_module);
+
+ u->caches = &fmcf->caches;
u->create_key = ngx_http_fastcgi_create_key;
#endif
+
u->create_request = ngx_http_fastcgi_create_request;
u->reinit_request = ngx_http_fastcgi_reinit_request;
u->process_header = ngx_http_fastcgi_process_header;
@@ -2337,6 +2350,29 @@ ngx_http_fastcgi_add_variables(ngx_conf_t *cf)
static void *
+ngx_http_fastcgi_create_main_conf(ngx_conf_t *cf)
+{
+ ngx_http_fastcgi_main_conf_t *conf;
+
+ conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_fastcgi_main_conf_t));
+ if (conf == NULL) {
+ return NULL;
+ }
+
+#if (NGX_HTTP_CACHE)
+ if (ngx_array_init(&conf->caches, cf->pool, 4,
+ sizeof(ngx_http_file_cache_t *))
+ != NGX_OK)
+ {
+ return NULL;
+ }
+#endif
+
+ return conf;
+}
+
+
+static void *
ngx_http_fastcgi_create_loc_conf(ngx_conf_t *cf)
{
ngx_http_fastcgi_loc_conf_t *conf;
@@ -2617,6 +2653,7 @@ ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
prev->upstream.cache, 0);
conf->upstream.cache_zone = prev->upstream.cache_zone;
+ conf->upstream.cache_value = prev->upstream.cache_value;
}
if (conf->upstream.cache_zone && conf->upstream.cache_zone->data == NULL) {
@@ -3272,7 +3309,9 @@ ngx_http_fastcgi_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_http_fastcgi_loc_conf_t *flcf = conf;
- ngx_str_t *value;
+ ngx_str_t *value;
+ ngx_http_complex_value_t cv;
+ ngx_http_compile_complex_value_t ccv;
value = cf->args->elts;
@@ -3291,6 +3330,29 @@ ngx_http_fastcgi_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
flcf->upstream.cache = 1;
+ ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
+
+ ccv.cf = cf;
+ ccv.value = &value[1];
+ ccv.complex_value = &cv;
+
+ if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
+ return NGX_CONF_ERROR;
+ }
+
+ if (cv.lengths != NULL) {
+
+ flcf->upstream.cache_value = ngx_palloc(cf->pool,
+ sizeof(ngx_http_complex_value_t));
+ if (flcf->upstream.cache_value == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
+ *flcf->upstream.cache_value = cv;
+
+ return NGX_CONF_OK;
+ }
+
flcf->upstream.cache_zone = ngx_shared_memory_add(cf, &value[1], 0,
&ngx_http_fastcgi_module);
if (flcf->upstream.cache_zone == NULL) {