comparison src/http/ngx_http_upstream.c @ 4298:186f02886bed

Upstream: don't cache unfinished responses. Check if received data length match Content-Length header (if present), don't cache response if no match found. This prevents caching of corrupted response in case of premature connection close by upstream.
author Maxim Dounin <mdounin@mdounin.ru>
date Fri, 18 Nov 2011 15:09:08 +0000
parents cf6a3467b5db
children d15a00e6d9e6
comparison
equal deleted inserted replaced
4297:2f8e9469b436 4298:186f02886bed
2694 if (p->upstream_done) { 2694 if (p->upstream_done) {
2695 ngx_http_file_cache_update(r, u->pipe->temp_file); 2695 ngx_http_file_cache_update(r, u->pipe->temp_file);
2696 2696
2697 } else if (p->upstream_eof) { 2697 } else if (p->upstream_eof) {
2698 2698
2699 /* TODO: check length & update cache */ 2699 tf = u->pipe->temp_file;
2700 2700
2701 ngx_http_file_cache_update(r, u->pipe->temp_file); 2701 if (u->headers_in.content_length_n == -1
2702 || u->headers_in.content_length_n
2703 == tf->offset - (off_t) r->cache->body_start)
2704 {
2705 ngx_http_file_cache_update(r, tf);
2706
2707 } else {
2708 ngx_http_file_cache_free(r->cache, tf);
2709 }
2702 2710
2703 } else if (p->upstream_error) { 2711 } else if (p->upstream_error) {
2704 ngx_http_file_cache_free(r->cache, u->pipe->temp_file); 2712 ngx_http_file_cache_free(r->cache, u->pipe->temp_file);
2705 } 2713 }
2706 } 2714 }