Skip to content

Commit

Permalink
Upstream: don't cache unfinished responses.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mdounin committed Nov 18, 2011
1 parent 5eef168 commit e0c1a63
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/http/ngx_http_upstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -2696,9 +2696,17 @@ ngx_http_upstream_process_request(ngx_http_request_t *r)

} else if (p->upstream_eof) {

/* TODO: check length & update cache */
tf = u->pipe->temp_file;

ngx_http_file_cache_update(r, u->pipe->temp_file);
if (u->headers_in.content_length_n == -1
|| u->headers_in.content_length_n
== tf->offset - (off_t) r->cache->body_start)
{
ngx_http_file_cache_update(r, tf);

} else {
ngx_http_file_cache_free(r->cache, tf);
}

} else if (p->upstream_error) {
ngx_http_file_cache_free(r->cache, u->pipe->temp_file);
Expand Down

0 comments on commit e0c1a63

Please sign in to comment.