comparison src/http/ngx_http_file_cache.c @ 4150:b9ee14871bf1

Cache: fix for sending of empty responses. Revert wrong fix for empty responses introduced in 0.8.31 and apply new one, rewritten to match things done by static module as close as possible.
author Maxim Dounin <mdounin@mdounin.ru>
date Tue, 27 Sep 2011 11:15:35 +0000
parents e2c075e774b6
children 02b558fce98a
comparison
equal deleted inserted replaced
4149:28b77af3a238 4150:b9ee14871bf1
851 c = r->cache; 851 c = r->cache;
852 852
853 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 853 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
854 "http file cache send: %s", c->file.name.data); 854 "http file cache send: %s", c->file.name.data);
855 855
856 if (r != r->main && c->length - c->body_start == 0) {
857 return ngx_http_send_header(r);
858 }
859
856 /* we need to allocate all before the header would be sent */ 860 /* we need to allocate all before the header would be sent */
857 861
858 b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t)); 862 b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t));
859 if (b == NULL) { 863 if (b == NULL) {
860 return NGX_HTTP_INTERNAL_SERVER_ERROR; 864 return NGX_HTTP_INTERNAL_SERVER_ERROR;
863 b->file = ngx_pcalloc(r->pool, sizeof(ngx_file_t)); 867 b->file = ngx_pcalloc(r->pool, sizeof(ngx_file_t));
864 if (b->file == NULL) { 868 if (b->file == NULL) {
865 return NGX_HTTP_INTERNAL_SERVER_ERROR; 869 return NGX_HTTP_INTERNAL_SERVER_ERROR;
866 } 870 }
867 871
868 r->header_only = (c->length - c->body_start) == 0;
869
870 rc = ngx_http_send_header(r); 872 rc = ngx_http_send_header(r);
871 873
872 if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) { 874 if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {
873 return rc; 875 return rc;
874 } 876 }
875 877
876 b->file_pos = c->body_start; 878 b->file_pos = c->body_start;
877 b->file_last = c->length; 879 b->file_last = c->length;
878 880
879 b->in_file = 1; 881 b->in_file = (c->length - c->body_start) ? 1: 0;
880 b->last_buf = (r == r->main) ? 1: 0; 882 b->last_buf = (r == r->main) ? 1: 0;
881 b->last_in_chain = 1; 883 b->last_in_chain = 1;
882 884
883 b->file->fd = c->file.fd; 885 b->file->fd = c->file.fd;
884 b->file->name = c->file.name; 886 b->file->name = c->file.name;