comparison src/http/ngx_http_upstream.c @ 2669:5e4d8bd4486c

support Cache-Control no-cache and max-age in cache
author Igor Sysoev <igor@sysoev.ru>
date Sat, 04 Apr 2009 17:35:40 +0000
parents c1ac00c2bc75
children d3cffe32b930
comparison
equal deleted inserted replaced
2668:2f9c37445ffb 2669:5e4d8bd4486c
68 ngx_http_upstream_t *u, ngx_int_t rc); 68 ngx_http_upstream_t *u, ngx_int_t rc);
69 69
70 static ngx_int_t ngx_http_upstream_process_header_line(ngx_http_request_t *r, 70 static ngx_int_t ngx_http_upstream_process_header_line(ngx_http_request_t *r,
71 ngx_table_elt_t *h, ngx_uint_t offset); 71 ngx_table_elt_t *h, ngx_uint_t offset);
72 static ngx_int_t 72 static ngx_int_t
73 ngx_http_upstream_process_multi_header_lines(ngx_http_request_t *r, 73 ngx_http_upstream_process_cache_control(ngx_http_request_t *r,
74 ngx_table_elt_t *h, ngx_uint_t offset); 74 ngx_table_elt_t *h, ngx_uint_t offset);
75 static ngx_int_t ngx_http_upstream_ignore_header_line(ngx_http_request_t *r, 75 static ngx_int_t ngx_http_upstream_ignore_header_line(ngx_http_request_t *r,
76 ngx_table_elt_t *h, ngx_uint_t offset); 76 ngx_table_elt_t *h, ngx_uint_t offset);
77 static ngx_int_t ngx_http_upstream_process_expires(ngx_http_request_t *r, 77 static ngx_int_t ngx_http_upstream_process_expires(ngx_http_request_t *r,
78 ngx_table_elt_t *h, ngx_uint_t offset); 78 ngx_table_elt_t *h, ngx_uint_t offset);
186 { ngx_string("Content-Disposition"), 186 { ngx_string("Content-Disposition"),
187 ngx_http_upstream_ignore_header_line, 0, 187 ngx_http_upstream_ignore_header_line, 0,
188 ngx_http_upstream_copy_header_line, 0, 1 }, 188 ngx_http_upstream_copy_header_line, 0, 1 },
189 189
190 { ngx_string("Cache-Control"), 190 { ngx_string("Cache-Control"),
191 ngx_http_upstream_process_multi_header_lines, 191 ngx_http_upstream_process_cache_control, 0,
192 offsetof(ngx_http_upstream_headers_in_t, cache_control),
193 ngx_http_upstream_copy_multi_header_lines, 192 ngx_http_upstream_copy_multi_header_lines,
194 offsetof(ngx_http_headers_out_t, cache_control), 1 }, 193 offsetof(ngx_http_headers_out_t, cache_control), 1 },
195 194
196 { ngx_string("Expires"), 195 { ngx_string("Expires"),
197 ngx_http_upstream_process_expires, 0, 196 ngx_http_upstream_process_expires, 0,
2803 return NGX_OK; 2802 return NGX_OK;
2804 } 2803 }
2805 2804
2806 2805
2807 static ngx_int_t 2806 static ngx_int_t
2808 ngx_http_upstream_process_multi_header_lines(ngx_http_request_t *r, 2807 ngx_http_upstream_ignore_header_line(ngx_http_request_t *r, ngx_table_elt_t *h,
2808 ngx_uint_t offset)
2809 {
2810 return NGX_OK;
2811 }
2812
2813
2814 static ngx_int_t
2815 ngx_http_upstream_process_cache_control(ngx_http_request_t *r,
2809 ngx_table_elt_t *h, ngx_uint_t offset) 2816 ngx_table_elt_t *h, ngx_uint_t offset)
2810 { 2817 {
2818 u_char *p, *last;
2819 ngx_int_t n;
2811 ngx_array_t *pa; 2820 ngx_array_t *pa;
2812 ngx_table_elt_t **ph; 2821 ngx_table_elt_t **ph;
2813 2822
2814 pa = (ngx_array_t *) ((char *) &r->upstream->headers_in + offset); 2823 pa = &r->upstream->headers_in.cache_control;
2815 2824
2816 if (pa->elts == NULL) { 2825 if (pa->elts == NULL) {
2817 if (ngx_array_init(pa, r->pool, 2, sizeof(ngx_table_elt_t *)) != NGX_OK) 2826 if (ngx_array_init(pa, r->pool, 2, sizeof(ngx_table_elt_t *)) != NGX_OK)
2818 { 2827 {
2819 return NGX_ERROR; 2828 return NGX_ERROR;
2825 return NGX_ERROR; 2834 return NGX_ERROR;
2826 } 2835 }
2827 2836
2828 *ph = h; 2837 *ph = h;
2829 2838
2830 return NGX_OK; 2839 if (r->cache == NULL) {
2831 } 2840 return NGX_OK;
2832 2841 }
2833 2842
2834 static ngx_int_t 2843 if (r->cache->valid_sec != 0) {
2835 ngx_http_upstream_ignore_header_line(ngx_http_request_t *r, ngx_table_elt_t *h, 2844 return NGX_OK;
2836 ngx_uint_t offset) 2845 }
2837 { 2846
2847 last = h->value.data + h->value.len;
2848
2849 if (ngx_strlcasestrn(h->value.data, last, (u_char *) "no-cache", 8 - 1)
2850 != NULL)
2851 {
2852 r->upstream->cacheable = 0;
2853 return NGX_OK;
2854 }
2855
2856 p = ngx_strlcasestrn(h->value.data, last, (u_char *) "max-age=", 8 - 1);
2857
2858 if (p == NULL) {
2859 return NGX_OK;
2860 }
2861
2862 n = 0;
2863
2864 for (p += 8; p < last; p++) {
2865 if (*p == ';' || *p == ' ') {
2866 break;
2867 }
2868
2869 if (*p >= '0' && *p <= '9') {
2870 n = n * 10 + *p - '0';
2871 continue;
2872 }
2873
2874 r->upstream->cacheable = 0;
2875 return NGX_OK;
2876 }
2877
2878 if (n == 0) {
2879 r->upstream->cacheable = 0;
2880 return NGX_OK;
2881 }
2882
2883 r->cache->valid_sec = ngx_time() + n;
2838 return NGX_OK; 2884 return NGX_OK;
2839 } 2885 }
2840 2886
2841 2887
2842 static ngx_int_t 2888 static ngx_int_t