comparison src/http/modules/ngx_http_range_filter.c @ 290:87e73f067470

nginx-0.0.2-2004-03-16-10:10:12 import
author Igor Sysoev <igor@sysoev.ru>
date Tue, 16 Mar 2004 07:10:12 +0000
parents 92db0aa1e83f
children a472bfb778b3
comparison
equal deleted inserted replaced
289:0750faf8d7e3 290:87e73f067470
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 int ngx_http_range_filter_init(ngx_cycle_t *cycle); 47 static ngx_int_t ngx_http_range_filter_init(ngx_cycle_t *cycle);
48 48
49 49
50 static ngx_http_module_t ngx_http_range_filter_module_ctx = { 50 static ngx_http_module_t ngx_http_range_filter_module_ctx = {
51 NULL, /* pre conf */ 51 NULL, /* pre conf */
52 52
73 73
74 static ngx_http_output_header_filter_pt ngx_http_next_header_filter; 74 static ngx_http_output_header_filter_pt ngx_http_next_header_filter;
75 static ngx_http_output_body_filter_pt ngx_http_next_body_filter; 75 static ngx_http_output_body_filter_pt ngx_http_next_body_filter;
76 76
77 77
78 static int ngx_http_range_header_filter(ngx_http_request_t *r) 78 static ngx_int_t ngx_http_range_header_filter(ngx_http_request_t *r)
79 { 79 {
80 ngx_int_t rc, boundary, suffix, len, i; 80 ngx_int_t rc;
81 char *p; 81 ngx_uint_t boundary, suffix, i;
82 u_char *p;
83 size_t len;
82 off_t start, end; 84 off_t start, end;
83 ngx_http_range_t *range; 85 ngx_http_range_t *range;
84 ngx_http_range_filter_ctx_t *ctx; 86 ngx_http_range_filter_ctx_t *ctx;
85 87
86 if (r->http_version < NGX_HTTP_VERSION_10 88 if (r->http_version < NGX_HTTP_VERSION_10
233 ngx_test_null(r->headers_out.content_range->value.data, 235 ngx_test_null(r->headers_out.content_range->value.data,
234 ngx_palloc(r->pool, 8 + 20 + 1), 236 ngx_palloc(r->pool, 8 + 20 + 1),
235 NGX_ERROR); 237 NGX_ERROR);
236 238
237 r->headers_out.content_range->value.len = 239 r->headers_out.content_range->value.len =
238 ngx_snprintf(r->headers_out.content_range->value.data, 240 ngx_snprintf((char *) r->headers_out.content_range->value.data,
239 8 + 20 + 1, "bytes */" OFF_T_FMT, 241 8 + 20 + 1, "bytes */" OFF_T_FMT,
240 r->headers_out.content_length_n); 242 r->headers_out.content_length_n);
241 243
242 r->headers_out.content_length_n = -1; 244 r->headers_out.content_length_n = -1;
243 if (r->headers_out.content_length) { 245 if (r->headers_out.content_length) {
244 r->headers_out.content_length->key.len = 0; 246 r->headers_out.content_length->key.len = 0;
245 r->headers_out.content_length = NULL; 247 r->headers_out.content_length = NULL;
266 NGX_ERROR); 268 NGX_ERROR);
267 269
268 /* "Content-Range: bytes SSSS-EEEE/TTTT" header */ 270 /* "Content-Range: bytes SSSS-EEEE/TTTT" header */
269 271
270 r->headers_out.content_range->value.len = 272 r->headers_out.content_range->value.len =
271 ngx_snprintf(r->headers_out.content_range->value.data, 273 ngx_snprintf((char *)
274 r->headers_out.content_range->value.data,
272 6 + 20 + 1 + 20 + 1 + 20 + 1, 275 6 + 20 + 1 + 20 + 1 + 20 + 1,
273 "bytes " OFF_T_FMT "-" OFF_T_FMT "/" OFF_T_FMT, 276 "bytes " OFF_T_FMT "-" OFF_T_FMT "/" OFF_T_FMT,
274 range->start, range->end - 1, 277 range->start, range->end - 1,
275 r->headers_out.content_length_n); 278 r->headers_out.content_length_n);
276 279
311 * "Content-Range: bytes " 314 * "Content-Range: bytes "
312 */ 315 */
313 316
314 if (r->headers_out.charset.len) { 317 if (r->headers_out.charset.len) {
315 ctx->boundary_header.len = 318 ctx->boundary_header.len =
316 ngx_snprintf(ctx->boundary_header.data, len, 319 ngx_snprintf((char *) ctx->boundary_header.data, len,
317 CRLF "--%010u" CRLF 320 CRLF "--%010u" CRLF
318 "Content-Type: %s; charset=%s" CRLF 321 "Content-Type: %s; charset=%s" CRLF
319 "Content-Range: bytes ", 322 "Content-Range: bytes ",
320 boundary, 323 boundary,
321 r->headers_out.content_type->value.data, 324 r->headers_out.content_type->value.data,
323 326
324 r->headers_out.charset.len = 0; 327 r->headers_out.charset.len = 0;
325 328
326 } else { 329 } else {
327 ctx->boundary_header.len = 330 ctx->boundary_header.len =
328 ngx_snprintf(ctx->boundary_header.data, len, 331 ngx_snprintf((char *) ctx->boundary_header.data, len,
329 CRLF "--%010u" CRLF 332 CRLF "--%010u" CRLF
330 "Content-Type: %s" CRLF 333 "Content-Type: %s" CRLF
331 "Content-Range: bytes ", 334 "Content-Range: bytes ",
332 boundary, 335 boundary,
333 r->headers_out.content_type->value.data); 336 r->headers_out.content_type->value.data);
338 NGX_ERROR); 341 NGX_ERROR);
339 342
340 /* "Content-Type: multipart/byteranges; boundary=0123456789" */ 343 /* "Content-Type: multipart/byteranges; boundary=0123456789" */
341 344
342 r->headers_out.content_type->value.len = 345 r->headers_out.content_type->value.len =
343 ngx_snprintf(r->headers_out.content_type->value.data, 346 ngx_snprintf((char *)
347 r->headers_out.content_type->value.data,
344 31 + 10 + 1, 348 31 + 10 + 1,
345 "multipart/byteranges; boundary=%010u", 349 "multipart/byteranges; boundary=%010u",
346 boundary); 350 boundary);
347 351
348 /* the size of the last boundary CRLF "--0123456789--" CRLF */ 352 /* the size of the last boundary CRLF "--0123456789--" CRLF */
355 NGX_ERROR); 359 NGX_ERROR);
356 360
357 /* the size of the range: "SSSS-EEEE/TTTT" CRLF CRLF */ 361 /* the size of the range: "SSSS-EEEE/TTTT" CRLF CRLF */
358 362
359 range[i].content_range.len = 363 range[i].content_range.len =
360 ngx_snprintf(range[i].content_range.data, 364 ngx_snprintf((char *) range[i].content_range.data,
361 20 + 1 + 20 + 1 + 20 + 5, 365 20 + 1 + 20 + 1 + 20 + 5,
362 OFF_T_FMT "-" OFF_T_FMT "/" OFF_T_FMT CRLF CRLF, 366 OFF_T_FMT "-" OFF_T_FMT "/" OFF_T_FMT CRLF CRLF,
363 range[i].start, range[i].end - 1, 367 range[i].start, range[i].end - 1,
364 r->headers_out.content_length_n); 368 r->headers_out.content_length_n);
365 369
374 378
375 return ngx_http_next_header_filter(r); 379 return ngx_http_next_header_filter(r);
376 } 380 }
377 381
378 382
379 static int ngx_http_range_body_filter(ngx_http_request_t *r, ngx_chain_t *in) 383 static ngx_int_t ngx_http_range_body_filter(ngx_http_request_t *r,
384 ngx_chain_t *in)
380 { 385 {
381 int i; 386 ngx_uint_t i;
382 ngx_hunk_t *h; 387 ngx_hunk_t *h;
383 ngx_chain_t *out, *hcl, *rcl, *dcl, **ll; 388 ngx_chain_t *out, *hcl, *rcl, *dcl, **ll;
384 ngx_http_range_t *range; 389 ngx_http_range_t *range;
385 ngx_http_range_filter_ctx_t *ctx; 390 ngx_http_range_filter_ctx_t *ctx;
386 391
473 478
474 return ngx_http_next_body_filter(r, in); 479 return ngx_http_next_body_filter(r, in);
475 } 480 }
476 481
477 482
478 static int ngx_http_range_filter_init(ngx_cycle_t *cycle) 483 static ngx_int_t ngx_http_range_filter_init(ngx_cycle_t *cycle)
479 { 484 {
480 ngx_http_next_header_filter = ngx_http_top_header_filter; 485 ngx_http_next_header_filter = ngx_http_top_header_filter;
481 ngx_http_top_header_filter = ngx_http_range_header_filter; 486 ngx_http_top_header_filter = ngx_http_range_header_filter;
482 487
483 ngx_http_next_body_filter = ngx_http_top_body_filter; 488 ngx_http_next_body_filter = ngx_http_top_body_filter;