comparison src/http/ngx_http_upstream.c @ 6428:545b5e4d83b2

Upstream: avoid closing client connection in edge case. If proxy_cache is enabled, and proxy_no_cache tests true, it was previously possible for the client connection to be closed after a 304. The fix is to recheck r->header_only after the final cacheability is determined, and end the request if no longer cacheable. Example configuration: proxy_cache foo; proxy_cache_bypass 1; proxy_no_cache 1; If a client sends If-None-Match, and the upstream server returns 200 with a matching ETag, no body should be returned to the client. At the start of ngx_http_upstream_send_response proxy_no_cache is not yet tested, thus cacheable is still 1 and downstream_error is set. However, by the time the downstream_error check is done in process_request, proxy_no_cache has been tested and cacheable is set to 0. The client connection is then closed, regardless of keepalive.
author Justin Li <jli.justinli@gmail.com>
date Tue, 08 Mar 2016 22:31:55 -0500
parents ad3f342f14ba
children 81329f6a4254
comparison
equal deleted inserted replaced
6427:ad3f342f14ba 6428:545b5e4d83b2
2859 2859
2860 if (u->cacheable == 0 && r->cache) { 2860 if (u->cacheable == 0 && r->cache) {
2861 ngx_http_file_cache_free(r->cache, u->pipe->temp_file); 2861 ngx_http_file_cache_free(r->cache, u->pipe->temp_file);
2862 } 2862 }
2863 2863
2864 if (r->header_only && !u->cacheable && !u->store) {
2865 ngx_http_upstream_finalize_request(r, u, 0);
2866 return;
2867 }
2868
2864 #endif 2869 #endif
2865 2870
2866 p = u->pipe; 2871 p = u->pipe;
2867 2872
2868 p->output_filter = (ngx_event_pipe_output_filter_pt) ngx_http_output_filter; 2873 p->output_filter = (ngx_event_pipe_output_filter_pt) ngx_http_output_filter;