comparison src/http/ngx_http_file_cache.c @ 3400:8e407e7c899e

fix a cached zero-length body case
author Igor Sysoev <igor@sysoev.ru>
date Wed, 23 Dec 2009 14:46:45 +0000
parents 479468a7d982
children bbea0b19b608
comparison
equal deleted inserted replaced
3399:ac9c0380337d 3400:8e407e7c899e
781 781
782 782
783 ngx_int_t 783 ngx_int_t
784 ngx_http_cache_send(ngx_http_request_t *r) 784 ngx_http_cache_send(ngx_http_request_t *r)
785 { 785 {
786 off_t size;
787 ngx_int_t rc; 786 ngx_int_t rc;
788 ngx_buf_t *b; 787 ngx_buf_t *b;
789 ngx_chain_t out; 788 ngx_chain_t out;
790 ngx_http_cache_t *c; 789 ngx_http_cache_t *c;
791 790
804 b->file = ngx_pcalloc(r->pool, sizeof(ngx_file_t)); 803 b->file = ngx_pcalloc(r->pool, sizeof(ngx_file_t));
805 if (b->file == NULL) { 804 if (b->file == NULL) {
806 return NGX_HTTP_INTERNAL_SERVER_ERROR; 805 return NGX_HTTP_INTERNAL_SERVER_ERROR;
807 } 806 }
808 807
808 r->header_only = (c->length - c->body_start) == 0;
809
809 rc = ngx_http_send_header(r); 810 rc = ngx_http_send_header(r);
810 811
811 if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) { 812 if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {
812 return rc; 813 return rc;
813 } 814 }
814 815
815 size = c->length - c->body_start;
816 if (size == 0) {
817 return rc;
818 }
819
820 b->file_pos = c->body_start; 816 b->file_pos = c->body_start;
821 b->file_last = c->length; 817 b->file_last = c->length;
822 818
823 b->in_file = size ? 1: 0; 819 b->in_file = 1;
824 b->last_buf = (r == r->main) ? 1: 0; 820 b->last_buf = (r == r->main) ? 1: 0;
825 b->last_in_chain = 1; 821 b->last_in_chain = 1;
826 822
827 b->file->fd = c->file.fd; 823 b->file->fd = c->file.fd;
828 b->file->name = c->file.name; 824 b->file->name = c->file.name;