Mercurial > hg > nginx
comparison src/http/ngx_http_upstream.c @ 5732:d0ce06cb9be1
Upstream: fixed cache revalidation with SSI.
Previous code in ngx_http_upstream_send_response() used last modified time
from r->headers_out.last_modified_time after the header filter chain was
already called. At this point, last_modified_time may be already cleared,
e.g., with SSI, resulting in incorrect last modified time stored in a
cache file. Fix is to introduce u->headers_in.last_modified_time instead.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 26 Jun 2014 02:20:09 +0400 |
parents | 02674312be45 |
children | 5fb1e57c758a |
comparison
equal
deleted
inserted
replaced
5731:02674312be45 | 5732:d0ce06cb9be1 |
---|---|
85 | 85 |
86 static ngx_int_t ngx_http_upstream_process_header_line(ngx_http_request_t *r, | 86 static ngx_int_t ngx_http_upstream_process_header_line(ngx_http_request_t *r, |
87 ngx_table_elt_t *h, ngx_uint_t offset); | 87 ngx_table_elt_t *h, ngx_uint_t offset); |
88 static ngx_int_t ngx_http_upstream_process_content_length(ngx_http_request_t *r, | 88 static ngx_int_t ngx_http_upstream_process_content_length(ngx_http_request_t *r, |
89 ngx_table_elt_t *h, ngx_uint_t offset); | 89 ngx_table_elt_t *h, ngx_uint_t offset); |
90 static ngx_int_t ngx_http_upstream_process_last_modified(ngx_http_request_t *r, | |
91 ngx_table_elt_t *h, ngx_uint_t offset); | |
90 static ngx_int_t ngx_http_upstream_process_set_cookie(ngx_http_request_t *r, | 92 static ngx_int_t ngx_http_upstream_process_set_cookie(ngx_http_request_t *r, |
91 ngx_table_elt_t *h, ngx_uint_t offset); | 93 ngx_table_elt_t *h, ngx_uint_t offset); |
92 static ngx_int_t | 94 static ngx_int_t |
93 ngx_http_upstream_process_cache_control(ngx_http_request_t *r, | 95 ngx_http_upstream_process_cache_control(ngx_http_request_t *r, |
94 ngx_table_elt_t *h, ngx_uint_t offset); | 96 ngx_table_elt_t *h, ngx_uint_t offset); |
182 offsetof(ngx_http_upstream_headers_in_t, date), | 184 offsetof(ngx_http_upstream_headers_in_t, date), |
183 ngx_http_upstream_copy_header_line, | 185 ngx_http_upstream_copy_header_line, |
184 offsetof(ngx_http_headers_out_t, date), 0 }, | 186 offsetof(ngx_http_headers_out_t, date), 0 }, |
185 | 187 |
186 { ngx_string("Last-Modified"), | 188 { ngx_string("Last-Modified"), |
187 ngx_http_upstream_process_header_line, | 189 ngx_http_upstream_process_last_modified, 0, |
188 offsetof(ngx_http_upstream_headers_in_t, last_modified), | |
189 ngx_http_upstream_copy_last_modified, 0, 0 }, | 190 ngx_http_upstream_copy_last_modified, 0, 0 }, |
190 | 191 |
191 { ngx_string("ETag"), | 192 { ngx_string("ETag"), |
192 ngx_http_upstream_process_header_line, | 193 ngx_http_upstream_process_header_line, |
193 offsetof(ngx_http_upstream_headers_in_t, etag), | 194 offsetof(ngx_http_upstream_headers_in_t, etag), |
2489 r->cache->valid_sec = now + valid; | 2490 r->cache->valid_sec = now + valid; |
2490 } | 2491 } |
2491 } | 2492 } |
2492 | 2493 |
2493 if (valid) { | 2494 if (valid) { |
2494 r->cache->last_modified = r->headers_out.last_modified_time; | 2495 r->cache->last_modified = u->headers_in.last_modified_time; |
2495 r->cache->date = now; | 2496 r->cache->date = now; |
2496 r->cache->body_start = (u_short) (u->buffer.pos - u->buffer.start); | 2497 r->cache->body_start = (u_short) (u->buffer.pos - u->buffer.start); |
2497 | 2498 |
2498 ngx_http_file_cache_set_header(r, u->buffer.start); | 2499 ngx_http_file_cache_set_header(r, u->buffer.start); |
2499 | 2500 |
3726 return NGX_OK; | 3727 return NGX_OK; |
3727 } | 3728 } |
3728 | 3729 |
3729 | 3730 |
3730 static ngx_int_t | 3731 static ngx_int_t |
3732 ngx_http_upstream_process_last_modified(ngx_http_request_t *r, | |
3733 ngx_table_elt_t *h, ngx_uint_t offset) | |
3734 { | |
3735 ngx_http_upstream_t *u; | |
3736 | |
3737 u = r->upstream; | |
3738 | |
3739 u->headers_in.last_modified = h; | |
3740 | |
3741 #if (NGX_HTTP_CACHE) | |
3742 | |
3743 if (u->cacheable) { | |
3744 u->headers_in.last_modified_time = ngx_http_parse_time(h->value.data, | |
3745 h->value.len); | |
3746 } | |
3747 | |
3748 #endif | |
3749 | |
3750 return NGX_OK; | |
3751 } | |
3752 | |
3753 | |
3754 static ngx_int_t | |
3731 ngx_http_upstream_process_set_cookie(ngx_http_request_t *r, ngx_table_elt_t *h, | 3755 ngx_http_upstream_process_set_cookie(ngx_http_request_t *r, ngx_table_elt_t *h, |
3732 ngx_uint_t offset) | 3756 ngx_uint_t offset) |
3733 { | 3757 { |
3734 ngx_array_t *pa; | 3758 ngx_array_t *pa; |
3735 ngx_table_elt_t **ph; | 3759 ngx_table_elt_t **ph; |
4181 r->headers_out.last_modified = ho; | 4205 r->headers_out.last_modified = ho; |
4182 | 4206 |
4183 #if (NGX_HTTP_CACHE) | 4207 #if (NGX_HTTP_CACHE) |
4184 | 4208 |
4185 if (r->upstream->cacheable) { | 4209 if (r->upstream->cacheable) { |
4186 r->headers_out.last_modified_time = ngx_http_parse_time(h->value.data, | 4210 r->headers_out.last_modified_time = |
4187 h->value.len); | 4211 r->upstream->headers_in.last_modified_time; |
4188 } | 4212 } |
4189 | 4213 |
4190 #endif | 4214 #endif |
4191 | 4215 |
4192 return NGX_OK; | 4216 return NGX_OK; |