mirror of
https://github.com/nginx/nginx.git
synced 2024-12-03 13:09:01 +08:00
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.
This commit is contained in:
parent
6c25c848cb
commit
5d477a76fe
@ -87,6 +87,8 @@ static ngx_int_t ngx_http_upstream_process_header_line(ngx_http_request_t *r,
|
||||
ngx_table_elt_t *h, ngx_uint_t offset);
|
||||
static ngx_int_t ngx_http_upstream_process_content_length(ngx_http_request_t *r,
|
||||
ngx_table_elt_t *h, ngx_uint_t offset);
|
||||
static ngx_int_t ngx_http_upstream_process_last_modified(ngx_http_request_t *r,
|
||||
ngx_table_elt_t *h, ngx_uint_t offset);
|
||||
static ngx_int_t ngx_http_upstream_process_set_cookie(ngx_http_request_t *r,
|
||||
ngx_table_elt_t *h, ngx_uint_t offset);
|
||||
static ngx_int_t
|
||||
@ -184,8 +186,7 @@ ngx_http_upstream_header_t ngx_http_upstream_headers_in[] = {
|
||||
offsetof(ngx_http_headers_out_t, date), 0 },
|
||||
|
||||
{ ngx_string("Last-Modified"),
|
||||
ngx_http_upstream_process_header_line,
|
||||
offsetof(ngx_http_upstream_headers_in_t, last_modified),
|
||||
ngx_http_upstream_process_last_modified, 0,
|
||||
ngx_http_upstream_copy_last_modified, 0, 0 },
|
||||
|
||||
{ ngx_string("ETag"),
|
||||
@ -2491,7 +2492,7 @@ ngx_http_upstream_send_response(ngx_http_request_t *r, ngx_http_upstream_t *u)
|
||||
}
|
||||
|
||||
if (valid) {
|
||||
r->cache->last_modified = r->headers_out.last_modified_time;
|
||||
r->cache->last_modified = u->headers_in.last_modified_time;
|
||||
r->cache->date = now;
|
||||
r->cache->body_start = (u_short) (u->buffer.pos - u->buffer.start);
|
||||
|
||||
@ -3727,6 +3728,29 @@ ngx_http_upstream_process_content_length(ngx_http_request_t *r,
|
||||
}
|
||||
|
||||
|
||||
static ngx_int_t
|
||||
ngx_http_upstream_process_last_modified(ngx_http_request_t *r,
|
||||
ngx_table_elt_t *h, ngx_uint_t offset)
|
||||
{
|
||||
ngx_http_upstream_t *u;
|
||||
|
||||
u = r->upstream;
|
||||
|
||||
u->headers_in.last_modified = h;
|
||||
|
||||
#if (NGX_HTTP_CACHE)
|
||||
|
||||
if (u->cacheable) {
|
||||
u->headers_in.last_modified_time = ngx_http_parse_time(h->value.data,
|
||||
h->value.len);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
return NGX_OK;
|
||||
}
|
||||
|
||||
|
||||
static ngx_int_t
|
||||
ngx_http_upstream_process_set_cookie(ngx_http_request_t *r, ngx_table_elt_t *h,
|
||||
ngx_uint_t offset)
|
||||
@ -4183,8 +4207,8 @@ ngx_http_upstream_copy_last_modified(ngx_http_request_t *r, ngx_table_elt_t *h,
|
||||
#if (NGX_HTTP_CACHE)
|
||||
|
||||
if (r->upstream->cacheable) {
|
||||
r->headers_out.last_modified_time = ngx_http_parse_time(h->value.data,
|
||||
h->value.len);
|
||||
r->headers_out.last_modified_time =
|
||||
r->upstream->headers_in.last_modified_time;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -246,11 +246,12 @@ typedef struct {
|
||||
ngx_table_elt_t *content_encoding;
|
||||
#endif
|
||||
|
||||
off_t content_length_n;
|
||||
|
||||
ngx_array_t cache_control;
|
||||
ngx_array_t cookies;
|
||||
|
||||
off_t content_length_n;
|
||||
time_t last_modified_time;
|
||||
|
||||
unsigned connection_close:1;
|
||||
unsigned chunked:1;
|
||||
} ngx_http_upstream_headers_in_t;
|
||||
|
Loading…
Reference in New Issue
Block a user