comparison src/http/modules/ngx_http_proxy_module.c @ 4274:595560d9dcbf

Fixed proxy_set_header inheritance with proxy_cache (ticket #45). Headers cleared with cache enabled (If-Modified-Since etc.) might be cleared in unrelated servers/locations without proxy_cache enabled if proxy_cache was used in some server/location. Example config which triggered the problem: proxy_set_header X-Test "test"; server { location /1 { proxy_cache name; proxy_pass ... } } server { location /2 { proxy_pass ... } } Another one: server { proxy_cache name; location /1 { proxy_pass ... } location /2 { proxy_cache off; proxy_pass ... } } In both cases If-Modified-Since header wasn't sent to backend in location /2. Fix is to not modify conf->headers_source, but instead merge user-supplied headers from conf->headers_source and default headers (either cache or not) into separate headers_merged array.
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 14 Nov 2011 13:18:15 +0000
parents 26c307b8dc3c
children bb909c0c8629
comparison
equal deleted inserted replaced
4273:e444e8f6538b 4274:595560d9dcbf
2873 { 2873 {
2874 u_char *p; 2874 u_char *p;
2875 size_t size; 2875 size_t size;
2876 uintptr_t *code; 2876 uintptr_t *code;
2877 ngx_uint_t i; 2877 ngx_uint_t i;
2878 ngx_array_t headers_names; 2878 ngx_array_t headers_names, headers_merged;
2879 ngx_keyval_t *src, *s, *h; 2879 ngx_keyval_t *src, *s, *h;
2880 ngx_hash_key_t *hk; 2880 ngx_hash_key_t *hk;
2881 ngx_hash_init_t hash; 2881 ngx_hash_init_t hash;
2882 ngx_http_script_compile_t sc; 2882 ngx_http_script_compile_t sc;
2883 ngx_http_script_copy_code_t *copy; 2883 ngx_http_script_copy_code_t *copy;
2904 != NGX_OK) 2904 != NGX_OK)
2905 { 2905 {
2906 return NGX_ERROR; 2906 return NGX_ERROR;
2907 } 2907 }
2908 2908
2909 if (ngx_array_init(&headers_merged, cf->temp_pool, 4, sizeof(ngx_keyval_t))
2910 != NGX_OK)
2911 {
2912 return NGX_ERROR;
2913 }
2914
2909 if (conf->headers_source == NULL) { 2915 if (conf->headers_source == NULL) {
2910 conf->headers_source = ngx_array_create(cf->pool, 4, 2916 conf->headers_source = ngx_array_create(cf->pool, 4,
2911 sizeof(ngx_keyval_t)); 2917 sizeof(ngx_keyval_t));
2912 if (conf->headers_source == NULL) { 2918 if (conf->headers_source == NULL) {
2913 return NGX_ERROR; 2919 return NGX_ERROR;
2923 if (conf->headers_set == NULL) { 2929 if (conf->headers_set == NULL) {
2924 return NGX_ERROR; 2930 return NGX_ERROR;
2925 } 2931 }
2926 2932
2927 2933
2928 src = conf->headers_source->elts;
2929
2930 #if (NGX_HTTP_CACHE) 2934 #if (NGX_HTTP_CACHE)
2931 2935
2932 h = conf->upstream.cache ? ngx_http_proxy_cache_headers: 2936 h = conf->upstream.cache ? ngx_http_proxy_cache_headers:
2933 ngx_http_proxy_headers; 2937 ngx_http_proxy_headers;
2934 #else 2938 #else
2935 2939
2936 h = ngx_http_proxy_headers; 2940 h = ngx_http_proxy_headers;
2937 2941
2938 #endif 2942 #endif
2939 2943
2944 src = conf->headers_source->elts;
2945 for (i = 0; i < conf->headers_source->nelts; i++) {
2946
2947 s = ngx_array_push(&headers_merged);
2948 if (s == NULL) {
2949 return NGX_ERROR;
2950 }
2951
2952 *s = src[i];
2953 }
2954
2940 while (h->key.len) { 2955 while (h->key.len) {
2941 2956
2942 for (i = 0; i < conf->headers_source->nelts; i++) { 2957 src = headers_merged.elts;
2958 for (i = 0; i < headers_merged.nelts; i++) {
2943 if (ngx_strcasecmp(h->key.data, src[i].key.data) == 0) { 2959 if (ngx_strcasecmp(h->key.data, src[i].key.data) == 0) {
2944 goto next; 2960 goto next;
2945 } 2961 }
2946 } 2962 }
2947 2963
2948 s = ngx_array_push(conf->headers_source); 2964 s = ngx_array_push(&headers_merged);
2949 if (s == NULL) { 2965 if (s == NULL) {
2950 return NGX_ERROR; 2966 return NGX_ERROR;
2951 } 2967 }
2952 2968
2953 *s = *h; 2969 *s = *h;
2954 2970
2955 src = conf->headers_source->elts;
2956
2957 next: 2971 next:
2958 2972
2959 h++; 2973 h++;
2960 } 2974 }
2961 2975
2962 2976
2963 src = conf->headers_source->elts; 2977 src = headers_merged.elts;
2964 for (i = 0; i < conf->headers_source->nelts; i++) { 2978 for (i = 0; i < headers_merged.nelts; i++) {
2965 2979
2966 hk = ngx_array_push(&headers_names); 2980 hk = ngx_array_push(&headers_names);
2967 if (hk == NULL) { 2981 if (hk == NULL) {
2968 return NGX_ERROR; 2982 return NGX_ERROR;
2969 } 2983 }