comparison src/http/ngx_http_upstream.c @ 5992:174512857ccf

Cache: do not inherit last_modified and etag from stale response. When replacing a stale cache entry, its last_modified and etag could be inherited from the old entry if the response code is not 200 or 206. Moreover, etag could be inherited with any response code if it's missing in the new response. As a result, the cache entry is left with invalid last_modified or etag which could lead to broken revalidation. For example, when a file is deleted from backend, its last_modified is copied to the new 404 cache entry and is used later for revalidation. Once the old file appears again with its original timestamp, revalidation succeeds and the cached 404 response is sent to client instead of the file. The problem appeared with etags in 44b9ab7752e3 (1.7.3) and affected last_modified in 1573fc7875fa (1.7.9).
author Roman Arutyunyan <arut@nginx.com>
date Mon, 02 Mar 2015 19:47:13 +0300
parents 26c127bab5ef
children 5abf5af257a7
comparison
equal deleted inserted replaced
5991:435ee290c2e1 5992:174512857ccf
2633 { 2633 {
2634 r->cache->last_modified = u->headers_in.last_modified_time; 2634 r->cache->last_modified = u->headers_in.last_modified_time;
2635 2635
2636 if (u->headers_in.etag) { 2636 if (u->headers_in.etag) {
2637 r->cache->etag = u->headers_in.etag->value; 2637 r->cache->etag = u->headers_in.etag->value;
2638
2639 } else {
2640 ngx_str_null(&r->cache->etag);
2638 } 2641 }
2642
2643 } else {
2644 r->cache->last_modified = -1;
2645 ngx_str_null(&r->cache->etag);
2639 } 2646 }
2640 2647
2641 if (ngx_http_file_cache_set_header(r, u->buffer.start) != NGX_OK) { 2648 if (ngx_http_file_cache_set_header(r, u->buffer.start) != NGX_OK) {
2642 ngx_http_upstream_finalize_request(r, u, NGX_ERROR); 2649 ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
2643 return; 2650 return;