Klaus Demo nginx / 21a3c66
support Cache-Control no-cache and max-age in cache Igor Sysoev 13 years ago
1 changed file(s) with 59 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
6969 static ngx_int_t ngx_http_upstream_process_header_line(ngx_http_request_t *r,
7070 ngx_table_elt_t *h, ngx_uint_t offset);
7171 static ngx_int_t
72 ngx_http_upstream_process_multi_header_lines(ngx_http_request_t *r,
72 ngx_http_upstream_process_cache_control(ngx_http_request_t *r,
7373 ngx_table_elt_t *h, ngx_uint_t offset);
7474 static ngx_int_t ngx_http_upstream_ignore_header_line(ngx_http_request_t *r,
7575 ngx_table_elt_t *h, ngx_uint_t offset);
187187 ngx_http_upstream_copy_header_line, 0, 1 },
188188
189189 { ngx_string("Cache-Control"),
190 ngx_http_upstream_process_multi_header_lines,
191 offsetof(ngx_http_upstream_headers_in_t, cache_control),
190 ngx_http_upstream_process_cache_control, 0,
192191 ngx_http_upstream_copy_multi_header_lines,
193192 offsetof(ngx_http_headers_out_t, cache_control), 1 },
194193
28042803
28052804
28062805 static ngx_int_t
2807 ngx_http_upstream_process_multi_header_lines(ngx_http_request_t *r,
2806 ngx_http_upstream_ignore_header_line(ngx_http_request_t *r, ngx_table_elt_t *h,
2807 ngx_uint_t offset)
2808 {
2809 return NGX_OK;
2810 }
2811
2812
2813 static ngx_int_t
2814 ngx_http_upstream_process_cache_control(ngx_http_request_t *r,
28082815 ngx_table_elt_t *h, ngx_uint_t offset)
28092816 {
2817 u_char *p, *last;
2818 ngx_int_t n;
28102819 ngx_array_t *pa;
28112820 ngx_table_elt_t **ph;
28122821
2813 pa = (ngx_array_t *) ((char *) &r->upstream->headers_in + offset);
2822 pa = &r->upstream->headers_in.cache_control;
28142823
28152824 if (pa->elts == NULL) {
28162825 if (ngx_array_init(pa, r->pool, 2, sizeof(ngx_table_elt_t *)) != NGX_OK)
28262835
28272836 *ph = h;
28282837
2829 return NGX_OK;
2830 }
2831
2832
2833 static ngx_int_t
2834 ngx_http_upstream_ignore_header_line(ngx_http_request_t *r, ngx_table_elt_t *h,
2835 ngx_uint_t offset)
2836 {
2838 if (r->cache == NULL) {
2839 return NGX_OK;
2840 }
2841
2842 if (r->cache->valid_sec != 0) {
2843 return NGX_OK;
2844 }
2845
2846 last = h->value.data + h->value.len;
2847
2848 if (ngx_strlcasestrn(h->value.data, last, (u_char *) "no-cache", 8 - 1)
2849 != NULL)
2850 {
2851 r->upstream->cacheable = 0;
2852 return NGX_OK;
2853 }
2854
2855 p = ngx_strlcasestrn(h->value.data, last, (u_char *) "max-age=", 8 - 1);
2856
2857 if (p == NULL) {
2858 return NGX_OK;
2859 }
2860
2861 n = 0;
2862
2863 for (p += 8; p < last; p++) {
2864 if (*p == ';' || *p == ' ') {
2865 break;
2866 }
2867
2868 if (*p >= '0' && *p <= '9') {
2869 n = n * 10 + *p - '0';
2870 continue;
2871 }
2872
2873 r->upstream->cacheable = 0;
2874 return NGX_OK;
2875 }
2876
2877 if (n == 0) {
2878 r->upstream->cacheable = 0;
2879 return NGX_OK;
2880 }
2881
2882 r->cache->valid_sec = ngx_time() + n;
28372883 return NGX_OK;
28382884 }
28392885