comparison src/http/modules/ngx_http_range_filter.c @ 42:41ccba1aba45 NGINX_0_1_21

nginx 0.1.21 *) Bugfix: the ngx_http_stub_status_module showed incorrect statistics if "rtsig" method was used or if several worker process ran on SMP. *) Bugfix: nginx could not be built by the icc compiler on Linux or if the zlib-1.2.x library was building from sources. *) Bugfix: nginx could not be built on NetBSD 2.0.
author Igor Sysoev <http://sysoev.ru>
date Tue, 22 Feb 2005 00:00:00 +0300
parents 74b1868dd3cd
children 4989c3d25945
comparison
equal deleted inserted replaced
41:4d8e7a81b3a0 42:41ccba1aba45
103 103
104 static ngx_http_output_header_filter_pt ngx_http_next_header_filter; 104 static ngx_http_output_header_filter_pt ngx_http_next_header_filter;
105 static ngx_http_output_body_filter_pt ngx_http_next_body_filter; 105 static ngx_http_output_body_filter_pt ngx_http_next_body_filter;
106 106
107 107
108 static ngx_int_t ngx_http_range_header_filter(ngx_http_request_t *r) 108 static ngx_int_t
109 ngx_http_range_header_filter(ngx_http_request_t *r)
109 { 110 {
110 u_char *p; 111 u_char *p;
111 size_t len; 112 size_t len;
112 off_t start, end; 113 off_t start, end;
113 ngx_int_t rc; 114 ngx_int_t rc;
114 uint32_t boundary;
115 ngx_uint_t suffix, i; 115 ngx_uint_t suffix, i;
116 ngx_atomic_int_t boundary;
116 ngx_table_elt_t *content_range; 117 ngx_table_elt_t *content_range;
117 ngx_http_range_t *range; 118 ngx_http_range_t *range;
118 ngx_http_range_filter_ctx_t *ctx; 119 ngx_http_range_filter_ctx_t *ctx;
119 120
120 if (r->http_version < NGX_HTTP_VERSION_10 121 if (r->http_version < NGX_HTTP_VERSION_10
326 327
327 ngx_http_create_ctx(r, ctx, ngx_http_range_body_filter_module, 328 ngx_http_create_ctx(r, ctx, ngx_http_range_body_filter_module,
328 sizeof(ngx_http_range_filter_ctx_t), NGX_ERROR); 329 sizeof(ngx_http_range_filter_ctx_t), NGX_ERROR);
329 330
330 331
331 len = sizeof(CRLF "--0123456789" CRLF "Content-Type: ") - 1 332 len = sizeof(CRLF "--") - 1 + NGX_ATOMIC_T_LEN
333 + sizeof(CRLF "Content-Type: ") - 1
332 + r->headers_out.content_type->value.len 334 + r->headers_out.content_type->value.len
333 + sizeof(CRLF "Content-Range: bytes ") - 1; 335 + sizeof(CRLF "Content-Range: bytes ") - 1;
334 336
335 if (r->headers_out.charset.len) { 337 if (r->headers_out.charset.len) {
336 len += sizeof("; charset=") - 1 + r->headers_out.charset.len; 338 len += sizeof("; charset=") - 1 + r->headers_out.charset.len;
338 340
339 if (!(ctx->boundary_header.data = ngx_palloc(r->pool, len))) { 341 if (!(ctx->boundary_header.data = ngx_palloc(r->pool, len))) {
340 return NGX_ERROR; 342 return NGX_ERROR;
341 } 343 }
342 344
343 boundary = (uint32_t) ngx_next_temp_number(0); 345 boundary = ngx_next_temp_number(0);
344 346
345 /* 347 /*
346 * The boundary header of the range: 348 * The boundary header of the range:
347 * CRLF 349 * CRLF
348 * "--0123456789" CRLF 350 * "--0123456789" CRLF
350 * "Content-Range: bytes " 352 * "Content-Range: bytes "
351 */ 353 */
352 354
353 if (r->headers_out.charset.len) { 355 if (r->headers_out.charset.len) {
354 ctx->boundary_header.len = ngx_sprintf(ctx->boundary_header.data, 356 ctx->boundary_header.len = ngx_sprintf(ctx->boundary_header.data,
355 CRLF "--%010ud" CRLF 357 CRLF "--%0muA" CRLF
356 "Content-Type: %V; charset=%V" CRLF 358 "Content-Type: %V; charset=%V" CRLF
357 "Content-Range: bytes ", 359 "Content-Range: bytes ",
358 boundary, 360 boundary,
359 &r->headers_out.content_type->value, 361 &r->headers_out.content_type->value,
360 &r->headers_out.charset) 362 &r->headers_out.charset)
362 364
363 r->headers_out.charset.len = 0; 365 r->headers_out.charset.len = 0;
364 366
365 } else { 367 } else {
366 ctx->boundary_header.len = ngx_sprintf(ctx->boundary_header.data, 368 ctx->boundary_header.len = ngx_sprintf(ctx->boundary_header.data,
367 CRLF "--%010ud" CRLF 369 CRLF "--%0muA" CRLF
368 "Content-Type: %V" CRLF 370 "Content-Type: %V" CRLF
369 "Content-Range: bytes ", 371 "Content-Range: bytes ",
370 boundary, 372 boundary,
371 &r->headers_out.content_type->value) 373 &r->headers_out.content_type->value)
372 - ctx->boundary_header.data; 374 - ctx->boundary_header.data;
373 } 375 }
374 376
375 r->headers_out.content_type->value.data = 377 r->headers_out.content_type->value.data =
376 ngx_palloc(r->pool, sizeof("Content-Type: multipart/byteranges; " 378 ngx_palloc(r->pool,
377 "boundary=0123456789") - 1); 379 sizeof("Content-Type: multipart/byteranges; boundary=") - 1
380 + NGX_ATOMIC_T_LEN);
378 381
379 if (r->headers_out.content_type->value.data == NULL) { 382 if (r->headers_out.content_type->value.data == NULL) {
380 return NGX_ERROR; 383 return NGX_ERROR;
381 } 384 }
382 385
383 /* "Content-Type: multipart/byteranges; boundary=0123456789" */ 386 /* "Content-Type: multipart/byteranges; boundary=0123456789" */
384 387
385 r->headers_out.content_type->value.len = 388 r->headers_out.content_type->value.len =
386 ngx_sprintf(r->headers_out.content_type->value.data, 389 ngx_sprintf(r->headers_out.content_type->value.data,
387 "multipart/byteranges; boundary=%010ud", 390 "multipart/byteranges; boundary=%0muA",
388 boundary) 391 boundary)
389 - r->headers_out.content_type->value.data; 392 - r->headers_out.content_type->value.data;
390 393
394
391 /* the size of the last boundary CRLF "--0123456789--" CRLF */ 395 /* the size of the last boundary CRLF "--0123456789--" CRLF */
392 len = sizeof(CRLF "--0123456789--" CRLF) - 1; 396
397 len = sizeof(CRLF "--") - 1 + NGX_ATOMIC_T_LEN + sizeof("--" CRLF) - 1;
393 398
394 range = r->headers_out.ranges.elts; 399 range = r->headers_out.ranges.elts;
395 for (i = 0; i < r->headers_out.ranges.nelts; i++) { 400 for (i = 0; i < r->headers_out.ranges.nelts; i++) {
396 401
397 /* the size of the range: "SSSS-EEEE/TTTT" CRLF CRLF */ 402 /* the size of the range: "SSSS-EEEE/TTTT" CRLF CRLF */
418 423
419 return ngx_http_next_header_filter(r); 424 return ngx_http_next_header_filter(r);
420 } 425 }
421 426
422 427
423 static ngx_int_t ngx_http_range_body_filter(ngx_http_request_t *r, 428 static ngx_int_t
424 ngx_chain_t *in) 429 ngx_http_range_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
425 { 430 {
426 ngx_uint_t i; 431 ngx_uint_t i;
427 ngx_buf_t *b; 432 ngx_buf_t *b;
428 ngx_chain_t *out, *hcl, *rcl, *dcl, **ll; 433 ngx_chain_t *out, *hcl, *rcl, *dcl, **ll;
429 ngx_http_range_t *range; 434 ngx_http_range_t *range;
523 } 528 }
524 529
525 b->temporary = 1; 530 b->temporary = 1;
526 b->last_buf = 1; 531 b->last_buf = 1;
527 532
528 b->pos = ngx_palloc(r->pool, sizeof(CRLF "--0123456789--" CRLF) - 1); 533 b->pos = ngx_palloc(r->pool, sizeof(CRLF "--") - 1 + NGX_ATOMIC_T_LEN
534 + sizeof("--" CRLF) - 1);
529 if (b->pos == NULL) { 535 if (b->pos == NULL) {
530 return NGX_ERROR; 536 return NGX_ERROR;
531 } 537 }
532 538
533 b->last = ngx_cpymem(b->pos, ctx->boundary_header.data, 4 + 10); 539 b->last = ngx_cpymem(b->pos, ctx->boundary_header.data, 4 + 10);
550 556
551 return ngx_http_next_body_filter(r, in); 557 return ngx_http_next_body_filter(r, in);
552 } 558 }
553 559
554 560
555 static ngx_int_t ngx_http_range_header_filter_init(ngx_cycle_t *cycle) 561 static ngx_int_t
562 ngx_http_range_header_filter_init(ngx_cycle_t *cycle)
556 { 563 {
557 ngx_http_next_header_filter = ngx_http_top_header_filter; 564 ngx_http_next_header_filter = ngx_http_top_header_filter;
558 ngx_http_top_header_filter = ngx_http_range_header_filter; 565 ngx_http_top_header_filter = ngx_http_range_header_filter;
559 566
560 return NGX_OK; 567 return NGX_OK;
561 } 568 }
562 569
563 570
564 static ngx_int_t ngx_http_range_body_filter_init(ngx_cycle_t *cycle) 571 static ngx_int_t
572 ngx_http_range_body_filter_init(ngx_cycle_t *cycle)
565 { 573 {
566 ngx_http_next_body_filter = ngx_http_top_body_filter; 574 ngx_http_next_body_filter = ngx_http_top_body_filter;
567 ngx_http_top_body_filter = ngx_http_range_body_filter; 575 ngx_http_top_body_filter = ngx_http_range_body_filter;
568 576
569 return NGX_OK; 577 return NGX_OK;