Skip to content

Commit

Permalink
Cache: fixed caching of intercepted errors (ticket #1382).
Browse files Browse the repository at this point in the history
When caching intercepted errors, previous behaviour was to use
proxy_cache_valid times specified, regardless of various cache control
headers present in the response.  Fix is to check u->cacheable and
use u->cache->valid_sec as set by various cache control response headers,
similar to how we do this in the normal caching code path.
  • Loading branch information
mdounin committed Oct 3, 2017
1 parent 105dd42 commit d07d598
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/http/ngx_http_upstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -2528,13 +2528,23 @@ ngx_http_upstream_intercept_errors(ngx_http_request_t *r,
#if (NGX_HTTP_CACHE)

if (r->cache) {
time_t valid;

valid = ngx_http_file_cache_valid(u->conf->cache_valid, status);
if (u->cacheable) {
time_t valid;

if (valid) {
r->cache->valid_sec = ngx_time() + valid;
r->cache->error = status;
valid = r->cache->valid_sec;

if (valid == 0) {
valid = ngx_http_file_cache_valid(u->conf->cache_valid,
status);
if (valid) {
r->cache->valid_sec = ngx_time() + valid;
}
}

if (valid) {
r->cache->error = status;
}
}

ngx_http_file_cache_free(r->cache, u->pipe->temp_file);
Expand Down

0 comments on commit d07d598

Please sign in to comment.