Mercurial > hg > nginx
comparison src/http/ngx_http_file_cache.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 | ee270f311dea |
children | 311b358658c8 |
comparison
equal
deleted
inserted
replaced
4247:b79dbadb3d5e | 4248:2fad4d19ea4b |
---|---|
852 c = r->cache; | 852 c = r->cache; |
853 | 853 |
854 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 854 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
855 "http file cache send: %s", c->file.name.data); | 855 "http file cache send: %s", c->file.name.data); |
856 | 856 |
857 if (r != r->main && c->length - c->body_start == 0) { | |
858 return ngx_http_send_header(r); | |
859 } | |
860 | |
857 /* we need to allocate all before the header would be sent */ | 861 /* we need to allocate all before the header would be sent */ |
858 | 862 |
859 b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t)); | 863 b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t)); |
860 if (b == NULL) { | 864 if (b == NULL) { |
861 return NGX_HTTP_INTERNAL_SERVER_ERROR; | 865 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
864 b->file = ngx_pcalloc(r->pool, sizeof(ngx_file_t)); | 868 b->file = ngx_pcalloc(r->pool, sizeof(ngx_file_t)); |
865 if (b->file == NULL) { | 869 if (b->file == NULL) { |
866 return NGX_HTTP_INTERNAL_SERVER_ERROR; | 870 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
867 } | 871 } |
868 | 872 |
869 r->header_only = (c->length - c->body_start) == 0; | |
870 | |
871 rc = ngx_http_send_header(r); | 873 rc = ngx_http_send_header(r); |
872 | 874 |
873 if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) { | 875 if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) { |
874 return rc; | 876 return rc; |
875 } | 877 } |
876 | 878 |
877 b->file_pos = c->body_start; | 879 b->file_pos = c->body_start; |
878 b->file_last = c->length; | 880 b->file_last = c->length; |
879 | 881 |
880 b->in_file = 1; | 882 b->in_file = (c->length - c->body_start) ? 1: 0; |
881 b->last_buf = (r == r->main) ? 1: 0; | 883 b->last_buf = (r == r->main) ? 1: 0; |
882 b->last_in_chain = 1; | 884 b->last_in_chain = 1; |
883 | 885 |
884 b->file->fd = c->file.fd; | 886 b->file->fd = c->file.fd; |
885 b->file->name = c->file.name; | 887 b->file->name = c->file.name; |