Mercurial > hg > nginx-quic
annotate src/http/modules/ngx_http_range_filter_module.c @ 2235:03180d4e5af2
ngx_http_random_index_module
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Fri, 05 Sep 2008 15:45:55 +0000 |
parents | b39c0040b3e4 |
children | 7155dbb2317e |
rev | line source |
---|---|
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
416
diff
changeset
|
1 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
416
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
416
diff
changeset
|
4 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
416
diff
changeset
|
5 |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
6 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 #include <ngx_config.h> |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_core.h> |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 #include <ngx_http.h> |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
12 /* |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
13 * the single part format: |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
14 * |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
15 * "HTTP/1.0 206 Partial Content" CRLF |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
16 * ... header ... |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
17 * "Content-Type: image/jpeg" CRLF |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
18 * "Content-Length: SIZE" CRLF |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
19 * "Content-Range: bytes START-END/SIZE" CRLF |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
20 * CRLF |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
21 * ... data ... |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
22 * |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
23 * |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
24 * the mutlipart format: |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
25 * |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
26 * "HTTP/1.0 206 Partial Content" CRLF |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
27 * ... header ... |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
28 * "Content-Type: multipart/byteranges; boundary=0123456789" CRLF |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
29 * CRLF |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
30 * CRLF |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
31 * "--0123456789" CRLF |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
32 * "Content-Type: image/jpeg" CRLF |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
33 * "Content-Range: bytes START0-END0/SIZE" CRLF |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
34 * CRLF |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
35 * ... data ... |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
36 * CRLF |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
37 * "--0123456789" CRLF |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
38 * "Content-Type: image/jpeg" CRLF |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
39 * "Content-Range: bytes START1-END1/SIZE" CRLF |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
40 * CRLF |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
41 * ... data ... |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
42 * CRLF |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
43 * "--0123456789--" CRLF |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
44 */ |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
45 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
46 |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
47 typedef struct { |
963
78e70dae89f0
move ranges array to ngx_http_range_filter_ctx_t
Igor Sysoev <igor@sysoev.ru>
parents:
962
diff
changeset
|
48 off_t start; |
78e70dae89f0
move ranges array to ngx_http_range_filter_ctx_t
Igor Sysoev <igor@sysoev.ru>
parents:
962
diff
changeset
|
49 off_t end; |
78e70dae89f0
move ranges array to ngx_http_range_filter_ctx_t
Igor Sysoev <igor@sysoev.ru>
parents:
962
diff
changeset
|
50 ngx_str_t content_range; |
78e70dae89f0
move ranges array to ngx_http_range_filter_ctx_t
Igor Sysoev <igor@sysoev.ru>
parents:
962
diff
changeset
|
51 } ngx_http_range_t; |
78e70dae89f0
move ranges array to ngx_http_range_filter_ctx_t
Igor Sysoev <igor@sysoev.ru>
parents:
962
diff
changeset
|
52 |
78e70dae89f0
move ranges array to ngx_http_range_filter_ctx_t
Igor Sysoev <igor@sysoev.ru>
parents:
962
diff
changeset
|
53 |
78e70dae89f0
move ranges array to ngx_http_range_filter_ctx_t
Igor Sysoev <igor@sysoev.ru>
parents:
962
diff
changeset
|
54 typedef struct { |
78e70dae89f0
move ranges array to ngx_http_range_filter_ctx_t
Igor Sysoev <igor@sysoev.ru>
parents:
962
diff
changeset
|
55 off_t offset; |
78e70dae89f0
move ranges array to ngx_http_range_filter_ctx_t
Igor Sysoev <igor@sysoev.ru>
parents:
962
diff
changeset
|
56 ngx_str_t boundary_header; |
78e70dae89f0
move ranges array to ngx_http_range_filter_ctx_t
Igor Sysoev <igor@sysoev.ru>
parents:
962
diff
changeset
|
57 ngx_array_t ranges; |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
58 } ngx_http_range_filter_ctx_t; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
59 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
60 |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
61 ngx_int_t ngx_http_range_parse(ngx_http_request_t *r, |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
62 ngx_http_range_filter_ctx_t *ctx); |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
63 static ngx_int_t ngx_http_range_singlepart_header(ngx_http_request_t *r, |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
64 ngx_http_range_filter_ctx_t *ctx); |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
65 static ngx_int_t ngx_http_range_multipart_header(ngx_http_request_t *r, |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
66 ngx_http_range_filter_ctx_t *ctx); |
2121
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
67 static ngx_int_t ngx_http_range_not_satisfiable(ngx_http_request_t *r); |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
68 static ngx_int_t ngx_http_range_test_overlapped(ngx_http_request_t *r, |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
69 ngx_http_range_filter_ctx_t *ctx, ngx_chain_t *in); |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
70 static ngx_int_t ngx_http_range_singlepart_body(ngx_http_request_t *r, |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
71 ngx_http_range_filter_ctx_t *ctx, ngx_chain_t *in); |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
72 static ngx_int_t ngx_http_range_multipart_body(ngx_http_request_t *r, |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
73 ngx_http_range_filter_ctx_t *ctx, ngx_chain_t *in); |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
74 |
681 | 75 static ngx_int_t ngx_http_range_header_filter_init(ngx_conf_t *cf); |
76 static ngx_int_t ngx_http_range_body_filter_init(ngx_conf_t *cf); | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
77 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
78 |
334
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
314
diff
changeset
|
79 static ngx_http_module_t ngx_http_range_header_filter_module_ctx = { |
509 | 80 NULL, /* preconfiguration */ |
681 | 81 ngx_http_range_header_filter_init, /* postconfiguration */ |
177
4db54fdbcbe7
nginx-0.0.1-2003-11-10-20:17:31 import
Igor Sysoev <igor@sysoev.ru>
parents:
165
diff
changeset
|
82 |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
83 NULL, /* create main configuration */ |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
84 NULL, /* init main configuration */ |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
85 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
86 NULL, /* create server configuration */ |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
87 NULL, /* merge server configuration */ |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
88 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
89 NULL, /* create location configuration */ |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
90 NULL, /* merge location configuration */ |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
91 }; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
92 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
93 |
334
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
314
diff
changeset
|
94 ngx_module_t ngx_http_range_header_filter_module = { |
509 | 95 NGX_MODULE_V1, |
334
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
314
diff
changeset
|
96 &ngx_http_range_header_filter_module_ctx, /* module context */ |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
97 NULL, /* module directives */ |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
98 NGX_HTTP_MODULE, /* module type */ |
541 | 99 NULL, /* init master */ |
681 | 100 NULL, /* init module */ |
541 | 101 NULL, /* init process */ |
102 NULL, /* init thread */ | |
103 NULL, /* exit thread */ | |
104 NULL, /* exit process */ | |
105 NULL, /* exit master */ | |
106 NGX_MODULE_V1_PADDING | |
334
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
314
diff
changeset
|
107 }; |
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
314
diff
changeset
|
108 |
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
314
diff
changeset
|
109 |
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
314
diff
changeset
|
110 static ngx_http_module_t ngx_http_range_body_filter_module_ctx = { |
509 | 111 NULL, /* preconfiguration */ |
681 | 112 ngx_http_range_body_filter_init, /* postconfiguration */ |
334
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
314
diff
changeset
|
113 |
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
314
diff
changeset
|
114 NULL, /* create main configuration */ |
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
314
diff
changeset
|
115 NULL, /* init main configuration */ |
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
314
diff
changeset
|
116 |
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
314
diff
changeset
|
117 NULL, /* create server configuration */ |
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
314
diff
changeset
|
118 NULL, /* merge server configuration */ |
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
314
diff
changeset
|
119 |
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
314
diff
changeset
|
120 NULL, /* create location configuration */ |
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
314
diff
changeset
|
121 NULL, /* merge location configuration */ |
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
314
diff
changeset
|
122 }; |
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
314
diff
changeset
|
123 |
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
314
diff
changeset
|
124 |
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
314
diff
changeset
|
125 ngx_module_t ngx_http_range_body_filter_module = { |
509 | 126 NGX_MODULE_V1, |
334
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
314
diff
changeset
|
127 &ngx_http_range_body_filter_module_ctx, /* module context */ |
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
314
diff
changeset
|
128 NULL, /* module directives */ |
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
314
diff
changeset
|
129 NGX_HTTP_MODULE, /* module type */ |
541 | 130 NULL, /* init master */ |
681 | 131 NULL, /* init module */ |
541 | 132 NULL, /* init process */ |
133 NULL, /* init thread */ | |
134 NULL, /* exit thread */ | |
135 NULL, /* exit process */ | |
136 NULL, /* exit master */ | |
137 NGX_MODULE_V1_PADDING | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
138 }; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
139 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
140 |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
153
diff
changeset
|
141 static ngx_http_output_header_filter_pt ngx_http_next_header_filter; |
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
153
diff
changeset
|
142 static ngx_http_output_body_filter_pt ngx_http_next_body_filter; |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
143 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
144 |
493 | 145 static ngx_int_t |
146 ngx_http_range_header_filter(ngx_http_request_t *r) | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
147 { |
1630 | 148 time_t if_range; |
461 | 149 ngx_int_t rc; |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
150 ngx_http_range_filter_ctx_t *ctx; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
151 |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
152 if (r->http_version < NGX_HTTP_VERSION_10 |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
153 || r->headers_out.status != NGX_HTTP_OK |
597 | 154 || r != r->main |
153
c71aeb75c071
nginx-0.0.1-2003-10-21-20:49:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
136
diff
changeset
|
155 || r->headers_out.content_length_n == -1 |
581 | 156 || !r->allow_ranges) |
117
f6e3c5d019b6
nginx-0.0.1-2003-07-11-19:17:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
113
diff
changeset
|
157 { |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
153
diff
changeset
|
158 return ngx_http_next_header_filter(r); |
117
f6e3c5d019b6
nginx-0.0.1-2003-07-11-19:17:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
113
diff
changeset
|
159 } |
f6e3c5d019b6
nginx-0.0.1-2003-07-11-19:17:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
113
diff
changeset
|
160 |
f6e3c5d019b6
nginx-0.0.1-2003-07-11-19:17:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
113
diff
changeset
|
161 if (r->headers_in.range == NULL |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
162 || r->headers_in.range->value.len < 7 |
1107
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1093
diff
changeset
|
163 || ngx_strncasecmp(r->headers_in.range->value.data, |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1093
diff
changeset
|
164 (u_char *) "bytes=", 6) |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1093
diff
changeset
|
165 != 0) |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
166 { |
1630 | 167 goto next_filter; |
168 } | |
169 | |
170 if (r->headers_in.if_range && r->headers_out.last_modified_time != -1) { | |
171 | |
172 if_range = ngx_http_parse_time(r->headers_in.if_range->value.data, | |
173 r->headers_in.if_range->value.len); | |
117
f6e3c5d019b6
nginx-0.0.1-2003-07-11-19:17:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
113
diff
changeset
|
174 |
1630 | 175 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
176 "http ir:%d lm:%d", | |
177 if_range, r->headers_out.last_modified_time); | |
117
f6e3c5d019b6
nginx-0.0.1-2003-07-11-19:17:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
113
diff
changeset
|
178 |
1630 | 179 if (if_range != r->headers_out.last_modified_time) { |
180 goto next_filter; | |
181 } | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
182 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
183 |
963
78e70dae89f0
move ranges array to ngx_http_range_filter_ctx_t
Igor Sysoev <igor@sysoev.ru>
parents:
962
diff
changeset
|
184 ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_range_filter_ctx_t)); |
78e70dae89f0
move ranges array to ngx_http_range_filter_ctx_t
Igor Sysoev <igor@sysoev.ru>
parents:
962
diff
changeset
|
185 if (ctx == NULL) { |
78e70dae89f0
move ranges array to ngx_http_range_filter_ctx_t
Igor Sysoev <igor@sysoev.ru>
parents:
962
diff
changeset
|
186 return NGX_ERROR; |
78e70dae89f0
move ranges array to ngx_http_range_filter_ctx_t
Igor Sysoev <igor@sysoev.ru>
parents:
962
diff
changeset
|
187 } |
78e70dae89f0
move ranges array to ngx_http_range_filter_ctx_t
Igor Sysoev <igor@sysoev.ru>
parents:
962
diff
changeset
|
188 |
78e70dae89f0
move ranges array to ngx_http_range_filter_ctx_t
Igor Sysoev <igor@sysoev.ru>
parents:
962
diff
changeset
|
189 if (ngx_array_init(&ctx->ranges, r->pool, 1, sizeof(ngx_http_range_t)) |
959 | 190 == NGX_ERROR) |
461 | 191 { |
192 return NGX_ERROR; | |
193 } | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
194 |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
195 rc = ngx_http_range_parse(r, ctx); |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
196 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
197 if (rc == NGX_OK) { |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
198 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
199 ngx_http_set_ctx(r, ctx, ngx_http_range_body_filter_module); |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
200 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
201 r->headers_out.status = NGX_HTTP_PARTIAL_CONTENT; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
202 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
203 if (ctx->ranges.nelts == 1) { |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
204 return ngx_http_range_singlepart_header(r, ctx); |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
205 } |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
206 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
207 return ngx_http_range_multipart_header(r, ctx); |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
208 } |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
209 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
210 if (rc == NGX_HTTP_RANGE_NOT_SATISFIABLE) { |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
211 return ngx_http_range_not_satisfiable(r); |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
212 } |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
213 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
214 /* rc == NGX_ERROR */ |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
215 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
216 return rc; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
217 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
218 next_filter: |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
219 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
220 r->headers_out.accept_ranges = ngx_list_push(&r->headers_out.headers); |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
221 if (r->headers_out.accept_ranges == NULL) { |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
222 return NGX_ERROR; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
223 } |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
224 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
225 r->headers_out.accept_ranges->hash = 1; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
226 r->headers_out.accept_ranges->key.len = sizeof("Accept-Ranges") - 1; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
227 r->headers_out.accept_ranges->key.data = (u_char *) "Accept-Ranges"; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
228 r->headers_out.accept_ranges->value.len = sizeof("bytes") - 1; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
229 r->headers_out.accept_ranges->value.data = (u_char *) "bytes"; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
230 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
231 return ngx_http_next_header_filter(r); |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
232 } |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
233 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
234 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
235 ngx_int_t |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
236 ngx_http_range_parse(ngx_http_request_t *r, ngx_http_range_filter_ctx_t *ctx) |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
237 { |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
238 u_char *p; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
239 off_t start, end; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
240 ngx_uint_t suffix; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
241 ngx_http_range_t *range; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
242 |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
243 p = r->headers_in.range->value.data + 6; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
244 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
245 for ( ;; ) { |
231
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
246 start = 0; |
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
247 end = 0; |
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
248 suffix = 0; |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
249 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
250 while (*p == ' ') { p++; } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
251 |
231
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
252 if (*p != '-') { |
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
253 if (*p < '0' || *p > '9') { |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
254 return NGX_HTTP_RANGE_NOT_SATISFIABLE; |
231
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
255 } |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
256 |
231
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
257 while (*p >= '0' && *p <= '9') { |
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
258 start = start * 10 + *p++ - '0'; |
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
259 } |
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
260 |
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
261 while (*p == ' ') { p++; } |
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
262 |
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
263 if (*p++ != '-') { |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
264 return NGX_HTTP_RANGE_NOT_SATISFIABLE; |
231
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
265 } |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
266 |
231
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
267 if (start >= r->headers_out.content_length_n) { |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
268 return NGX_HTTP_RANGE_NOT_SATISFIABLE; |
231
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
269 } |
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
270 |
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
271 while (*p == ' ') { p++; } |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
272 |
231
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
273 if (*p == ',' || *p == '\0') { |
963
78e70dae89f0
move ranges array to ngx_http_range_filter_ctx_t
Igor Sysoev <igor@sysoev.ru>
parents:
962
diff
changeset
|
274 range = ngx_array_push(&ctx->ranges); |
501 | 275 if (range == NULL) { |
461 | 276 return NGX_ERROR; |
277 } | |
278 | |
231
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
279 range->start = start; |
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
280 range->end = r->headers_out.content_length_n; |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
281 |
231
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
282 if (*p++ != ',') { |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
283 return NGX_OK; |
231
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
284 } |
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
285 |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
286 continue; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
287 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
288 |
231
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
289 } else { |
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
290 suffix = 1; |
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
291 p++; |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
292 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
293 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
294 if (*p < '0' || *p > '9') { |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
295 return NGX_HTTP_RANGE_NOT_SATISFIABLE; |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
296 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
297 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
298 while (*p >= '0' && *p <= '9') { |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
299 end = end * 10 + *p++ - '0'; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
300 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
301 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
302 while (*p == ' ') { p++; } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
303 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
304 if (*p != ',' && *p != '\0') { |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
305 return NGX_HTTP_RANGE_NOT_SATISFIABLE; |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
306 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
307 |
231
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
308 if (suffix) { |
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
309 start = r->headers_out.content_length_n - end; |
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
310 end = r->headers_out.content_length_n - 1; |
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
311 } |
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
312 |
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
313 if (start > end) { |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
314 return NGX_HTTP_RANGE_NOT_SATISFIABLE; |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
315 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
316 |
963
78e70dae89f0
move ranges array to ngx_http_range_filter_ctx_t
Igor Sysoev <igor@sysoev.ru>
parents:
962
diff
changeset
|
317 range = ngx_array_push(&ctx->ranges); |
501 | 318 if (range == NULL) { |
461 | 319 return NGX_ERROR; |
320 } | |
321 | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
322 range->start = start; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
323 |
231
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
324 if (end >= r->headers_out.content_length_n) { |
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
325 /* |
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
326 * Download Accelerator sends the last byte position |
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
327 * that equals to the file length |
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
328 */ |
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
329 range->end = r->headers_out.content_length_n; |
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
330 |
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
331 } else { |
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
332 range->end = end + 1; |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
333 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
334 |
231
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
335 if (*p++ != ',') { |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
336 return NGX_OK; |
231
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
337 } |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
338 } |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
339 } |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
340 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
341 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
342 static ngx_int_t |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
343 ngx_http_range_singlepart_header(ngx_http_request_t *r, |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
344 ngx_http_range_filter_ctx_t *ctx) |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
345 { |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
346 ngx_table_elt_t *content_range; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
347 ngx_http_range_t *range; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
348 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
349 content_range = ngx_list_push(&r->headers_out.headers); |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
350 if (content_range == NULL) { |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
351 return NGX_ERROR; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
352 } |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
353 |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
354 r->headers_out.content_range = content_range; |
461 | 355 |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
356 content_range->hash = 1; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
357 content_range->key.len = sizeof("Content-Range") - 1; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
358 content_range->key.data = (u_char *) "Content-Range"; |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
359 |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
360 content_range->value.data = ngx_pnalloc(r->pool, |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
361 sizeof("bytes -/") - 1 + 3 * NGX_OFF_T_LEN); |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
362 if (content_range->value.data == NULL) { |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
363 return NGX_ERROR; |
461 | 364 } |
365 | |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
366 /* "Content-Range: bytes SSSS-EEEE/TTTT" header */ |
461 | 367 |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
368 range = ctx->ranges.elts; |
461 | 369 |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
370 content_range->value.len = ngx_sprintf(content_range->value.data, |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
371 "bytes %O-%O/%O", |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
372 range->start, range->end - 1, |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
373 r->headers_out.content_length_n) |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
374 - content_range->value.data; |
461 | 375 |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
376 r->headers_out.content_length_n = range->end - range->start; |
461 | 377 |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
378 if (r->headers_out.content_length) { |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
379 r->headers_out.content_length->hash = 0; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
380 r->headers_out.content_length = NULL; |
461 | 381 } |
382 | |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
383 return ngx_http_next_header_filter(r); |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
384 } |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
385 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
386 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
387 static ngx_int_t |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
388 ngx_http_range_multipart_header(ngx_http_request_t *r, |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
389 ngx_http_range_filter_ctx_t *ctx) |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
390 { |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
391 size_t len; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
392 ngx_uint_t i; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
393 ngx_http_range_t *range; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
394 ngx_atomic_uint_t boundary; |
461 | 395 |
493 | 396 len = sizeof(CRLF "--") - 1 + NGX_ATOMIC_T_LEN |
397 + sizeof(CRLF "Content-Type: ") - 1 | |
509 | 398 + r->headers_out.content_type.len |
461 | 399 + sizeof(CRLF "Content-Range: bytes ") - 1; |
400 | |
401 if (r->headers_out.charset.len) { | |
402 len += sizeof("; charset=") - 1 + r->headers_out.charset.len; | |
403 } | |
404 | |
2049 | 405 ctx->boundary_header.data = ngx_pnalloc(r->pool, len); |
501 | 406 if (ctx->boundary_header.data == NULL) { |
461 | 407 return NGX_ERROR; |
408 } | |
409 | |
493 | 410 boundary = ngx_next_temp_number(0); |
461 | 411 |
412 /* | |
413 * The boundary header of the range: | |
414 * CRLF | |
415 * "--0123456789" CRLF | |
416 * "Content-Type: image/jpeg" CRLF | |
417 * "Content-Range: bytes " | |
418 */ | |
419 | |
420 if (r->headers_out.charset.len) { | |
421 ctx->boundary_header.len = ngx_sprintf(ctx->boundary_header.data, | |
493 | 422 CRLF "--%0muA" CRLF |
461 | 423 "Content-Type: %V; charset=%V" CRLF |
424 "Content-Range: bytes ", | |
425 boundary, | |
509 | 426 &r->headers_out.content_type, |
461 | 427 &r->headers_out.charset) |
428 - ctx->boundary_header.data; | |
429 | |
430 r->headers_out.charset.len = 0; | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
431 |
2119
0799703985ef
fix ranges without Content-Type
Igor Sysoev <igor@sysoev.ru>
parents:
2118
diff
changeset
|
432 } else if (r->headers_out.content_type.len) { |
461 | 433 ctx->boundary_header.len = ngx_sprintf(ctx->boundary_header.data, |
493 | 434 CRLF "--%0muA" CRLF |
461 | 435 "Content-Type: %V" CRLF |
436 "Content-Range: bytes ", | |
437 boundary, | |
509 | 438 &r->headers_out.content_type) |
461 | 439 - ctx->boundary_header.data; |
2119
0799703985ef
fix ranges without Content-Type
Igor Sysoev <igor@sysoev.ru>
parents:
2118
diff
changeset
|
440 |
0799703985ef
fix ranges without Content-Type
Igor Sysoev <igor@sysoev.ru>
parents:
2118
diff
changeset
|
441 } else { |
0799703985ef
fix ranges without Content-Type
Igor Sysoev <igor@sysoev.ru>
parents:
2118
diff
changeset
|
442 ctx->boundary_header.len = ngx_sprintf(ctx->boundary_header.data, |
0799703985ef
fix ranges without Content-Type
Igor Sysoev <igor@sysoev.ru>
parents:
2118
diff
changeset
|
443 CRLF "--%0muA" CRLF |
0799703985ef
fix ranges without Content-Type
Igor Sysoev <igor@sysoev.ru>
parents:
2118
diff
changeset
|
444 "Content-Range: bytes ", |
0799703985ef
fix ranges without Content-Type
Igor Sysoev <igor@sysoev.ru>
parents:
2118
diff
changeset
|
445 boundary) |
0799703985ef
fix ranges without Content-Type
Igor Sysoev <igor@sysoev.ru>
parents:
2118
diff
changeset
|
446 - ctx->boundary_header.data; |
461 | 447 } |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
448 |
509 | 449 r->headers_out.content_type.data = |
2049 | 450 ngx_pnalloc(r->pool, |
451 sizeof("Content-Type: multipart/byteranges; boundary=") - 1 | |
452 + NGX_ATOMIC_T_LEN); | |
165
894a01c6aea3
nginx-0.0.1-2003-10-29-20:39:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
164
diff
changeset
|
453 |
509 | 454 if (r->headers_out.content_type.data == NULL) { |
461 | 455 return NGX_ERROR; |
456 } | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
457 |
461 | 458 /* "Content-Type: multipart/byteranges; boundary=0123456789" */ |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
459 |
509 | 460 r->headers_out.content_type.len = |
461 ngx_sprintf(r->headers_out.content_type.data, | |
493 | 462 "multipart/byteranges; boundary=%0muA", |
461 | 463 boundary) |
509 | 464 - r->headers_out.content_type.data; |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
465 |
493 | 466 |
461 | 467 /* the size of the last boundary CRLF "--0123456789--" CRLF */ |
493 | 468 |
469 len = sizeof(CRLF "--") - 1 + NGX_ATOMIC_T_LEN + sizeof("--" CRLF) - 1; | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
470 |
963
78e70dae89f0
move ranges array to ngx_http_range_filter_ctx_t
Igor Sysoev <igor@sysoev.ru>
parents:
962
diff
changeset
|
471 range = ctx->ranges.elts; |
78e70dae89f0
move ranges array to ngx_http_range_filter_ctx_t
Igor Sysoev <igor@sysoev.ru>
parents:
962
diff
changeset
|
472 for (i = 0; i < ctx->ranges.nelts; i++) { |
455 | 473 |
461 | 474 /* the size of the range: "SSSS-EEEE/TTTT" CRLF CRLF */ |
455 | 475 |
461 | 476 range[i].content_range.data = |
2049 | 477 ngx_pnalloc(r->pool, 3 * NGX_OFF_T_LEN + 2 + 4); |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
478 |
461 | 479 if (range[i].content_range.data == NULL) { |
480 return NGX_ERROR; | |
481 } | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
482 |
461 | 483 range[i].content_range.len = ngx_sprintf(range[i].content_range.data, |
484 "%O-%O/%O" CRLF CRLF, | |
485 range[i].start, range[i].end - 1, | |
486 r->headers_out.content_length_n) | |
487 - range[i].content_range.data; | |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
488 |
461 | 489 len += ctx->boundary_header.len + range[i].content_range.len |
490 + (size_t) (range[i].end - range[i].start); | |
491 } | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
492 |
461 | 493 r->headers_out.content_length_n = len; |
960 | 494 |
495 if (r->headers_out.content_length) { | |
496 r->headers_out.content_length->hash = 0; | |
497 r->headers_out.content_length = NULL; | |
498 } | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
499 |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
153
diff
changeset
|
500 return ngx_http_next_header_filter(r); |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
501 } |
1630 | 502 |
503 | |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
504 static ngx_int_t |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
505 ngx_http_range_not_satisfiable(ngx_http_request_t *r) |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
506 { |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
507 ngx_table_elt_t *content_range; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
508 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
509 r->headers_out.status = NGX_HTTP_RANGE_NOT_SATISFIABLE; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
510 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
511 content_range = ngx_list_push(&r->headers_out.headers); |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
512 if (content_range == NULL) { |
1630 | 513 return NGX_ERROR; |
514 } | |
515 | |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
516 r->headers_out.content_range = content_range; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
517 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
518 content_range->hash = 1; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
519 content_range->key.len = sizeof("Content-Range") - 1; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
520 content_range->key.data = (u_char *) "Content-Range"; |
1630 | 521 |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
522 content_range->value.data = ngx_pnalloc(r->pool, |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
523 sizeof("bytes */") - 1 + NGX_OFF_T_LEN); |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
524 if (content_range->value.data == NULL) { |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
525 return NGX_ERROR; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
526 } |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
527 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
528 content_range->value.len = ngx_sprintf(content_range->value.data, |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
529 "bytes */%O", |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
530 r->headers_out.content_length_n) |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
531 - content_range->value.data; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
532 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
533 ngx_http_clear_content_length(r); |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
534 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
535 return NGX_HTTP_RANGE_NOT_SATISFIABLE; |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
536 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
537 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
538 |
493 | 539 static ngx_int_t |
540 ngx_http_range_body_filter(ngx_http_request_t *r, ngx_chain_t *in) | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
541 { |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
542 ngx_http_range_filter_ctx_t *ctx; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
543 |
963
78e70dae89f0
move ranges array to ngx_http_range_filter_ctx_t
Igor Sysoev <igor@sysoev.ru>
parents:
962
diff
changeset
|
544 if (in == NULL) { |
78e70dae89f0
move ranges array to ngx_http_range_filter_ctx_t
Igor Sysoev <igor@sysoev.ru>
parents:
962
diff
changeset
|
545 return ngx_http_next_body_filter(r, in); |
78e70dae89f0
move ranges array to ngx_http_range_filter_ctx_t
Igor Sysoev <igor@sysoev.ru>
parents:
962
diff
changeset
|
546 } |
78e70dae89f0
move ranges array to ngx_http_range_filter_ctx_t
Igor Sysoev <igor@sysoev.ru>
parents:
962
diff
changeset
|
547 |
78e70dae89f0
move ranges array to ngx_http_range_filter_ctx_t
Igor Sysoev <igor@sysoev.ru>
parents:
962
diff
changeset
|
548 ctx = ngx_http_get_module_ctx(r, ngx_http_range_body_filter_module); |
78e70dae89f0
move ranges array to ngx_http_range_filter_ctx_t
Igor Sysoev <igor@sysoev.ru>
parents:
962
diff
changeset
|
549 |
78e70dae89f0
move ranges array to ngx_http_range_filter_ctx_t
Igor Sysoev <igor@sysoev.ru>
parents:
962
diff
changeset
|
550 if (ctx == NULL) { |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
153
diff
changeset
|
551 return ngx_http_next_body_filter(r, in); |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
552 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
553 |
2121
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
554 if (ctx->ranges.nelts == 1) { |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
555 return ngx_http_range_singlepart_body(r, ctx, in); |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
556 } |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
557 |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
558 /* |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
559 * multipart ranges are supported only if whole body is in a single buffer |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
560 */ |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
561 |
962
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
562 if (ngx_buf_special(in->buf)) { |
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
563 return ngx_http_next_body_filter(r, in); |
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
564 } |
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
565 |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
566 if (ngx_http_range_test_overlapped(r, ctx, in) != NGX_OK) { |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
567 return NGX_ERROR; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
568 } |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
569 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
570 return ngx_http_range_multipart_body(r, ctx, in); |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
571 } |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
572 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
573 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
574 static ngx_int_t |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
575 ngx_http_range_test_overlapped(ngx_http_request_t *r, |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
576 ngx_http_range_filter_ctx_t *ctx, ngx_chain_t *in) |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
577 { |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
578 off_t start, last; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
579 ngx_buf_t *buf; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
580 ngx_uint_t i; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
581 ngx_http_range_t *range; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
582 |
962
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
583 if (ctx->offset) { |
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
584 goto overlapped; |
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
585 } |
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
586 |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
587 buf = in->buf; |
960 | 588 |
589 if (!buf->last_buf) { | |
962
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
590 |
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
591 if (buf->in_file) { |
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
592 start = buf->file_pos + ctx->offset; |
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
593 last = buf->file_last + ctx->offset; |
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
594 |
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
595 } else { |
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
596 start = buf->pos - buf->start + ctx->offset; |
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
597 last = buf->last - buf->start + ctx->offset; |
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
598 } |
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
599 |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
600 range = ctx->ranges.elts; |
963
78e70dae89f0
move ranges array to ngx_http_range_filter_ctx_t
Igor Sysoev <igor@sysoev.ru>
parents:
962
diff
changeset
|
601 for (i = 0; i < ctx->ranges.nelts; i++) { |
962
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
602 if (start > range[i].start || last < range[i].end) { |
960 | 603 goto overlapped; |
604 } | |
605 } | |
606 } | |
607 | |
962
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
608 ctx->offset = ngx_buf_size(buf); |
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
609 |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
610 return NGX_OK; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
611 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
612 overlapped: |
960 | 613 |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
614 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
615 "range in overlapped buffers"); |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
616 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
617 return NGX_ERROR; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
618 } |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
619 |
962
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
620 |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
621 static ngx_int_t |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
622 ngx_http_range_singlepart_body(ngx_http_request_t *r, |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
623 ngx_http_range_filter_ctx_t *ctx, ngx_chain_t *in) |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
624 { |
2121
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
625 off_t start, last; |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
626 ngx_buf_t *buf; |
2121
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
627 ngx_chain_t *out, *cl, **ll; |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
628 ngx_http_range_t *range; |
960 | 629 |
2121
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
630 out = NULL; |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
631 ll = &out; |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
632 range = ctx->ranges.elts; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
633 |
2121
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
634 for (cl = in; cl; cl = cl->next) { |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
635 |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
636 buf = cl->buf; |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
637 |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
638 start = ctx->offset; |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
639 last = ctx->offset + ngx_buf_size(buf); |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
640 |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
641 ctx->offset = last; |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
642 |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
643 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
644 "http range body buf: %O-%O", start, last); |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
645 |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
646 if (ngx_buf_special(buf)) { |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
647 *ll = cl; |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
648 ll = &cl->next; |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
649 continue; |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
650 } |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
651 |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
652 if (range->end <= start || range->start >= last) { |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
653 |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
654 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
655 "http range body skip"); |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
656 |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
657 buf->pos = buf->last; |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
658 continue; |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
659 } |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
660 |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
661 if (range->start > start) { |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
662 |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
663 if (buf->in_file) { |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
664 buf->file_pos += range->start - start; |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
665 } |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
666 |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
667 if (ngx_buf_in_memory(buf)) { |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
668 buf->pos += (size_t) (range->start - start); |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
669 } |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
670 } |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
671 |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
672 if (range->end <= last) { |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
673 |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
674 if (buf->in_file) { |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
675 buf->file_last -= last - range->end; |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
676 } |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
677 |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
678 if (ngx_buf_in_memory(buf)) { |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
679 buf->last -= (size_t) (last - range->end); |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
680 } |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
681 |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
682 buf->last_buf = 1; |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
683 *ll = cl; |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
684 cl->next = NULL; |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
685 |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
686 break; |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
687 } |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
688 |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
689 *ll = cl; |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
690 ll = &cl->next; |
960 | 691 } |
692 | |
2121
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
693 if (out == NULL) { |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
694 return NGX_OK; |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
695 } |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
696 |
2121
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
697 return ngx_http_next_body_filter(r, out); |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
698 } |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
699 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
700 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
701 static ngx_int_t |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
702 ngx_http_range_multipart_body(ngx_http_request_t *r, |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
703 ngx_http_range_filter_ctx_t *ctx, ngx_chain_t *in) |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
704 { |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
705 ngx_buf_t *b, *buf; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
706 ngx_uint_t i; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
707 ngx_chain_t *out, *hcl, *rcl, *dcl, **ll; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
708 ngx_http_range_t *range; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
709 |
960 | 710 ll = &out; |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
711 buf = in->buf; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
712 range = ctx->ranges.elts; |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
713 |
963
78e70dae89f0
move ranges array to ngx_http_range_filter_ctx_t
Igor Sysoev <igor@sysoev.ru>
parents:
962
diff
changeset
|
714 for (i = 0; i < ctx->ranges.nelts; i++) { |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
715 |
960 | 716 /* |
717 * The boundary header of the range: | |
718 * CRLF | |
719 * "--0123456789" CRLF | |
720 * "Content-Type: image/jpeg" CRLF | |
721 * "Content-Range: bytes " | |
722 */ | |
723 | |
724 b = ngx_calloc_buf(r->pool); | |
725 if (b == NULL) { | |
726 return NGX_ERROR; | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
727 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
728 |
960 | 729 b->memory = 1; |
730 b->pos = ctx->boundary_header.data; | |
731 b->last = ctx->boundary_header.data + ctx->boundary_header.len; | |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
732 |
960 | 733 hcl = ngx_alloc_chain_link(r->pool); |
734 if (hcl == NULL) { | |
735 return NGX_ERROR; | |
736 } | |
461 | 737 |
960 | 738 hcl->buf = b; |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
739 |
461 | 740 |
960 | 741 /* "SSSS-EEEE/TTTT" CRLF CRLF */ |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
742 |
501 | 743 b = ngx_calloc_buf(r->pool); |
744 if (b == NULL) { | |
461 | 745 return NGX_ERROR; |
746 } | |
747 | |
343
6bdf858bff8c
nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents:
335
diff
changeset
|
748 b->temporary = 1; |
960 | 749 b->pos = range[i].content_range.data; |
750 b->last = range[i].content_range.data + range[i].content_range.len; | |
751 | |
752 rcl = ngx_alloc_chain_link(r->pool); | |
753 if (rcl == NULL) { | |
754 return NGX_ERROR; | |
755 } | |
756 | |
757 rcl->buf = b; | |
758 | |
759 | |
760 /* the range data */ | |
461 | 761 |
960 | 762 b = ngx_calloc_buf(r->pool); |
763 if (b == NULL) { | |
764 return NGX_ERROR; | |
765 } | |
766 | |
962
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
767 b->in_file = buf->in_file; |
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
768 b->temporary = buf->temporary; |
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
769 b->memory = buf->memory; |
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
770 b->mmap = buf->mmap; |
960 | 771 b->file = buf->file; |
772 | |
962
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
773 if (buf->in_file) { |
1093 | 774 b->file_pos = range[i].start; |
775 b->file_last = range[i].end; | |
962
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
776 } |
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
777 |
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
778 if (ngx_buf_in_memory(buf)) { |
1093 | 779 b->pos = buf->start + (size_t) range[i].start; |
780 b->last = buf->start + (size_t) range[i].end; | |
962
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
781 } |
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
782 |
960 | 783 dcl = ngx_alloc_chain_link(r->pool); |
784 if (dcl == NULL) { | |
461 | 785 return NGX_ERROR; |
786 } | |
787 | |
960 | 788 dcl->buf = b; |
461 | 789 |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
153
diff
changeset
|
790 *ll = hcl; |
960 | 791 hcl->next = rcl; |
792 rcl->next = dcl; | |
793 ll = &dcl->next; | |
794 } | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
795 |
960 | 796 /* the last boundary CRLF "--0123456789--" CRLF */ |
797 | |
798 b = ngx_calloc_buf(r->pool); | |
799 if (b == NULL) { | |
800 return NGX_ERROR; | |
801 } | |
802 | |
803 b->temporary = 1; | |
804 b->last_buf = 1; | |
805 | |
2049 | 806 b->pos = ngx_pnalloc(r->pool, sizeof(CRLF "--") - 1 + NGX_ATOMIC_T_LEN |
807 + sizeof("--" CRLF) - 1); | |
960 | 808 if (b->pos == NULL) { |
809 return NGX_ERROR; | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
810 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
811 |
1195
4ba6df5d5b53
fix multipart ranges trailing
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
812 b->last = ngx_cpymem(b->pos, ctx->boundary_header.data, |
4ba6df5d5b53
fix multipart ranges trailing
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
813 sizeof(CRLF "--") - 1 + NGX_ATOMIC_T_LEN); |
960 | 814 *b->last++ = '-'; *b->last++ = '-'; |
815 *b->last++ = CR; *b->last++ = LF; | |
816 | |
817 hcl = ngx_alloc_chain_link(r->pool); | |
818 if (hcl == NULL) { | |
819 return NGX_ERROR; | |
820 } | |
821 | |
822 hcl->buf = b; | |
823 hcl->next = NULL; | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
824 |
960 | 825 *ll = hcl; |
826 | |
827 return ngx_http_next_body_filter(r, out); | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
828 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
829 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
830 |
493 | 831 static ngx_int_t |
681 | 832 ngx_http_range_header_filter_init(ngx_conf_t *cf) |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
833 { |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
153
diff
changeset
|
834 ngx_http_next_header_filter = ngx_http_top_header_filter; |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
835 ngx_http_top_header_filter = ngx_http_range_header_filter; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
836 |
334
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
314
diff
changeset
|
837 return NGX_OK; |
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
314
diff
changeset
|
838 } |
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
314
diff
changeset
|
839 |
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
314
diff
changeset
|
840 |
493 | 841 static ngx_int_t |
681 | 842 ngx_http_range_body_filter_init(ngx_conf_t *cf) |
334
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
314
diff
changeset
|
843 { |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
153
diff
changeset
|
844 ngx_http_next_body_filter = ngx_http_top_body_filter; |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
845 ngx_http_top_body_filter = ngx_http_range_body_filter; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
846 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
847 return NGX_OK; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
848 } |