comparison src/http/modules/ngx_http_range_filter_module.c @ 2592:3a8a53c0c42f

a prelimiary proxy cache support
author Igor Sysoev <igor@sysoev.ru>
date Mon, 23 Mar 2009 13:14:51 +0000
parents a6d6d762c554
children 896db5a09bd2
comparison
equal deleted inserted replaced
2591:7162ac8d564f 2592:3a8a53c0c42f
197 if (rc == NGX_OK) { 197 if (rc == NGX_OK) {
198 198
199 ngx_http_set_ctx(r, ctx, ngx_http_range_body_filter_module); 199 ngx_http_set_ctx(r, ctx, ngx_http_range_body_filter_module);
200 200
201 r->headers_out.status = NGX_HTTP_PARTIAL_CONTENT; 201 r->headers_out.status = NGX_HTTP_PARTIAL_CONTENT;
202 r->headers_out.status_line.len = 0;
202 203
203 if (ctx->ranges.nelts == 1) { 204 if (ctx->ranges.nelts == 1) {
204 return ngx_http_range_singlepart_header(r, ctx); 205 return ngx_http_range_singlepart_header(r, ctx);
205 } 206 }
206 207
706 707
707 static ngx_int_t 708 static ngx_int_t
708 ngx_http_range_multipart_body(ngx_http_request_t *r, 709 ngx_http_range_multipart_body(ngx_http_request_t *r,
709 ngx_http_range_filter_ctx_t *ctx, ngx_chain_t *in) 710 ngx_http_range_filter_ctx_t *ctx, ngx_chain_t *in)
710 { 711 {
712 off_t body_start;
711 ngx_buf_t *b, *buf; 713 ngx_buf_t *b, *buf;
712 ngx_uint_t i; 714 ngx_uint_t i;
713 ngx_chain_t *out, *hcl, *rcl, *dcl, **ll; 715 ngx_chain_t *out, *hcl, *rcl, *dcl, **ll;
714 ngx_http_range_t *range; 716 ngx_http_range_t *range;
715 717
716 ll = &out; 718 ll = &out;
717 buf = in->buf; 719 buf = in->buf;
718 range = ctx->ranges.elts; 720 range = ctx->ranges.elts;
721
722 #if (NGX_HTTP_CACHE)
723 body_start = r->cached ? r->cache->body_start : 0;
724 #else
725 body_start = 0;
726 #endif
719 727
720 for (i = 0; i < ctx->ranges.nelts; i++) { 728 for (i = 0; i < ctx->ranges.nelts; i++) {
721 729
722 /* 730 /*
723 * The boundary header of the range: 731 * The boundary header of the range:
775 b->memory = buf->memory; 783 b->memory = buf->memory;
776 b->mmap = buf->mmap; 784 b->mmap = buf->mmap;
777 b->file = buf->file; 785 b->file = buf->file;
778 786
779 if (buf->in_file) { 787 if (buf->in_file) {
780 b->file_pos = range[i].start; 788 b->file_pos = body_start + range[i].start;
781 b->file_last = range[i].end; 789 b->file_last = body_start + range[i].end;
782 } 790 }
783 791
784 if (ngx_buf_in_memory(buf)) { 792 if (ngx_buf_in_memory(buf)) {
785 b->pos = buf->start + (size_t) range[i].start; 793 b->pos = buf->start + (size_t) range[i].start;
786 b->last = buf->start + (size_t) range[i].end; 794 b->last = buf->start + (size_t) range[i].end;