comparison src/http/modules/ngx_http_proxy_module.c @ 5949:634da79665d3

Upstream: refactored proxy_cache and friends. The configuration handling code has changed to look similar to the proxy_store directive and friends. This simplifies adding variable support in the following patch. No functional changes.
author Valentin Bartenev <vbart@nginx.com>
date Mon, 22 Dec 2014 12:59:02 +0300
parents f2ff0aa89126
children 610832763648
comparison
equal deleted inserted replaced
5948:f2ff0aa89126 5949:634da79665d3
2507 * set by ngx_pcalloc(): 2507 * set by ngx_pcalloc():
2508 * 2508 *
2509 * conf->upstream.bufs.num = 0; 2509 * conf->upstream.bufs.num = 0;
2510 * conf->upstream.ignore_headers = 0; 2510 * conf->upstream.ignore_headers = 0;
2511 * conf->upstream.next_upstream = 0; 2511 * conf->upstream.next_upstream = 0;
2512 * conf->upstream.cache_zone = NULL;
2512 * conf->upstream.cache_use_stale = 0; 2513 * conf->upstream.cache_use_stale = 0;
2513 * conf->upstream.cache_methods = 0; 2514 * conf->upstream.cache_methods = 0;
2514 * conf->upstream.temp_path = NULL; 2515 * conf->upstream.temp_path = NULL;
2515 * conf->upstream.hide_headers_hash = { NULL, 0 }; 2516 * conf->upstream.hide_headers_hash = { NULL, 0 };
2516 * conf->upstream.uri = { 0, NULL }; 2517 * conf->upstream.uri = { 0, NULL };
2564 2565
2565 conf->upstream.pass_request_headers = NGX_CONF_UNSET; 2566 conf->upstream.pass_request_headers = NGX_CONF_UNSET;
2566 conf->upstream.pass_request_body = NGX_CONF_UNSET; 2567 conf->upstream.pass_request_body = NGX_CONF_UNSET;
2567 2568
2568 #if (NGX_HTTP_CACHE) 2569 #if (NGX_HTTP_CACHE)
2569 conf->upstream.cache = NGX_CONF_UNSET_PTR; 2570 conf->upstream.cache = NGX_CONF_UNSET;
2570 conf->upstream.cache_min_uses = NGX_CONF_UNSET_UINT; 2571 conf->upstream.cache_min_uses = NGX_CONF_UNSET_UINT;
2571 conf->upstream.cache_bypass = NGX_CONF_UNSET_PTR; 2572 conf->upstream.cache_bypass = NGX_CONF_UNSET_PTR;
2572 conf->upstream.no_cache = NGX_CONF_UNSET_PTR; 2573 conf->upstream.no_cache = NGX_CONF_UNSET_PTR;
2573 conf->upstream.cache_valid = NGX_CONF_UNSET_PTR; 2574 conf->upstream.cache_valid = NGX_CONF_UNSET_PTR;
2574 conf->upstream.cache_lock = NGX_CONF_UNSET; 2575 conf->upstream.cache_lock = NGX_CONF_UNSET;
2625 ngx_http_script_compile_t sc; 2626 ngx_http_script_compile_t sc;
2626 2627
2627 #if (NGX_HTTP_CACHE) 2628 #if (NGX_HTTP_CACHE)
2628 2629
2629 if (conf->upstream.store > 0) { 2630 if (conf->upstream.store > 0) {
2630 conf->upstream.cache = NULL; 2631 conf->upstream.cache = 0;
2631 } 2632 }
2632 2633
2633 if (conf->upstream.cache != NGX_CONF_UNSET_PTR 2634 if (conf->upstream.cache > 0) {
2634 && conf->upstream.cache != NULL)
2635 {
2636 conf->upstream.store = 0; 2635 conf->upstream.store = 0;
2637 } 2636 }
2638 2637
2639 #endif 2638 #endif
2640 2639
2802 } 2801 }
2803 2802
2804 2803
2805 #if (NGX_HTTP_CACHE) 2804 #if (NGX_HTTP_CACHE)
2806 2805
2807 ngx_conf_merge_ptr_value(conf->upstream.cache, 2806 if (conf->upstream.cache == NGX_CONF_UNSET) {
2808 prev->upstream.cache, NULL); 2807 ngx_conf_merge_value(conf->upstream.cache,
2809 2808 prev->upstream.cache, 0);
2810 if (conf->upstream.cache && conf->upstream.cache->data == NULL) { 2809
2810 conf->upstream.cache_zone = prev->upstream.cache_zone;
2811 }
2812
2813 if (conf->upstream.cache_zone && conf->upstream.cache_zone->data == NULL) {
2811 ngx_shm_zone_t *shm_zone; 2814 ngx_shm_zone_t *shm_zone;
2812 2815
2813 shm_zone = conf->upstream.cache; 2816 shm_zone = conf->upstream.cache_zone;
2814 2817
2815 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, 2818 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2816 "\"proxy_cache\" zone \"%V\" is unknown", 2819 "\"proxy_cache\" zone \"%V\" is unknown",
2817 &shm_zone->shm.name); 2820 &shm_zone->shm.name);
2818 2821
3816 plcf->upstream.store = 0; 3819 plcf->upstream.store = 0;
3817 return NGX_CONF_OK; 3820 return NGX_CONF_OK;
3818 } 3821 }
3819 3822
3820 #if (NGX_HTTP_CACHE) 3823 #if (NGX_HTTP_CACHE)
3821 3824 if (plcf->upstream.cache > 0) {
3822 if (plcf->upstream.cache != NGX_CONF_UNSET_PTR
3823 && plcf->upstream.cache != NULL)
3824 {
3825 return "is incompatible with \"proxy_cache\""; 3825 return "is incompatible with \"proxy_cache\"";
3826 } 3826 }
3827
3828 #endif 3827 #endif
3829 3828
3830 plcf->upstream.store = 1; 3829 plcf->upstream.store = 1;
3831 3830
3832 if (ngx_strcmp(value[1].data, "on") == 0) { 3831 if (ngx_strcmp(value[1].data, "on") == 0) {
3863 3862
3864 ngx_str_t *value; 3863 ngx_str_t *value;
3865 3864
3866 value = cf->args->elts; 3865 value = cf->args->elts;
3867 3866
3868 if (plcf->upstream.cache != NGX_CONF_UNSET_PTR) { 3867 if (plcf->upstream.cache != NGX_CONF_UNSET) {
3869 return "is duplicate"; 3868 return "is duplicate";
3870 } 3869 }
3871 3870
3872 if (ngx_strcmp(value[1].data, "off") == 0) { 3871 if (ngx_strcmp(value[1].data, "off") == 0) {
3873 plcf->upstream.cache = NULL; 3872 plcf->upstream.cache = 0;
3874 return NGX_CONF_OK; 3873 return NGX_CONF_OK;
3875 } 3874 }
3876 3875
3877 if (plcf->upstream.store > 0) { 3876 if (plcf->upstream.store > 0) {
3878 return "is incompatible with \"proxy_store\""; 3877 return "is incompatible with \"proxy_store\"";
3879 } 3878 }
3880 3879
3881 plcf->upstream.cache = ngx_shared_memory_add(cf, &value[1], 0, 3880 plcf->upstream.cache = 1;
3882 &ngx_http_proxy_module); 3881
3883 if (plcf->upstream.cache == NULL) { 3882 plcf->upstream.cache_zone = ngx_shared_memory_add(cf, &value[1], 0,
3883 &ngx_http_proxy_module);
3884 if (plcf->upstream.cache_zone == NULL) {
3884 return NGX_CONF_ERROR; 3885 return NGX_CONF_ERROR;
3885 } 3886 }
3886 3887
3887 return NGX_CONF_OK; 3888 return NGX_CONF_OK;
3888 } 3889 }