From 136dd8d1e692de0f5b96c6f1da51188737d630b0 Mon Sep 17 00:00:00 2001 From: Igor Sysoev Date: Wed, 7 Oct 2009 12:55:58 +0000 Subject: [PATCH] use real file cache length, this fixes cache size counting for responses without "Content-Length" header and 304 responses. --- src/http/ngx_http_file_cache.c | 8 +++++--- src/http/ngx_http_upstream.c | 5 ----- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/http/ngx_http_file_cache.c b/src/http/ngx_http_file_cache.c index 4caca919a..0a9b761cd 100644 --- a/src/http/ngx_http_file_cache.c +++ b/src/http/ngx_http_file_cache.c @@ -692,7 +692,7 @@ ngx_http_file_cache_set_header(ngx_http_request_t *r, u_char *buf) void ngx_http_file_cache_update(ngx_http_request_t *r, ngx_temp_file_t *tf) { - off_t size; + off_t size, length; ngx_int_t rc; ngx_file_uniq_t uniq; ngx_file_info_t fi; @@ -714,6 +714,7 @@ ngx_http_file_cache_update(ngx_http_request_t *r, ngx_temp_file_t *tf) cache = c->file_cache; uniq = 0; + length = 0; ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "http file cache rename: \"%s\" to \"%s\"", @@ -738,10 +739,11 @@ ngx_http_file_cache_update(ngx_http_request_t *r, ngx_temp_file_t *tf) } else { uniq = ngx_file_uniq(&fi); + length = ngx_file_size(&fi); } } - size = (c->length + cache->bsize - 1) / cache->bsize; + size = (length + cache->bsize - 1) / cache->bsize; ngx_shmtx_lock(&cache->shpool->mutex); @@ -751,7 +753,7 @@ ngx_http_file_cache_update(ngx_http_request_t *r, ngx_temp_file_t *tf) size = size - (c->node->length + cache->bsize - 1) / cache->bsize; - c->node->length = c->length; + c->node->length = length; cache->sh->size += size; diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c index 1e79a4f10..86c5af8f4 100644 --- a/src/http/ngx_http_upstream.c +++ b/src/http/ngx_http_upstream.c @@ -2098,11 +2098,6 @@ ngx_http_upstream_send_response(ngx_http_request_t *r, ngx_http_upstream_t *u) r->cache->date = now; r->cache->body_start = (u_short) (u->buffer.pos - u->buffer.start); - if (r->headers_out.content_length_n != -1) { - r->cache->length = r->cache->body_start - + r->headers_out.content_length_n; - } - ngx_http_file_cache_set_header(r, u->buffer.start); } else {