comparison src/http/modules/ngx_http_range_filter_module.c @ 517:8fbdd980b527

Merge with current.
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 13 Jul 2009 23:56:24 +0400
parents 44a61c599bb2 499474178a11
children e67b227c8dbb
comparison
equal deleted inserted replaced
424:44a61c599bb2 517:8fbdd980b527
220 if (ctx == NULL) { 220 if (ctx == NULL) {
221 return NGX_ERROR; 221 return NGX_ERROR;
222 } 222 }
223 223
224 if (ngx_array_init(&ctx->ranges, r->pool, 1, sizeof(ngx_http_range_t)) 224 if (ngx_array_init(&ctx->ranges, r->pool, 1, sizeof(ngx_http_range_t))
225 == NGX_ERROR) 225 != NGX_OK)
226 { 226 {
227 return NGX_ERROR; 227 return NGX_ERROR;
228 } 228 }
229 229
230 rc = ngx_http_range_parse(r, ctx); 230 rc = ngx_http_range_parse(r, ctx);
232 if (rc == NGX_OK) { 232 if (rc == NGX_OK) {
233 233
234 ngx_http_set_ctx(r, ctx, ngx_http_range_body_filter_module); 234 ngx_http_set_ctx(r, ctx, ngx_http_range_body_filter_module);
235 235
236 r->headers_out.status = NGX_HTTP_PARTIAL_CONTENT; 236 r->headers_out.status = NGX_HTTP_PARTIAL_CONTENT;
237 r->headers_out.status_line.len = 0;
237 238
238 if (ctx->ranges.nelts == 1) { 239 if (ctx->ranges.nelts == 1) {
239 return ngx_http_range_singlepart_header(r, ctx); 240 return ngx_http_range_singlepart_header(r, ctx);
240 } 241 }
241 242
488 489
489 if (r->headers_out.content_type.data == NULL) { 490 if (r->headers_out.content_type.data == NULL) {
490 return NGX_ERROR; 491 return NGX_ERROR;
491 } 492 }
492 493
494 r->headers_out.content_type_lowcase = NULL;
495
493 /* "Content-Type: multipart/byteranges; boundary=0123456789" */ 496 /* "Content-Type: multipart/byteranges; boundary=0123456789" */
494 497
495 r->headers_out.content_type.len = 498 r->headers_out.content_type.len =
496 ngx_sprintf(r->headers_out.content_type.data, 499 ngx_sprintf(r->headers_out.content_type.data,
497 "multipart/byteranges; boundary=%0muA", 500 "multipart/byteranges; boundary=%0muA",
498 boundary) 501 boundary)
499 - r->headers_out.content_type.data; 502 - r->headers_out.content_type.data;
500 503
504 r->headers_out.content_type_len = r->headers_out.content_type.len;
501 505
502 /* the size of the last boundary CRLF "--0123456789--" CRLF */ 506 /* the size of the last boundary CRLF "--0123456789--" CRLF */
503 507
504 len = sizeof(CRLF "--") - 1 + NGX_ATOMIC_T_LEN + sizeof("--" CRLF) - 1; 508 len = sizeof(CRLF "--") - 1 + NGX_ATOMIC_T_LEN + sizeof("--" CRLF) - 1;
505 509
746 static ngx_int_t 750 static ngx_int_t
747 ngx_http_range_multipart_body(ngx_http_request_t *r, 751 ngx_http_range_multipart_body(ngx_http_request_t *r,
748 ngx_http_range_filter_ctx_t *ctx, ngx_chain_t *in, 752 ngx_http_range_filter_ctx_t *ctx, ngx_chain_t *in,
749 ngx_http_output_body_filter_pt ngx_http_next_body_filter) 753 ngx_http_output_body_filter_pt ngx_http_next_body_filter)
750 { 754 {
755 off_t body_start;
751 ngx_buf_t *b, *buf; 756 ngx_buf_t *b, *buf;
752 ngx_uint_t i; 757 ngx_uint_t i;
753 ngx_chain_t *out, *hcl, *rcl, *dcl, **ll; 758 ngx_chain_t *out, *hcl, *rcl, *dcl, **ll;
754 ngx_http_range_t *range; 759 ngx_http_range_t *range;
755 760
756 ll = &out; 761 ll = &out;
757 buf = in->buf; 762 buf = in->buf;
758 range = ctx->ranges.elts; 763 range = ctx->ranges.elts;
764
765 #if (NGX_HTTP_CACHE)
766 body_start = r->cached ? r->cache->body_start : 0;
767 #else
768 body_start = 0;
769 #endif
759 770
760 for (i = 0; i < ctx->ranges.nelts; i++) { 771 for (i = 0; i < ctx->ranges.nelts; i++) {
761 772
762 /* 773 /*
763 * The boundary header of the range: 774 * The boundary header of the range:
815 b->memory = buf->memory; 826 b->memory = buf->memory;
816 b->mmap = buf->mmap; 827 b->mmap = buf->mmap;
817 b->file = buf->file; 828 b->file = buf->file;
818 829
819 if (buf->in_file) { 830 if (buf->in_file) {
820 b->file_pos = range[i].start; 831 b->file_pos = body_start + range[i].start;
821 b->file_last = range[i].end; 832 b->file_last = body_start + range[i].end;
822 } 833 }
823 834
824 if (ngx_buf_in_memory(buf)) { 835 if (ngx_buf_in_memory(buf)) {
825 b->pos = buf->start + (size_t) range[i].start; 836 b->pos = buf->start + (size_t) range[i].start;
826 b->last = buf->start + (size_t) range[i].end; 837 b->last = buf->start + (size_t) range[i].end;