Mercurial > hg > nginx
comparison src/http/modules/ngx_http_fastcgi_module.c @ 5951:610832763648
Upstream: added variables support to proxy_cache and friends.
author | Valentin Bartenev <vbart@nginx.com> |
---|---|
date | Mon, 22 Dec 2014 12:59:09 +0300 |
parents | 634da79665d3 |
children | 8ad78808a612 |
comparison
equal
deleted
inserted
replaced
5950:eaeecf00d5d7 | 5951:610832763648 |
---|---|
6 | 6 |
7 | 7 |
8 #include <ngx_config.h> | 8 #include <ngx_config.h> |
9 #include <ngx_core.h> | 9 #include <ngx_core.h> |
10 #include <ngx_http.h> | 10 #include <ngx_http.h> |
11 | |
12 | |
13 typedef struct { | |
14 ngx_array_t caches; /* ngx_http_file_cache_t * */ | |
15 } ngx_http_fastcgi_main_conf_t; | |
11 | 16 |
12 | 17 |
13 typedef struct { | 18 typedef struct { |
14 ngx_array_t *flushes; | 19 ngx_array_t *flushes; |
15 ngx_array_t *lengths; | 20 ngx_array_t *lengths; |
153 static void ngx_http_fastcgi_abort_request(ngx_http_request_t *r); | 158 static void ngx_http_fastcgi_abort_request(ngx_http_request_t *r); |
154 static void ngx_http_fastcgi_finalize_request(ngx_http_request_t *r, | 159 static void ngx_http_fastcgi_finalize_request(ngx_http_request_t *r, |
155 ngx_int_t rc); | 160 ngx_int_t rc); |
156 | 161 |
157 static ngx_int_t ngx_http_fastcgi_add_variables(ngx_conf_t *cf); | 162 static ngx_int_t ngx_http_fastcgi_add_variables(ngx_conf_t *cf); |
163 static void *ngx_http_fastcgi_create_main_conf(ngx_conf_t *cf); | |
158 static void *ngx_http_fastcgi_create_loc_conf(ngx_conf_t *cf); | 164 static void *ngx_http_fastcgi_create_loc_conf(ngx_conf_t *cf); |
159 static char *ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf, | 165 static char *ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf, |
160 void *parent, void *child); | 166 void *parent, void *child); |
161 static ngx_int_t ngx_http_fastcgi_init_params(ngx_conf_t *cf, | 167 static ngx_int_t ngx_http_fastcgi_init_params(ngx_conf_t *cf, |
162 ngx_http_fastcgi_loc_conf_t *conf, ngx_http_fastcgi_params_t *params, | 168 ngx_http_fastcgi_loc_conf_t *conf, ngx_http_fastcgi_params_t *params, |
366 NULL }, | 372 NULL }, |
367 | 373 |
368 { ngx_string("fastcgi_cache_path"), | 374 { ngx_string("fastcgi_cache_path"), |
369 NGX_HTTP_MAIN_CONF|NGX_CONF_2MORE, | 375 NGX_HTTP_MAIN_CONF|NGX_CONF_2MORE, |
370 ngx_http_file_cache_set_slot, | 376 ngx_http_file_cache_set_slot, |
371 0, | 377 NGX_HTTP_MAIN_CONF_OFFSET, |
372 0, | 378 offsetof(ngx_http_fastcgi_main_conf_t, caches), |
373 &ngx_http_fastcgi_module }, | 379 &ngx_http_fastcgi_module }, |
374 | 380 |
375 { ngx_string("fastcgi_cache_bypass"), | 381 { ngx_string("fastcgi_cache_bypass"), |
376 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE, | 382 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE, |
377 ngx_http_set_predicate_slot, | 383 ngx_http_set_predicate_slot, |
534 | 540 |
535 static ngx_http_module_t ngx_http_fastcgi_module_ctx = { | 541 static ngx_http_module_t ngx_http_fastcgi_module_ctx = { |
536 ngx_http_fastcgi_add_variables, /* preconfiguration */ | 542 ngx_http_fastcgi_add_variables, /* preconfiguration */ |
537 NULL, /* postconfiguration */ | 543 NULL, /* postconfiguration */ |
538 | 544 |
539 NULL, /* create main configuration */ | 545 ngx_http_fastcgi_create_main_conf, /* create main configuration */ |
540 NULL, /* init main configuration */ | 546 NULL, /* init main configuration */ |
541 | 547 |
542 NULL, /* create server configuration */ | 548 NULL, /* create server configuration */ |
543 NULL, /* merge server configuration */ | 549 NULL, /* merge server configuration */ |
544 | 550 |
633 | 639 |
634 | 640 |
635 static ngx_int_t | 641 static ngx_int_t |
636 ngx_http_fastcgi_handler(ngx_http_request_t *r) | 642 ngx_http_fastcgi_handler(ngx_http_request_t *r) |
637 { | 643 { |
638 ngx_int_t rc; | 644 ngx_int_t rc; |
639 ngx_http_upstream_t *u; | 645 ngx_http_upstream_t *u; |
640 ngx_http_fastcgi_ctx_t *f; | 646 ngx_http_fastcgi_ctx_t *f; |
641 ngx_http_fastcgi_loc_conf_t *flcf; | 647 ngx_http_fastcgi_loc_conf_t *flcf; |
648 #if (NGX_HTTP_CACHE) | |
649 ngx_http_fastcgi_main_conf_t *fmcf; | |
650 #endif | |
642 | 651 |
643 if (ngx_http_upstream_create(r) != NGX_OK) { | 652 if (ngx_http_upstream_create(r) != NGX_OK) { |
644 return NGX_HTTP_INTERNAL_SERVER_ERROR; | 653 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
645 } | 654 } |
646 | 655 |
665 u->output.tag = (ngx_buf_tag_t) &ngx_http_fastcgi_module; | 674 u->output.tag = (ngx_buf_tag_t) &ngx_http_fastcgi_module; |
666 | 675 |
667 u->conf = &flcf->upstream; | 676 u->conf = &flcf->upstream; |
668 | 677 |
669 #if (NGX_HTTP_CACHE) | 678 #if (NGX_HTTP_CACHE) |
679 fmcf = ngx_http_get_module_main_conf(r, ngx_http_fastcgi_module); | |
680 | |
681 u->caches = &fmcf->caches; | |
670 u->create_key = ngx_http_fastcgi_create_key; | 682 u->create_key = ngx_http_fastcgi_create_key; |
671 #endif | 683 #endif |
684 | |
672 u->create_request = ngx_http_fastcgi_create_request; | 685 u->create_request = ngx_http_fastcgi_create_request; |
673 u->reinit_request = ngx_http_fastcgi_reinit_request; | 686 u->reinit_request = ngx_http_fastcgi_reinit_request; |
674 u->process_header = ngx_http_fastcgi_process_header; | 687 u->process_header = ngx_http_fastcgi_process_header; |
675 u->abort_request = ngx_http_fastcgi_abort_request; | 688 u->abort_request = ngx_http_fastcgi_abort_request; |
676 u->finalize_request = ngx_http_fastcgi_finalize_request; | 689 u->finalize_request = ngx_http_fastcgi_finalize_request; |
2335 return NGX_OK; | 2348 return NGX_OK; |
2336 } | 2349 } |
2337 | 2350 |
2338 | 2351 |
2339 static void * | 2352 static void * |
2353 ngx_http_fastcgi_create_main_conf(ngx_conf_t *cf) | |
2354 { | |
2355 ngx_http_fastcgi_main_conf_t *conf; | |
2356 | |
2357 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_fastcgi_main_conf_t)); | |
2358 if (conf == NULL) { | |
2359 return NULL; | |
2360 } | |
2361 | |
2362 #if (NGX_HTTP_CACHE) | |
2363 if (ngx_array_init(&conf->caches, cf->pool, 4, | |
2364 sizeof(ngx_http_file_cache_t *)) | |
2365 != NGX_OK) | |
2366 { | |
2367 return NULL; | |
2368 } | |
2369 #endif | |
2370 | |
2371 return conf; | |
2372 } | |
2373 | |
2374 | |
2375 static void * | |
2340 ngx_http_fastcgi_create_loc_conf(ngx_conf_t *cf) | 2376 ngx_http_fastcgi_create_loc_conf(ngx_conf_t *cf) |
2341 { | 2377 { |
2342 ngx_http_fastcgi_loc_conf_t *conf; | 2378 ngx_http_fastcgi_loc_conf_t *conf; |
2343 | 2379 |
2344 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_fastcgi_loc_conf_t)); | 2380 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_fastcgi_loc_conf_t)); |
2615 if (conf->upstream.cache == NGX_CONF_UNSET) { | 2651 if (conf->upstream.cache == NGX_CONF_UNSET) { |
2616 ngx_conf_merge_value(conf->upstream.cache, | 2652 ngx_conf_merge_value(conf->upstream.cache, |
2617 prev->upstream.cache, 0); | 2653 prev->upstream.cache, 0); |
2618 | 2654 |
2619 conf->upstream.cache_zone = prev->upstream.cache_zone; | 2655 conf->upstream.cache_zone = prev->upstream.cache_zone; |
2656 conf->upstream.cache_value = prev->upstream.cache_value; | |
2620 } | 2657 } |
2621 | 2658 |
2622 if (conf->upstream.cache_zone && conf->upstream.cache_zone->data == NULL) { | 2659 if (conf->upstream.cache_zone && conf->upstream.cache_zone->data == NULL) { |
2623 ngx_shm_zone_t *shm_zone; | 2660 ngx_shm_zone_t *shm_zone; |
2624 | 2661 |
3270 static char * | 3307 static char * |
3271 ngx_http_fastcgi_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 3308 ngx_http_fastcgi_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
3272 { | 3309 { |
3273 ngx_http_fastcgi_loc_conf_t *flcf = conf; | 3310 ngx_http_fastcgi_loc_conf_t *flcf = conf; |
3274 | 3311 |
3275 ngx_str_t *value; | 3312 ngx_str_t *value; |
3313 ngx_http_complex_value_t cv; | |
3314 ngx_http_compile_complex_value_t ccv; | |
3276 | 3315 |
3277 value = cf->args->elts; | 3316 value = cf->args->elts; |
3278 | 3317 |
3279 if (flcf->upstream.cache != NGX_CONF_UNSET) { | 3318 if (flcf->upstream.cache != NGX_CONF_UNSET) { |
3280 return "is duplicate"; | 3319 return "is duplicate"; |
3288 if (flcf->upstream.store > 0) { | 3327 if (flcf->upstream.store > 0) { |
3289 return "is incompatible with \"fastcgi_store\""; | 3328 return "is incompatible with \"fastcgi_store\""; |
3290 } | 3329 } |
3291 | 3330 |
3292 flcf->upstream.cache = 1; | 3331 flcf->upstream.cache = 1; |
3332 | |
3333 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t)); | |
3334 | |
3335 ccv.cf = cf; | |
3336 ccv.value = &value[1]; | |
3337 ccv.complex_value = &cv; | |
3338 | |
3339 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) { | |
3340 return NGX_CONF_ERROR; | |
3341 } | |
3342 | |
3343 if (cv.lengths != NULL) { | |
3344 | |
3345 flcf->upstream.cache_value = ngx_palloc(cf->pool, | |
3346 sizeof(ngx_http_complex_value_t)); | |
3347 if (flcf->upstream.cache_value == NULL) { | |
3348 return NGX_CONF_ERROR; | |
3349 } | |
3350 | |
3351 *flcf->upstream.cache_value = cv; | |
3352 | |
3353 return NGX_CONF_OK; | |
3354 } | |
3293 | 3355 |
3294 flcf->upstream.cache_zone = ngx_shared_memory_add(cf, &value[1], 0, | 3356 flcf->upstream.cache_zone = ngx_shared_memory_add(cf, &value[1], 0, |
3295 &ngx_http_fastcgi_module); | 3357 &ngx_http_fastcgi_module); |
3296 if (flcf->upstream.cache_zone == NULL) { | 3358 if (flcf->upstream.cache_zone == NULL) { |
3297 return NGX_CONF_ERROR; | 3359 return NGX_CONF_ERROR; |