Skip to content

Commit

Permalink
Upstream: fixed store/cache of unfinished responses.
Browse files Browse the repository at this point in the history
In case of upstream eof, only responses with u->pipe->length == -1
are now cached/stored.  This ensures that unfinished chunked responses
are not cached.

Note well - previously used checks for u->headers_in.content_length_n are
preserved.  This provides an additional level of protection if protol data
disagree with Content-Length header provided (e.g., a FastCGI response
is sent with wrong Content-Length, or an incomple SCGI or uwsgi response),
as well as protects from storing of responses to HEAD requests.  This should
be reconsidered if we'll consider caching of responses to HEAD requests.
  • Loading branch information
mdounin committed Jul 25, 2013
1 parent eafe44f commit 187f394
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/http/ngx_http_upstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -2985,6 +2985,7 @@ ngx_http_upstream_process_request(ngx_http_request_t *r)
tf = p->temp_file;

if (u->headers_in.status_n == NGX_HTTP_OK
&& (p->upstream_done || p->length == -1)
&& (u->headers_in.content_length_n == -1
|| u->headers_in.content_length_n == tf->offset))
{
Expand All @@ -3005,9 +3006,10 @@ ngx_http_upstream_process_request(ngx_http_request_t *r)

tf = p->temp_file;

if (u->headers_in.content_length_n == -1
|| u->headers_in.content_length_n
== tf->offset - (off_t) r->cache->body_start)
if (p->length == -1
&& (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);

Expand Down

0 comments on commit 187f394

Please sign in to comment.