Mercurial > hg > nginx-quic
comparison src/http/ngx_http_upstream.c @ 4248:2fad4d19ea4b stable-1.0
Merging r4151, r4152, r4177:
HTTP cache related fixes:
*) Cache: fix for sending of empty responses.
Revert wrong fix for empty responses introduced in 0.8.31 and apply new
one, rewritten to match things done by static module as close as possible.
*) Cache: fix for sending of stale responses.
For normal cached responses ngx_http_cache_send() sends last buffer and then
request finalized via ngx_http_finalize_request() call, i.e. everything is
ok.
But for stale responses (i.e. when upstream died, but we have something in
cache) the same ngx_http_cache_send() sends last buffer, but then in
ngx_http_upstream_finalize_request() another last buffer is send. This
causes duplicate final chunk to appear if chunked encoding is used (and
resulting problems with keepalive connections and so on).
Fix this by not sending in ngx_http_upstream_finalize_request()
another last buffer if we know response was from cache.
*) Fixed cache bypass caching of non-cacheable replies (ticket #21).
If cache was bypassed with proxy_cache_bypass, cache-controlling headers
(Cache-Control, Expires) wasn't considered and response was cached even
if it was actually non-cacheable.
Patch by John Ferlito.
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 01 Nov 2011 13:49:31 +0000 |
parents | d3568507db51 |
children | f83b47591642 |
comparison
equal
deleted
inserted
replaced
4247:b79dbadb3d5e | 4248:2fad4d19ea4b |
---|---|
670 | 670 |
671 r->cache = NULL; | 671 r->cache = NULL; |
672 return NGX_DECLINED; | 672 return NGX_DECLINED; |
673 } | 673 } |
674 | 674 |
675 u->cacheable = 1; | |
676 | |
675 switch (ngx_http_test_predicates(r, u->conf->cache_bypass)) { | 677 switch (ngx_http_test_predicates(r, u->conf->cache_bypass)) { |
676 | 678 |
677 case NGX_ERROR: | 679 case NGX_ERROR: |
678 return NGX_ERROR; | 680 return NGX_ERROR; |
679 | 681 |
682 return NGX_DECLINED; | 684 return NGX_DECLINED; |
683 | 685 |
684 default: /* NGX_OK */ | 686 default: /* NGX_OK */ |
685 break; | 687 break; |
686 } | 688 } |
687 | |
688 u->cacheable = 1; | |
689 | 689 |
690 c = r->cache; | 690 c = r->cache; |
691 | 691 |
692 c->min_uses = u->conf->cache_min_uses; | 692 c->min_uses = u->conf->cache_min_uses; |
693 c->body_start = u->conf->buffer_size; | 693 c->body_start = u->conf->buffer_size; |
2152 | 2152 |
2153 if (ngx_http_file_cache_create(r) != NGX_OK) { | 2153 if (ngx_http_file_cache_create(r) != NGX_OK) { |
2154 ngx_http_upstream_finalize_request(r, u, 0); | 2154 ngx_http_upstream_finalize_request(r, u, 0); |
2155 return; | 2155 return; |
2156 } | 2156 } |
2157 | |
2158 u->cacheable = 1; | |
2159 } | 2157 } |
2160 | 2158 |
2161 break; | 2159 break; |
2162 } | 2160 } |
2163 | 2161 |
3025 return; | 3023 return; |
3026 } | 3024 } |
3027 | 3025 |
3028 r->connection->log->action = "sending to client"; | 3026 r->connection->log->action = "sending to client"; |
3029 | 3027 |
3030 if (rc == 0) { | 3028 if (rc == 0 |
3029 #if (NGX_HTTP_CACHE) | |
3030 && !r->cached | |
3031 #endif | |
3032 ) | |
3033 { | |
3031 rc = ngx_http_send_special(r, NGX_HTTP_LAST); | 3034 rc = ngx_http_send_special(r, NGX_HTTP_LAST); |
3032 } | 3035 } |
3033 | 3036 |
3034 ngx_http_finalize_request(r, rc); | 3037 ngx_http_finalize_request(r, rc); |
3035 } | 3038 } |