Mercurial > hg > nginx
comparison src/http/modules/ngx_http_range_filter.c @ 334:af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Wed, 12 May 2004 05:37:55 +0000 |
parents | d71c87d11b16 |
children | d4241d7787fe |
comparison
equal
deleted
inserted
replaced
333:be40e9893a19 | 334:af451db3fe99 |
---|---|
42 typedef struct { | 42 typedef struct { |
43 ngx_str_t boundary_header; | 43 ngx_str_t boundary_header; |
44 } ngx_http_range_filter_ctx_t; | 44 } ngx_http_range_filter_ctx_t; |
45 | 45 |
46 | 46 |
47 static ngx_int_t ngx_http_range_filter_init(ngx_cycle_t *cycle); | 47 static ngx_int_t ngx_http_range_header_filter_init(ngx_cycle_t *cycle); |
48 | 48 static ngx_int_t ngx_http_range_body_filter_init(ngx_cycle_t *cycle); |
49 | 49 |
50 static ngx_http_module_t ngx_http_range_filter_module_ctx = { | 50 |
51 static ngx_http_module_t ngx_http_range_header_filter_module_ctx = { | |
51 NULL, /* pre conf */ | 52 NULL, /* pre conf */ |
52 | 53 |
53 NULL, /* create main configuration */ | 54 NULL, /* create main configuration */ |
54 NULL, /* init main configuration */ | 55 NULL, /* init main configuration */ |
55 | 56 |
59 NULL, /* create location configuration */ | 60 NULL, /* create location configuration */ |
60 NULL, /* merge location configuration */ | 61 NULL, /* merge location configuration */ |
61 }; | 62 }; |
62 | 63 |
63 | 64 |
64 ngx_module_t ngx_http_range_filter_module = { | 65 ngx_module_t ngx_http_range_header_filter_module = { |
65 NGX_MODULE, | 66 NGX_MODULE, |
66 &ngx_http_range_filter_module_ctx, /* module context */ | 67 &ngx_http_range_header_filter_module_ctx, /* module context */ |
67 NULL, /* module directives */ | 68 NULL, /* module directives */ |
68 NGX_HTTP_MODULE, /* module type */ | 69 NGX_HTTP_MODULE, /* module type */ |
69 ngx_http_range_filter_init, /* init module */ | 70 ngx_http_range_header_filter_init, /* init module */ |
71 NULL /* init child */ | |
72 }; | |
73 | |
74 | |
75 static ngx_http_module_t ngx_http_range_body_filter_module_ctx = { | |
76 NULL, /* pre conf */ | |
77 | |
78 NULL, /* create main configuration */ | |
79 NULL, /* init main configuration */ | |
80 | |
81 NULL, /* create server configuration */ | |
82 NULL, /* merge server configuration */ | |
83 | |
84 NULL, /* create location configuration */ | |
85 NULL, /* merge location configuration */ | |
86 }; | |
87 | |
88 | |
89 ngx_module_t ngx_http_range_body_filter_module = { | |
90 NGX_MODULE, | |
91 &ngx_http_range_body_filter_module_ctx, /* module context */ | |
92 NULL, /* module directives */ | |
93 NGX_HTTP_MODULE, /* module type */ | |
94 ngx_http_range_body_filter_init, /* init module */ | |
70 NULL /* init child */ | 95 NULL /* init child */ |
71 }; | 96 }; |
72 | 97 |
73 | 98 |
74 static ngx_http_output_header_filter_pt ngx_http_next_header_filter; | 99 static ngx_http_output_header_filter_pt ngx_http_next_header_filter; |
86 ngx_http_range_filter_ctx_t *ctx; | 111 ngx_http_range_filter_ctx_t *ctx; |
87 | 112 |
88 if (r->http_version < NGX_HTTP_VERSION_10 | 113 if (r->http_version < NGX_HTTP_VERSION_10 |
89 || r->headers_out.status != NGX_HTTP_OK | 114 || r->headers_out.status != NGX_HTTP_OK |
90 || r->headers_out.content_length_n == -1 | 115 || r->headers_out.content_length_n == -1 |
91 | 116 || !(r->filter & NGX_HTTP_FILTER_ALLOW_RANGES)) |
117 | |
118 #if 0 | |
92 /* STUB: we currently support ranges for file hunks only */ | 119 /* STUB: we currently support ranges for file hunks only */ |
93 || !r->sendfile | 120 || !r->sendfile |
94 || r->filter & NGX_HTTP_FILTER_NEED_IN_MEMORY | 121 || r->filter & NGX_HTTP_FILTER_NEED_IN_MEMORY |
95 | 122 #endif |
123 | |
124 #if 0 | |
96 || (r->headers_out.content_encoding | 125 || (r->headers_out.content_encoding |
97 && r->headers_out.content_encoding->value.len)) | 126 && r->headers_out.content_encoding->value.len)) |
127 #endif | |
98 { | 128 { |
99 return ngx_http_next_header_filter(r); | 129 return ngx_http_next_header_filter(r); |
100 } | 130 } |
101 | 131 |
102 if (r->headers_in.range == NULL | 132 if (r->headers_in.range == NULL |
292 { | 322 { |
293 return NGX_ERROR; | 323 return NGX_ERROR; |
294 } | 324 } |
295 #endif | 325 #endif |
296 | 326 |
297 ngx_http_create_ctx(r, ctx, ngx_http_range_filter_module, | 327 ngx_http_create_ctx(r, ctx, ngx_http_range_body_filter_module, |
298 sizeof(ngx_http_range_filter_ctx_t), NGX_ERROR); | 328 sizeof(ngx_http_range_filter_ctx_t), NGX_ERROR); |
299 | 329 |
300 len = 4 + 10 + 2 + 14 + r->headers_out.content_type->value.len | 330 len = 4 + 10 + 2 + 14 + r->headers_out.content_type->value.len |
301 + 2 + 21 + 1; | 331 + 2 + 21 + 1; |
302 | 332 |
412 in->hunk->file_last = range->end; | 442 in->hunk->file_last = range->end; |
413 | 443 |
414 return ngx_http_next_body_filter(r, in); | 444 return ngx_http_next_body_filter(r, in); |
415 } | 445 } |
416 | 446 |
417 ctx = ngx_http_get_module_ctx(r, ngx_http_range_filter_module); | 447 ctx = ngx_http_get_module_ctx(r, ngx_http_range_body_filter_module); |
418 ll = &out; | 448 ll = &out; |
419 | 449 |
420 for (i = 0; i < r->headers_out.ranges.nelts; i++) { | 450 for (i = 0; i < r->headers_out.ranges.nelts; i++) { |
421 | 451 |
422 /* | 452 /* |
481 | 511 |
482 return ngx_http_next_body_filter(r, in); | 512 return ngx_http_next_body_filter(r, in); |
483 } | 513 } |
484 | 514 |
485 | 515 |
486 static ngx_int_t ngx_http_range_filter_init(ngx_cycle_t *cycle) | 516 static ngx_int_t ngx_http_range_header_filter_init(ngx_cycle_t *cycle) |
487 { | 517 { |
488 ngx_http_next_header_filter = ngx_http_top_header_filter; | 518 ngx_http_next_header_filter = ngx_http_top_header_filter; |
489 ngx_http_top_header_filter = ngx_http_range_header_filter; | 519 ngx_http_top_header_filter = ngx_http_range_header_filter; |
490 | 520 |
521 return NGX_OK; | |
522 } | |
523 | |
524 | |
525 static ngx_int_t ngx_http_range_body_filter_init(ngx_cycle_t *cycle) | |
526 { | |
491 ngx_http_next_body_filter = ngx_http_top_body_filter; | 527 ngx_http_next_body_filter = ngx_http_top_body_filter; |
492 ngx_http_top_body_filter = ngx_http_range_body_filter; | 528 ngx_http_top_body_filter = ngx_http_range_body_filter; |
493 | 529 |
494 return NGX_OK; | 530 return NGX_OK; |
495 } | 531 } |