Mercurial > hg > nginx
annotate src/http/modules/ngx_http_range_filter_module.c @ 8031:d26db4f82d7d
All known output headers can be linked lists now.
The h->next pointer properly provided as NULL in all cases where known
output headers are added.
Note that there are 3rd party modules which might not do this, and it
might be risky to rely on this for arbitrary headers.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 30 May 2022 21:25:45 +0300 |
parents | c30a20e06c21 |
children | ae2d62bb12c0 |
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 |
4412 | 4 * Copyright (C) Nginx, Inc. |
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
|
5 */ |
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
|
6 |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_config.h> |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 #include <ngx_core.h> |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 #include <ngx_http.h> |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
12 |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
13 /* |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
14 * 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
|
15 * |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
16 * "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
|
17 * ... header ... |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
18 * "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
|
19 * "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
|
20 * "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
|
21 * CRLF |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
22 * ... data ... |
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 * |
5538 | 25 * the multipart format: |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
26 * |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
27 * "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
|
28 * ... header ... |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
29 * "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
|
30 * CRLF |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
31 * CRLF |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
32 * "--0123456789" CRLF |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
33 * "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
|
34 * "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
|
35 * CRLF |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
36 * ... data ... |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
37 * CRLF |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
38 * "--0123456789" CRLF |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
39 * "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
|
40 * "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
|
41 * CRLF |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
42 * ... data ... |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
43 * CRLF |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
44 * "--0123456789--" CRLF |
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 |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
47 |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
48 typedef struct { |
963
78e70dae89f0
move ranges array to ngx_http_range_filter_ctx_t
Igor Sysoev <igor@sysoev.ru>
parents:
962
diff
changeset
|
49 off_t start; |
78e70dae89f0
move ranges array to ngx_http_range_filter_ctx_t
Igor Sysoev <igor@sysoev.ru>
parents:
962
diff
changeset
|
50 off_t end; |
78e70dae89f0
move ranges array to ngx_http_range_filter_ctx_t
Igor Sysoev <igor@sysoev.ru>
parents:
962
diff
changeset
|
51 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
|
52 } ngx_http_range_t; |
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 |
78e70dae89f0
move ranges array to ngx_http_range_filter_ctx_t
Igor Sysoev <igor@sysoev.ru>
parents:
962
diff
changeset
|
55 typedef struct { |
78e70dae89f0
move ranges array to ngx_http_range_filter_ctx_t
Igor Sysoev <igor@sysoev.ru>
parents:
962
diff
changeset
|
56 off_t offset; |
78e70dae89f0
move ranges array to ngx_http_range_filter_ctx_t
Igor Sysoev <igor@sysoev.ru>
parents:
962
diff
changeset
|
57 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
|
58 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
|
59 } 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
|
60 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
61 |
4058
d32a2000b766
ngx_http_range_parse() should be static.
Igor Sysoev <igor@sysoev.ru>
parents:
4057
diff
changeset
|
62 static ngx_int_t ngx_http_range_parse(ngx_http_request_t *r, |
4062 | 63 ngx_http_range_filter_ctx_t *ctx, ngx_uint_t ranges); |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
64 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
|
65 ngx_http_range_filter_ctx_t *ctx); |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
66 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
|
67 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
|
68 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
|
69 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
|
70 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
|
71 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
|
72 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
|
73 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
|
74 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
|
75 |
681 | 76 static ngx_int_t ngx_http_range_header_filter_init(ngx_conf_t *cf); |
77 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
|
78 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
79 |
334
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
314
diff
changeset
|
80 static ngx_http_module_t ngx_http_range_header_filter_module_ctx = { |
509 | 81 NULL, /* preconfiguration */ |
681 | 82 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
|
83 |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
84 NULL, /* create main configuration */ |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
85 NULL, /* init main configuration */ |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
86 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
87 NULL, /* create server configuration */ |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
88 NULL, /* merge server configuration */ |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
89 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
90 NULL, /* create location configuration */ |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
91 NULL, /* merge location configuration */ |
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 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
94 |
334
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
314
diff
changeset
|
95 ngx_module_t ngx_http_range_header_filter_module = { |
509 | 96 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
|
97 &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
|
98 NULL, /* module directives */ |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
99 NGX_HTTP_MODULE, /* module type */ |
541 | 100 NULL, /* init master */ |
681 | 101 NULL, /* init module */ |
541 | 102 NULL, /* init process */ |
103 NULL, /* init thread */ | |
104 NULL, /* exit thread */ | |
105 NULL, /* exit process */ | |
106 NULL, /* exit master */ | |
107 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
|
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 |
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
314
diff
changeset
|
111 static ngx_http_module_t ngx_http_range_body_filter_module_ctx = { |
509 | 112 NULL, /* preconfiguration */ |
681 | 113 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
|
114 |
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
314
diff
changeset
|
115 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
|
116 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
|
117 |
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
314
diff
changeset
|
118 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
|
119 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
|
120 |
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
314
diff
changeset
|
121 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
|
122 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
|
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 |
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
314
diff
changeset
|
126 ngx_module_t ngx_http_range_body_filter_module = { |
509 | 127 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
|
128 &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
|
129 NULL, /* module directives */ |
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
314
diff
changeset
|
130 NGX_HTTP_MODULE, /* module type */ |
541 | 131 NULL, /* init master */ |
681 | 132 NULL, /* init module */ |
541 | 133 NULL, /* init process */ |
134 NULL, /* init thread */ | |
135 NULL, /* exit thread */ | |
136 NULL, /* exit process */ | |
137 NULL, /* exit master */ | |
138 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
|
139 }; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
140 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
141 |
155
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_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
|
143 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
|
144 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
145 |
493 | 146 static ngx_int_t |
147 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
|
148 { |
4745
4752060ca462
Entity tags: support in If-Range header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4741
diff
changeset
|
149 time_t if_range_time; |
4752060ca462
Entity tags: support in If-Range header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4741
diff
changeset
|
150 ngx_str_t *if_range, *etag; |
5621
345e4fd4bb64
Range filter: single_range flag in request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5558
diff
changeset
|
151 ngx_uint_t ranges; |
4062 | 152 ngx_http_core_loc_conf_t *clcf; |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
153 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
|
154 |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
155 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
|
156 || r->headers_out.status != NGX_HTTP_OK |
6317 | 157 || (r != r->main && !r->subrequest_ranges) |
153
c71aeb75c071
nginx-0.0.1-2003-10-21-20:49:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
136
diff
changeset
|
158 || r->headers_out.content_length_n == -1 |
581 | 159 || !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
|
160 { |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
153
diff
changeset
|
161 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
|
162 } |
f6e3c5d019b6
nginx-0.0.1-2003-07-11-19:17:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
113
diff
changeset
|
163 |
4062 | 164 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
165 | |
166 if (clcf->max_ranges == 0) { | |
167 return ngx_http_next_header_filter(r); | |
168 } | |
169 | |
117
f6e3c5d019b6
nginx-0.0.1-2003-07-11-19:17:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
113
diff
changeset
|
170 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
|
171 || r->headers_in.range->value.len < 7 |
1107
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1093
diff
changeset
|
172 || ngx_strncasecmp(r->headers_in.range->value.data, |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1093
diff
changeset
|
173 (u_char *) "bytes=", 6) |
db7c468c447d
ngx_strcasecmp()/ngx_strncasecmp()
Igor Sysoev <igor@sysoev.ru>
parents:
1093
diff
changeset
|
174 != 0) |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
175 { |
1630 | 176 goto next_filter; |
177 } | |
178 | |
4741
5ea8c710c532
Fixed If-Range with unknown last modified time.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4467
diff
changeset
|
179 if (r->headers_in.if_range) { |
5ea8c710c532
Fixed If-Range with unknown last modified time.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4467
diff
changeset
|
180 |
4745
4752060ca462
Entity tags: support in If-Range header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4741
diff
changeset
|
181 if_range = &r->headers_in.if_range->value; |
4752060ca462
Entity tags: support in If-Range header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4741
diff
changeset
|
182 |
4750
149634c98d67
Entity tags: empty etags handling in If-Range.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4745
diff
changeset
|
183 if (if_range->len >= 2 && if_range->data[if_range->len - 1] == '"') { |
4745
4752060ca462
Entity tags: support in If-Range header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4741
diff
changeset
|
184 |
4752060ca462
Entity tags: support in If-Range header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4741
diff
changeset
|
185 if (r->headers_out.etag == NULL) { |
4752060ca462
Entity tags: support in If-Range header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4741
diff
changeset
|
186 goto next_filter; |
4752060ca462
Entity tags: support in If-Range header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4741
diff
changeset
|
187 } |
4752060ca462
Entity tags: support in If-Range header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4741
diff
changeset
|
188 |
4752060ca462
Entity tags: support in If-Range header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4741
diff
changeset
|
189 etag = &r->headers_out.etag->value; |
4752060ca462
Entity tags: support in If-Range header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4741
diff
changeset
|
190 |
4752060ca462
Entity tags: support in If-Range header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4741
diff
changeset
|
191 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
4752060ca462
Entity tags: support in If-Range header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4741
diff
changeset
|
192 "http ir:%V etag:%V", if_range, etag); |
4752060ca462
Entity tags: support in If-Range header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4741
diff
changeset
|
193 |
4752060ca462
Entity tags: support in If-Range header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4741
diff
changeset
|
194 if (if_range->len != etag->len |
4752060ca462
Entity tags: support in If-Range header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4741
diff
changeset
|
195 || ngx_strncmp(if_range->data, etag->data, etag->len) != 0) |
4752060ca462
Entity tags: support in If-Range header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4741
diff
changeset
|
196 { |
4752060ca462
Entity tags: support in If-Range header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4741
diff
changeset
|
197 goto next_filter; |
4752060ca462
Entity tags: support in If-Range header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4741
diff
changeset
|
198 } |
4752060ca462
Entity tags: support in If-Range header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4741
diff
changeset
|
199 |
4752060ca462
Entity tags: support in If-Range header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4741
diff
changeset
|
200 goto parse; |
4752060ca462
Entity tags: support in If-Range header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4741
diff
changeset
|
201 } |
4752060ca462
Entity tags: support in If-Range header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4741
diff
changeset
|
202 |
4741
5ea8c710c532
Fixed If-Range with unknown last modified time.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4467
diff
changeset
|
203 if (r->headers_out.last_modified_time == (time_t) -1) { |
5ea8c710c532
Fixed If-Range with unknown last modified time.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4467
diff
changeset
|
204 goto next_filter; |
5ea8c710c532
Fixed If-Range with unknown last modified time.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4467
diff
changeset
|
205 } |
1630 | 206 |
6180
8b6fa4842133
Moved ngx_http_parse_time() to core, renamed accordingly.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6013
diff
changeset
|
207 if_range_time = ngx_parse_http_time(if_range->data, if_range->len); |
117
f6e3c5d019b6
nginx-0.0.1-2003-07-11-19:17:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
113
diff
changeset
|
208 |
1630 | 209 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
6480 | 210 "http ir:%T lm:%T", |
4745
4752060ca462
Entity tags: support in If-Range header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4741
diff
changeset
|
211 if_range_time, 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
|
212 |
4745
4752060ca462
Entity tags: support in If-Range header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4741
diff
changeset
|
213 if (if_range_time != r->headers_out.last_modified_time) { |
1630 | 214 goto next_filter; |
215 } | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
216 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
217 |
4745
4752060ca462
Entity tags: support in If-Range header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4741
diff
changeset
|
218 parse: |
4752060ca462
Entity tags: support in If-Range header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4741
diff
changeset
|
219 |
963
78e70dae89f0
move ranges array to ngx_http_range_filter_ctx_t
Igor Sysoev <igor@sysoev.ru>
parents:
962
diff
changeset
|
220 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
|
221 if (ctx == NULL) { |
78e70dae89f0
move ranges array to ngx_http_range_filter_ctx_t
Igor Sysoev <igor@sysoev.ru>
parents:
962
diff
changeset
|
222 return NGX_ERROR; |
78e70dae89f0
move ranges array to ngx_http_range_filter_ctx_t
Igor Sysoev <igor@sysoev.ru>
parents:
962
diff
changeset
|
223 } |
78e70dae89f0
move ranges array to ngx_http_range_filter_ctx_t
Igor Sysoev <igor@sysoev.ru>
parents:
962
diff
changeset
|
224 |
6317 | 225 ctx->offset = r->headers_out.content_offset; |
226 | |
5621
345e4fd4bb64
Range filter: single_range flag in request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5558
diff
changeset
|
227 ranges = r->single_range ? 1 : clcf->max_ranges; |
345e4fd4bb64
Range filter: single_range flag in request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5558
diff
changeset
|
228 |
345e4fd4bb64
Range filter: single_range flag in request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5558
diff
changeset
|
229 switch (ngx_http_range_parse(r, ctx, ranges)) { |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
230 |
4035
c2a91088b0c0
Now if total size of all ranges is greater than source response size,
Igor Sysoev <igor@sysoev.ru>
parents:
3516
diff
changeset
|
231 case NGX_OK: |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
232 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
|
233 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
234 r->headers_out.status = NGX_HTTP_PARTIAL_CONTENT; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
235 r->headers_out.status_line.len = 0; |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
236 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
237 if (ctx->ranges.nelts == 1) { |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
238 return ngx_http_range_singlepart_header(r, ctx); |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
239 } |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
240 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
241 return ngx_http_range_multipart_header(r, ctx); |
4035
c2a91088b0c0
Now if total size of all ranges is greater than source response size,
Igor Sysoev <igor@sysoev.ru>
parents:
3516
diff
changeset
|
242 |
c2a91088b0c0
Now if total size of all ranges is greater than source response size,
Igor Sysoev <igor@sysoev.ru>
parents:
3516
diff
changeset
|
243 case NGX_HTTP_RANGE_NOT_SATISFIABLE: |
c2a91088b0c0
Now if total size of all ranges is greater than source response size,
Igor Sysoev <igor@sysoev.ru>
parents:
3516
diff
changeset
|
244 return ngx_http_range_not_satisfiable(r); |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
245 |
4035
c2a91088b0c0
Now if total size of all ranges is greater than source response size,
Igor Sysoev <igor@sysoev.ru>
parents:
3516
diff
changeset
|
246 case NGX_ERROR: |
c2a91088b0c0
Now if total size of all ranges is greater than source response size,
Igor Sysoev <igor@sysoev.ru>
parents:
3516
diff
changeset
|
247 return NGX_ERROR; |
c2a91088b0c0
Now if total size of all ranges is greater than source response size,
Igor Sysoev <igor@sysoev.ru>
parents:
3516
diff
changeset
|
248 |
c2a91088b0c0
Now if total size of all ranges is greater than source response size,
Igor Sysoev <igor@sysoev.ru>
parents:
3516
diff
changeset
|
249 default: /* NGX_DECLINED */ |
c2a91088b0c0
Now if total size of all ranges is greater than source response size,
Igor Sysoev <igor@sysoev.ru>
parents:
3516
diff
changeset
|
250 break; |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
251 } |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
252 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
253 next_filter: |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
254 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
255 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
|
256 if (r->headers_out.accept_ranges == NULL) { |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
257 return NGX_ERROR; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
258 } |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
259 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
260 r->headers_out.accept_ranges->hash = 1; |
8031
d26db4f82d7d
All known output headers can be linked lists now.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7508
diff
changeset
|
261 r->headers_out.accept_ranges->next = NULL; |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3331
diff
changeset
|
262 ngx_str_set(&r->headers_out.accept_ranges->key, "Accept-Ranges"); |
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3331
diff
changeset
|
263 ngx_str_set(&r->headers_out.accept_ranges->value, "bytes"); |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
264 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
265 return ngx_http_next_header_filter(r); |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
266 } |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
267 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
268 |
4058
d32a2000b766
ngx_http_range_parse() should be static.
Igor Sysoev <igor@sysoev.ru>
parents:
4057
diff
changeset
|
269 static ngx_int_t |
4062 | 270 ngx_http_range_parse(ngx_http_request_t *r, ngx_http_range_filter_ctx_t *ctx, |
271 ngx_uint_t ranges) | |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
272 { |
6317 | 273 u_char *p; |
274 off_t start, end, size, content_length, cutoff, | |
275 cutlim; | |
276 ngx_uint_t suffix; | |
277 ngx_http_range_t *range; | |
278 ngx_http_range_filter_ctx_t *mctx; | |
279 | |
280 if (r != r->main) { | |
281 mctx = ngx_http_get_module_ctx(r->main, | |
282 ngx_http_range_body_filter_module); | |
283 if (mctx) { | |
284 ctx->ranges = mctx->ranges; | |
285 return NGX_OK; | |
286 } | |
287 } | |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
288 |
6798
2decd6b34306
Range filter: only initialize ctx->ranges in main request.
hucongcong <hucong.c@foxmail.com>
parents:
6722
diff
changeset
|
289 if (ngx_array_init(&ctx->ranges, r->pool, 1, sizeof(ngx_http_range_t)) |
2decd6b34306
Range filter: only initialize ctx->ranges in main request.
hucongcong <hucong.c@foxmail.com>
parents:
6722
diff
changeset
|
290 != NGX_OK) |
2decd6b34306
Range filter: only initialize ctx->ranges in main request.
hucongcong <hucong.c@foxmail.com>
parents:
6722
diff
changeset
|
291 { |
2decd6b34306
Range filter: only initialize ctx->ranges in main request.
hucongcong <hucong.c@foxmail.com>
parents:
6722
diff
changeset
|
292 return NGX_ERROR; |
2decd6b34306
Range filter: only initialize ctx->ranges in main request.
hucongcong <hucong.c@foxmail.com>
parents:
6722
diff
changeset
|
293 } |
2decd6b34306
Range filter: only initialize ctx->ranges in main request.
hucongcong <hucong.c@foxmail.com>
parents:
6722
diff
changeset
|
294 |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
295 p = r->headers_in.range->value.data + 6; |
4035
c2a91088b0c0
Now if total size of all ranges is greater than source response size,
Igor Sysoev <igor@sysoev.ru>
parents:
3516
diff
changeset
|
296 size = 0; |
4057
3205a6d6c6ec
Ranges processing small optimization.
Igor Sysoev <igor@sysoev.ru>
parents:
4056
diff
changeset
|
297 content_length = 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
|
298 |
6013
9653092a79fd
Overflow detection in ngx_http_range_parse().
Ruslan Ermilov <ru@nginx.com>
parents:
5621
diff
changeset
|
299 cutoff = NGX_MAX_OFF_T_VALUE / 10; |
9653092a79fd
Overflow detection in ngx_http_range_parse().
Ruslan Ermilov <ru@nginx.com>
parents:
5621
diff
changeset
|
300 cutlim = NGX_MAX_OFF_T_VALUE % 10; |
9653092a79fd
Overflow detection in ngx_http_range_parse().
Ruslan Ermilov <ru@nginx.com>
parents:
5621
diff
changeset
|
301 |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
302 for ( ;; ) { |
231
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
303 start = 0; |
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
304 end = 0; |
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
305 suffix = 0; |
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 while (*p == ' ') { p++; } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
308 |
231
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
309 if (*p != '-') { |
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
310 if (*p < '0' || *p > '9') { |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
311 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
|
312 } |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
313 |
231
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
314 while (*p >= '0' && *p <= '9') { |
6013
9653092a79fd
Overflow detection in ngx_http_range_parse().
Ruslan Ermilov <ru@nginx.com>
parents:
5621
diff
changeset
|
315 if (start >= cutoff && (start > cutoff || *p - '0' > cutlim)) { |
9653092a79fd
Overflow detection in ngx_http_range_parse().
Ruslan Ermilov <ru@nginx.com>
parents:
5621
diff
changeset
|
316 return NGX_HTTP_RANGE_NOT_SATISFIABLE; |
9653092a79fd
Overflow detection in ngx_http_range_parse().
Ruslan Ermilov <ru@nginx.com>
parents:
5621
diff
changeset
|
317 } |
9653092a79fd
Overflow detection in ngx_http_range_parse().
Ruslan Ermilov <ru@nginx.com>
parents:
5621
diff
changeset
|
318 |
7067
e3723f2a11b7
Parenthesized ASCII-related calculations.
Valentin Bartenev <vbart@nginx.com>
parents:
7055
diff
changeset
|
319 start = start * 10 + (*p++ - '0'); |
231
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
320 } |
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
321 |
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
322 while (*p == ' ') { p++; } |
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
323 |
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
324 if (*p++ != '-') { |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
325 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
|
326 } |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
327 |
231
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
328 while (*p == ' ') { p++; } |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
329 |
231
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
330 if (*p == ',' || *p == '\0') { |
4057
3205a6d6c6ec
Ranges processing small optimization.
Igor Sysoev <igor@sysoev.ru>
parents:
4056
diff
changeset
|
331 end = content_length; |
4055
9cce506be97d
Ranges processing small optimization.
Igor Sysoev <igor@sysoev.ru>
parents:
4054
diff
changeset
|
332 goto found; |
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 } else { |
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
336 suffix = 1; |
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
337 p++; |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
338 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
339 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
340 if (*p < '0' || *p > '9') { |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
341 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
|
342 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
343 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
344 while (*p >= '0' && *p <= '9') { |
6013
9653092a79fd
Overflow detection in ngx_http_range_parse().
Ruslan Ermilov <ru@nginx.com>
parents:
5621
diff
changeset
|
345 if (end >= cutoff && (end > cutoff || *p - '0' > cutlim)) { |
9653092a79fd
Overflow detection in ngx_http_range_parse().
Ruslan Ermilov <ru@nginx.com>
parents:
5621
diff
changeset
|
346 return NGX_HTTP_RANGE_NOT_SATISFIABLE; |
9653092a79fd
Overflow detection in ngx_http_range_parse().
Ruslan Ermilov <ru@nginx.com>
parents:
5621
diff
changeset
|
347 } |
9653092a79fd
Overflow detection in ngx_http_range_parse().
Ruslan Ermilov <ru@nginx.com>
parents:
5621
diff
changeset
|
348 |
7067
e3723f2a11b7
Parenthesized ASCII-related calculations.
Valentin Bartenev <vbart@nginx.com>
parents:
7055
diff
changeset
|
349 end = end * 10 + (*p++ - '0'); |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
350 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
351 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
352 while (*p == ' ') { p++; } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
353 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
354 if (*p != ',' && *p != '\0') { |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
355 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
|
356 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
357 |
231
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
358 if (suffix) { |
7055
887c8c58ffeb
Range filter: avoid negative range start.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7054
diff
changeset
|
359 start = (end < content_length) ? content_length - end : 0; |
4057
3205a6d6c6ec
Ranges processing small optimization.
Igor Sysoev <igor@sysoev.ru>
parents:
4056
diff
changeset
|
360 end = content_length - 1; |
231
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
361 } |
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
362 |
4057
3205a6d6c6ec
Ranges processing small optimization.
Igor Sysoev <igor@sysoev.ru>
parents:
4056
diff
changeset
|
363 if (end >= content_length) { |
3205a6d6c6ec
Ranges processing small optimization.
Igor Sysoev <igor@sysoev.ru>
parents:
4056
diff
changeset
|
364 end = content_length; |
4055
9cce506be97d
Ranges processing small optimization.
Igor Sysoev <igor@sysoev.ru>
parents:
4054
diff
changeset
|
365 |
9cce506be97d
Ranges processing small optimization.
Igor Sysoev <igor@sysoev.ru>
parents:
4054
diff
changeset
|
366 } else { |
9cce506be97d
Ranges processing small optimization.
Igor Sysoev <igor@sysoev.ru>
parents:
4054
diff
changeset
|
367 end++; |
9cce506be97d
Ranges processing small optimization.
Igor Sysoev <igor@sysoev.ru>
parents:
4054
diff
changeset
|
368 } |
9cce506be97d
Ranges processing small optimization.
Igor Sysoev <igor@sysoev.ru>
parents:
4054
diff
changeset
|
369 |
9cce506be97d
Ranges processing small optimization.
Igor Sysoev <igor@sysoev.ru>
parents:
4054
diff
changeset
|
370 found: |
9cce506be97d
Ranges processing small optimization.
Igor Sysoev <igor@sysoev.ru>
parents:
4054
diff
changeset
|
371 |
4060
45de8d258085
*) fix of r4060: start value should be tested after the "found" label;
Igor Sysoev <igor@sysoev.ru>
parents:
4059
diff
changeset
|
372 if (start < end) { |
4061
bd2ec6ce5d58
Style fix: removal of tabs introduced in the previous commit.
Igor Sysoev <igor@sysoev.ru>
parents:
4060
diff
changeset
|
373 range = ngx_array_push(&ctx->ranges); |
bd2ec6ce5d58
Style fix: removal of tabs introduced in the previous commit.
Igor Sysoev <igor@sysoev.ru>
parents:
4060
diff
changeset
|
374 if (range == NULL) { |
bd2ec6ce5d58
Style fix: removal of tabs introduced in the previous commit.
Igor Sysoev <igor@sysoev.ru>
parents:
4060
diff
changeset
|
375 return NGX_ERROR; |
bd2ec6ce5d58
Style fix: removal of tabs introduced in the previous commit.
Igor Sysoev <igor@sysoev.ru>
parents:
4060
diff
changeset
|
376 } |
461 | 377 |
4061
bd2ec6ce5d58
Style fix: removal of tabs introduced in the previous commit.
Igor Sysoev <igor@sysoev.ru>
parents:
4060
diff
changeset
|
378 range->start = start; |
bd2ec6ce5d58
Style fix: removal of tabs introduced in the previous commit.
Igor Sysoev <igor@sysoev.ru>
parents:
4060
diff
changeset
|
379 range->end = end; |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
380 |
7054
e02555553d0b
Range filter: protect from total size overflows.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7043
diff
changeset
|
381 if (size > NGX_MAX_OFF_T_VALUE - (end - start)) { |
e02555553d0b
Range filter: protect from total size overflows.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7043
diff
changeset
|
382 return NGX_HTTP_RANGE_NOT_SATISFIABLE; |
e02555553d0b
Range filter: protect from total size overflows.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7043
diff
changeset
|
383 } |
e02555553d0b
Range filter: protect from total size overflows.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7043
diff
changeset
|
384 |
4061
bd2ec6ce5d58
Style fix: removal of tabs introduced in the previous commit.
Igor Sysoev <igor@sysoev.ru>
parents:
4060
diff
changeset
|
385 size += end - start; |
4062 | 386 |
4063
8d70904b6c48
Now if client requests more ranges than "max_ranges" permits,
Igor Sysoev <igor@sysoev.ru>
parents:
4062
diff
changeset
|
387 if (ranges-- == 0) { |
8d70904b6c48
Now if client requests more ranges than "max_ranges" permits,
Igor Sysoev <igor@sysoev.ru>
parents:
4062
diff
changeset
|
388 return NGX_DECLINED; |
4062 | 389 } |
7043
aeaac3ccee4f
Range filter: allowed ranges on empty files (ticket #1031).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6986
diff
changeset
|
390 |
aeaac3ccee4f
Range filter: allowed ranges on empty files (ticket #1031).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6986
diff
changeset
|
391 } else if (start == 0) { |
aeaac3ccee4f
Range filter: allowed ranges on empty files (ticket #1031).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6986
diff
changeset
|
392 return NGX_DECLINED; |
4060
45de8d258085
*) fix of r4060: start value should be tested after the "found" label;
Igor Sysoev <igor@sysoev.ru>
parents:
4059
diff
changeset
|
393 } |
4056
e9213133993a
Now unsatisfiable ranges are processed according to RFC 2616.
Igor Sysoev <igor@sysoev.ru>
parents:
4055
diff
changeset
|
394 |
231
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
395 if (*p++ != ',') { |
4035
c2a91088b0c0
Now if total size of all ranges is greater than source response size,
Igor Sysoev <igor@sysoev.ru>
parents:
3516
diff
changeset
|
396 break; |
231
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
397 } |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
398 } |
4035
c2a91088b0c0
Now if total size of all ranges is greater than source response size,
Igor Sysoev <igor@sysoev.ru>
parents:
3516
diff
changeset
|
399 |
4056
e9213133993a
Now unsatisfiable ranges are processed according to RFC 2616.
Igor Sysoev <igor@sysoev.ru>
parents:
4055
diff
changeset
|
400 if (ctx->ranges.nelts == 0) { |
e9213133993a
Now unsatisfiable ranges are processed according to RFC 2616.
Igor Sysoev <igor@sysoev.ru>
parents:
4055
diff
changeset
|
401 return NGX_HTTP_RANGE_NOT_SATISFIABLE; |
e9213133993a
Now unsatisfiable ranges are processed according to RFC 2616.
Igor Sysoev <igor@sysoev.ru>
parents:
4055
diff
changeset
|
402 } |
e9213133993a
Now unsatisfiable ranges are processed according to RFC 2616.
Igor Sysoev <igor@sysoev.ru>
parents:
4055
diff
changeset
|
403 |
4057
3205a6d6c6ec
Ranges processing small optimization.
Igor Sysoev <igor@sysoev.ru>
parents:
4056
diff
changeset
|
404 if (size > content_length) { |
4035
c2a91088b0c0
Now if total size of all ranges is greater than source response size,
Igor Sysoev <igor@sysoev.ru>
parents:
3516
diff
changeset
|
405 return NGX_DECLINED; |
c2a91088b0c0
Now if total size of all ranges is greater than source response size,
Igor Sysoev <igor@sysoev.ru>
parents:
3516
diff
changeset
|
406 } |
c2a91088b0c0
Now if total size of all ranges is greater than source response size,
Igor Sysoev <igor@sysoev.ru>
parents:
3516
diff
changeset
|
407 |
c2a91088b0c0
Now if total size of all ranges is greater than source response size,
Igor Sysoev <igor@sysoev.ru>
parents:
3516
diff
changeset
|
408 return NGX_OK; |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
409 } |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
410 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
411 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
412 static ngx_int_t |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
413 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
|
414 ngx_http_range_filter_ctx_t *ctx) |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
415 { |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
416 ngx_table_elt_t *content_range; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
417 ngx_http_range_t *range; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
418 |
6317 | 419 if (r != r->main) { |
420 return ngx_http_next_header_filter(r); | |
421 } | |
422 | |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
423 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
|
424 if (content_range == NULL) { |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
425 return NGX_ERROR; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
426 } |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
427 |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
428 r->headers_out.content_range = content_range; |
461 | 429 |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
430 content_range->hash = 1; |
8031
d26db4f82d7d
All known output headers can be linked lists now.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7508
diff
changeset
|
431 content_range->next = NULL; |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3331
diff
changeset
|
432 ngx_str_set(&content_range->key, "Content-Range"); |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
433 |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
434 content_range->value.data = ngx_pnalloc(r->pool, |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
435 sizeof("bytes -/") - 1 + 3 * NGX_OFF_T_LEN); |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
436 if (content_range->value.data == NULL) { |
6986
0cdee26605f3
Cleaned up r->headers_out.headers allocation error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6798
diff
changeset
|
437 content_range->hash = 0; |
0cdee26605f3
Cleaned up r->headers_out.headers allocation error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6798
diff
changeset
|
438 r->headers_out.content_range = NULL; |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
439 return NGX_ERROR; |
461 | 440 } |
441 | |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
442 /* "Content-Range: bytes SSSS-EEEE/TTTT" header */ |
461 | 443 |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
444 range = ctx->ranges.elts; |
461 | 445 |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
446 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
|
447 "bytes %O-%O/%O", |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
448 range->start, range->end - 1, |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
449 r->headers_out.content_length_n) |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
450 - content_range->value.data; |
461 | 451 |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
452 r->headers_out.content_length_n = range->end - range->start; |
6317 | 453 r->headers_out.content_offset = range->start; |
461 | 454 |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
455 if (r->headers_out.content_length) { |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
456 r->headers_out.content_length->hash = 0; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
457 r->headers_out.content_length = NULL; |
461 | 458 } |
459 | |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
460 return ngx_http_next_header_filter(r); |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
461 } |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
462 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
463 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
464 static ngx_int_t |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
465 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
|
466 ngx_http_range_filter_ctx_t *ctx) |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
467 { |
7090
a2f5e25d6a28
Range filter: changed type for total length to off_t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7067
diff
changeset
|
468 off_t len; |
a2f5e25d6a28
Range filter: changed type for total length to off_t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7067
diff
changeset
|
469 size_t size; |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
470 ngx_uint_t i; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
471 ngx_http_range_t *range; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
472 ngx_atomic_uint_t boundary; |
461 | 473 |
7090
a2f5e25d6a28
Range filter: changed type for total length to off_t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7067
diff
changeset
|
474 size = sizeof(CRLF "--") - 1 + NGX_ATOMIC_T_LEN |
a2f5e25d6a28
Range filter: changed type for total length to off_t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7067
diff
changeset
|
475 + sizeof(CRLF "Content-Type: ") - 1 |
a2f5e25d6a28
Range filter: changed type for total length to off_t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7067
diff
changeset
|
476 + r->headers_out.content_type.len |
a2f5e25d6a28
Range filter: changed type for total length to off_t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7067
diff
changeset
|
477 + sizeof(CRLF "Content-Range: bytes ") - 1; |
461 | 478 |
5558
eeb3c2719147
Range filter: fixed duplicate charset.
Ruslan Ermilov <ru@nginx.com>
parents:
5538
diff
changeset
|
479 if (r->headers_out.content_type_len == r->headers_out.content_type.len |
eeb3c2719147
Range filter: fixed duplicate charset.
Ruslan Ermilov <ru@nginx.com>
parents:
5538
diff
changeset
|
480 && r->headers_out.charset.len) |
eeb3c2719147
Range filter: fixed duplicate charset.
Ruslan Ermilov <ru@nginx.com>
parents:
5538
diff
changeset
|
481 { |
7090
a2f5e25d6a28
Range filter: changed type for total length to off_t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7067
diff
changeset
|
482 size += sizeof("; charset=") - 1 + r->headers_out.charset.len; |
461 | 483 } |
484 | |
7090
a2f5e25d6a28
Range filter: changed type for total length to off_t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7067
diff
changeset
|
485 ctx->boundary_header.data = ngx_pnalloc(r->pool, size); |
501 | 486 if (ctx->boundary_header.data == NULL) { |
461 | 487 return NGX_ERROR; |
488 } | |
489 | |
493 | 490 boundary = ngx_next_temp_number(0); |
461 | 491 |
492 /* | |
493 * The boundary header of the range: | |
494 * CRLF | |
495 * "--0123456789" CRLF | |
496 * "Content-Type: image/jpeg" CRLF | |
497 * "Content-Range: bytes " | |
498 */ | |
499 | |
5558
eeb3c2719147
Range filter: fixed duplicate charset.
Ruslan Ermilov <ru@nginx.com>
parents:
5538
diff
changeset
|
500 if (r->headers_out.content_type_len == r->headers_out.content_type.len |
eeb3c2719147
Range filter: fixed duplicate charset.
Ruslan Ermilov <ru@nginx.com>
parents:
5538
diff
changeset
|
501 && r->headers_out.charset.len) |
eeb3c2719147
Range filter: fixed duplicate charset.
Ruslan Ermilov <ru@nginx.com>
parents:
5538
diff
changeset
|
502 { |
461 | 503 ctx->boundary_header.len = ngx_sprintf(ctx->boundary_header.data, |
493 | 504 CRLF "--%0muA" CRLF |
461 | 505 "Content-Type: %V; charset=%V" CRLF |
506 "Content-Range: bytes ", | |
507 boundary, | |
509 | 508 &r->headers_out.content_type, |
461 | 509 &r->headers_out.charset) |
510 - ctx->boundary_header.data; | |
511 | |
2119
0799703985ef
fix ranges without Content-Type
Igor Sysoev <igor@sysoev.ru>
parents:
2118
diff
changeset
|
512 } else if (r->headers_out.content_type.len) { |
461 | 513 ctx->boundary_header.len = ngx_sprintf(ctx->boundary_header.data, |
493 | 514 CRLF "--%0muA" CRLF |
461 | 515 "Content-Type: %V" CRLF |
516 "Content-Range: bytes ", | |
517 boundary, | |
509 | 518 &r->headers_out.content_type) |
461 | 519 - ctx->boundary_header.data; |
2119
0799703985ef
fix ranges without Content-Type
Igor Sysoev <igor@sysoev.ru>
parents:
2118
diff
changeset
|
520 |
0799703985ef
fix ranges without Content-Type
Igor Sysoev <igor@sysoev.ru>
parents:
2118
diff
changeset
|
521 } else { |
0799703985ef
fix ranges without Content-Type
Igor Sysoev <igor@sysoev.ru>
parents:
2118
diff
changeset
|
522 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
|
523 CRLF "--%0muA" CRLF |
0799703985ef
fix ranges without Content-Type
Igor Sysoev <igor@sysoev.ru>
parents:
2118
diff
changeset
|
524 "Content-Range: bytes ", |
0799703985ef
fix ranges without Content-Type
Igor Sysoev <igor@sysoev.ru>
parents:
2118
diff
changeset
|
525 boundary) |
0799703985ef
fix ranges without Content-Type
Igor Sysoev <igor@sysoev.ru>
parents:
2118
diff
changeset
|
526 - ctx->boundary_header.data; |
461 | 527 } |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
528 |
509 | 529 r->headers_out.content_type.data = |
2049 | 530 ngx_pnalloc(r->pool, |
531 sizeof("Content-Type: multipart/byteranges; boundary=") - 1 | |
532 + 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
|
533 |
509 | 534 if (r->headers_out.content_type.data == NULL) { |
461 | 535 return NGX_ERROR; |
536 } | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
537 |
2882
896db5a09bd2
reset content_type hash value, this fixes a bug when XSLT responses
Igor Sysoev <igor@sysoev.ru>
parents:
2592
diff
changeset
|
538 r->headers_out.content_type_lowcase = NULL; |
896db5a09bd2
reset content_type hash value, this fixes a bug when XSLT responses
Igor Sysoev <igor@sysoev.ru>
parents:
2592
diff
changeset
|
539 |
461 | 540 /* "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
|
541 |
509 | 542 r->headers_out.content_type.len = |
543 ngx_sprintf(r->headers_out.content_type.data, | |
493 | 544 "multipart/byteranges; boundary=%0muA", |
461 | 545 boundary) |
509 | 546 - 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
|
547 |
2882
896db5a09bd2
reset content_type hash value, this fixes a bug when XSLT responses
Igor Sysoev <igor@sysoev.ru>
parents:
2592
diff
changeset
|
548 r->headers_out.content_type_len = r->headers_out.content_type.len; |
493 | 549 |
5558
eeb3c2719147
Range filter: fixed duplicate charset.
Ruslan Ermilov <ru@nginx.com>
parents:
5538
diff
changeset
|
550 r->headers_out.charset.len = 0; |
eeb3c2719147
Range filter: fixed duplicate charset.
Ruslan Ermilov <ru@nginx.com>
parents:
5538
diff
changeset
|
551 |
461 | 552 /* the size of the last boundary CRLF "--0123456789--" CRLF */ |
493 | 553 |
554 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
|
555 |
963
78e70dae89f0
move ranges array to ngx_http_range_filter_ctx_t
Igor Sysoev <igor@sysoev.ru>
parents:
962
diff
changeset
|
556 range = ctx->ranges.elts; |
78e70dae89f0
move ranges array to ngx_http_range_filter_ctx_t
Igor Sysoev <igor@sysoev.ru>
parents:
962
diff
changeset
|
557 for (i = 0; i < ctx->ranges.nelts; i++) { |
455 | 558 |
461 | 559 /* the size of the range: "SSSS-EEEE/TTTT" CRLF CRLF */ |
455 | 560 |
461 | 561 range[i].content_range.data = |
2049 | 562 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
|
563 |
461 | 564 if (range[i].content_range.data == NULL) { |
565 return NGX_ERROR; | |
566 } | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
567 |
461 | 568 range[i].content_range.len = ngx_sprintf(range[i].content_range.data, |
569 "%O-%O/%O" CRLF CRLF, | |
570 range[i].start, range[i].end - 1, | |
571 r->headers_out.content_length_n) | |
572 - 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
|
573 |
461 | 574 len += ctx->boundary_header.len + range[i].content_range.len |
7090
a2f5e25d6a28
Range filter: changed type for total length to off_t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7067
diff
changeset
|
575 + (range[i].end - range[i].start); |
461 | 576 } |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
577 |
461 | 578 r->headers_out.content_length_n = len; |
960 | 579 |
580 if (r->headers_out.content_length) { | |
581 r->headers_out.content_length->hash = 0; | |
582 r->headers_out.content_length = NULL; | |
583 } | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
584 |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
153
diff
changeset
|
585 return ngx_http_next_header_filter(r); |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
586 } |
1630 | 587 |
588 | |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
589 static ngx_int_t |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
590 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
|
591 { |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
592 ngx_table_elt_t *content_range; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
593 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
594 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
|
595 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
596 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
|
597 if (content_range == NULL) { |
1630 | 598 return NGX_ERROR; |
599 } | |
600 | |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
601 r->headers_out.content_range = content_range; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
602 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
603 content_range->hash = 1; |
8031
d26db4f82d7d
All known output headers can be linked lists now.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7508
diff
changeset
|
604 content_range->next = NULL; |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3331
diff
changeset
|
605 ngx_str_set(&content_range->key, "Content-Range"); |
1630 | 606 |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
607 content_range->value.data = ngx_pnalloc(r->pool, |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
608 sizeof("bytes */") - 1 + NGX_OFF_T_LEN); |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
609 if (content_range->value.data == NULL) { |
6986
0cdee26605f3
Cleaned up r->headers_out.headers allocation error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6798
diff
changeset
|
610 content_range->hash = 0; |
0cdee26605f3
Cleaned up r->headers_out.headers allocation error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6798
diff
changeset
|
611 r->headers_out.content_range = NULL; |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
612 return NGX_ERROR; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
613 } |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
614 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
615 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
|
616 "bytes */%O", |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
617 r->headers_out.content_length_n) |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
618 - content_range->value.data; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
619 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
620 ngx_http_clear_content_length(r); |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
621 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
622 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
|
623 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
624 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
625 |
493 | 626 static ngx_int_t |
627 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
|
628 { |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
629 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
|
630 |
963
78e70dae89f0
move ranges array to ngx_http_range_filter_ctx_t
Igor Sysoev <igor@sysoev.ru>
parents:
962
diff
changeset
|
631 if (in == NULL) { |
78e70dae89f0
move ranges array to ngx_http_range_filter_ctx_t
Igor Sysoev <igor@sysoev.ru>
parents:
962
diff
changeset
|
632 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
|
633 } |
78e70dae89f0
move ranges array to ngx_http_range_filter_ctx_t
Igor Sysoev <igor@sysoev.ru>
parents:
962
diff
changeset
|
634 |
78e70dae89f0
move ranges array to ngx_http_range_filter_ctx_t
Igor Sysoev <igor@sysoev.ru>
parents:
962
diff
changeset
|
635 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
|
636 |
78e70dae89f0
move ranges array to ngx_http_range_filter_ctx_t
Igor Sysoev <igor@sysoev.ru>
parents:
962
diff
changeset
|
637 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
|
638 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
|
639 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
640 |
2121
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
641 if (ctx->ranges.nelts == 1) { |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
642 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
|
643 } |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
644 |
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 * 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
|
647 */ |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
648 |
962
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
649 if (ngx_buf_special(in->buf)) { |
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
650 return ngx_http_next_body_filter(r, in); |
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
651 } |
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
652 |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
653 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
|
654 return NGX_ERROR; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
655 } |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
656 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
657 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
|
658 } |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
659 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
660 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
661 static ngx_int_t |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
662 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
|
663 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
|
664 { |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
665 off_t start, last; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
666 ngx_buf_t *buf; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
667 ngx_uint_t i; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
668 ngx_http_range_t *range; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
669 |
962
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
670 if (ctx->offset) { |
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
671 goto overlapped; |
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
672 } |
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
673 |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
674 buf = in->buf; |
960 | 675 |
676 if (!buf->last_buf) { | |
4467
85a1570ce960
Removed r->cache/r->cached dependencies in range filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
677 start = ctx->offset; |
85a1570ce960
Removed r->cache/r->cached dependencies in range filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
678 last = ctx->offset + ngx_buf_size(buf); |
962
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
679 |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
680 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
|
681 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
|
682 if (start > range[i].start || last < range[i].end) { |
6474 | 683 goto overlapped; |
960 | 684 } |
685 } | |
686 } | |
687 | |
962
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
688 ctx->offset = ngx_buf_size(buf); |
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
689 |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
690 return NGX_OK; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
691 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
692 overlapped: |
960 | 693 |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
694 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
|
695 "range in overlapped buffers"); |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
696 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
697 return NGX_ERROR; |
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 |
962
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
700 |
2118
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_singlepart_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 { |
2121
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
705 off_t start, last; |
7507
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
706 ngx_int_t rc; |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
707 ngx_buf_t *buf; |
7507
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
708 ngx_chain_t *out, *cl, *tl, **ll; |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
709 ngx_http_range_t *range; |
960 | 710 |
2121
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
711 out = NULL; |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
712 ll = &out; |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
713 range = ctx->ranges.elts; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
714 |
2121
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
715 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
|
716 |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
717 buf = cl->buf; |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
718 |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
719 start = ctx->offset; |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
720 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
|
721 |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
722 ctx->offset = last; |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
723 |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
724 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
|
725 "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
|
726 |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
727 if (ngx_buf_special(buf)) { |
7507
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
728 |
7508
c30a20e06c21
Range filter: fixed duplicate last buffers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7507
diff
changeset
|
729 if (range->end <= start) { |
c30a20e06c21
Range filter: fixed duplicate last buffers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7507
diff
changeset
|
730 continue; |
c30a20e06c21
Range filter: fixed duplicate last buffers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7507
diff
changeset
|
731 } |
c30a20e06c21
Range filter: fixed duplicate last buffers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7507
diff
changeset
|
732 |
7507
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
733 tl = ngx_alloc_chain_link(r->pool); |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
734 if (tl == NULL) { |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
735 return NGX_ERROR; |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
736 } |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
737 |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
738 tl->buf = buf; |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
739 tl->next = NULL; |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
740 |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
741 *ll = tl; |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
742 ll = &tl->next; |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
743 |
2121
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
744 continue; |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
745 } |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
746 |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
747 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
|
748 |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
749 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
|
750 "http range body skip"); |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
751 |
2269 | 752 if (buf->in_file) { |
753 buf->file_pos = buf->file_last; | |
754 } | |
755 | |
2121
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
756 buf->pos = buf->last; |
2269 | 757 buf->sync = 1; |
758 | |
2121
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
759 continue; |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
760 } |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
761 |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
762 if (range->start > start) { |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
763 |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
764 if (buf->in_file) { |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
765 buf->file_pos += range->start - start; |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
766 } |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
767 |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
768 if (ngx_buf_in_memory(buf)) { |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
769 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
|
770 } |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
771 } |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
772 |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
773 if (range->end <= last) { |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
774 |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
775 if (buf->in_file) { |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
776 buf->file_last -= last - range->end; |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
777 } |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
778 |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
779 if (ngx_buf_in_memory(buf)) { |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
780 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
|
781 } |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
782 |
6722
6136a51f9c21
Do not set last_buf flag in subrequests.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
783 buf->last_buf = (r == r->main) ? 1 : 0; |
6136a51f9c21
Do not set last_buf flag in subrequests.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
784 buf->last_in_chain = 1; |
7507
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
785 |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
786 tl = ngx_alloc_chain_link(r->pool); |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
787 if (tl == NULL) { |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
788 return NGX_ERROR; |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
789 } |
2121
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
790 |
7507
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
791 tl->buf = buf; |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
792 tl->next = NULL; |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
793 |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
794 *ll = tl; |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
795 ll = &tl->next; |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
796 |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
797 continue; |
2121
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
798 } |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
799 |
7507
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
800 tl = ngx_alloc_chain_link(r->pool); |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
801 if (tl == NULL) { |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
802 return NGX_ERROR; |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
803 } |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
804 |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
805 tl->buf = buf; |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
806 tl->next = NULL; |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
807 |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
808 *ll = tl; |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
809 ll = &tl->next; |
960 | 810 } |
811 | |
7507
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
812 rc = ngx_http_next_body_filter(r, out); |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
813 |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
814 while (out) { |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
815 cl = out; |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
816 out = out->next; |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
817 ngx_free_chain(r->pool, cl); |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
818 } |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
819 |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
820 return rc; |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
821 } |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
822 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
823 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
824 static ngx_int_t |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
825 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
|
826 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
|
827 { |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
828 ngx_buf_t *b, *buf; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
829 ngx_uint_t i; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
830 ngx_chain_t *out, *hcl, *rcl, *dcl, **ll; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
831 ngx_http_range_t *range; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
832 |
960 | 833 ll = &out; |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
834 buf = in->buf; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
835 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
|
836 |
963
78e70dae89f0
move ranges array to ngx_http_range_filter_ctx_t
Igor Sysoev <igor@sysoev.ru>
parents:
962
diff
changeset
|
837 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
|
838 |
960 | 839 /* |
840 * The boundary header of the range: | |
841 * CRLF | |
842 * "--0123456789" CRLF | |
843 * "Content-Type: image/jpeg" CRLF | |
844 * "Content-Range: bytes " | |
845 */ | |
846 | |
847 b = ngx_calloc_buf(r->pool); | |
848 if (b == NULL) { | |
849 return NGX_ERROR; | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
850 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
851 |
960 | 852 b->memory = 1; |
853 b->pos = ctx->boundary_header.data; | |
854 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
|
855 |
960 | 856 hcl = ngx_alloc_chain_link(r->pool); |
857 if (hcl == NULL) { | |
858 return NGX_ERROR; | |
859 } | |
461 | 860 |
960 | 861 hcl->buf = b; |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
862 |
461 | 863 |
960 | 864 /* "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
|
865 |
501 | 866 b = ngx_calloc_buf(r->pool); |
867 if (b == NULL) { | |
461 | 868 return NGX_ERROR; |
869 } | |
870 | |
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
|
871 b->temporary = 1; |
960 | 872 b->pos = range[i].content_range.data; |
873 b->last = range[i].content_range.data + range[i].content_range.len; | |
874 | |
875 rcl = ngx_alloc_chain_link(r->pool); | |
876 if (rcl == NULL) { | |
877 return NGX_ERROR; | |
878 } | |
879 | |
880 rcl->buf = b; | |
881 | |
882 | |
883 /* the range data */ | |
461 | 884 |
960 | 885 b = ngx_calloc_buf(r->pool); |
886 if (b == NULL) { | |
887 return NGX_ERROR; | |
888 } | |
889 | |
962
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
890 b->in_file = buf->in_file; |
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
891 b->temporary = buf->temporary; |
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
892 b->memory = buf->memory; |
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
893 b->mmap = buf->mmap; |
960 | 894 b->file = buf->file; |
895 | |
962
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
896 if (buf->in_file) { |
4467
85a1570ce960
Removed r->cache/r->cached dependencies in range filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
897 b->file_pos = buf->file_pos + range[i].start; |
85a1570ce960
Removed r->cache/r->cached dependencies in range filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
898 b->file_last = buf->file_pos + range[i].end; |
962
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
899 } |
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
900 |
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
901 if (ngx_buf_in_memory(buf)) { |
4467
85a1570ce960
Removed r->cache/r->cached dependencies in range filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
902 b->pos = buf->pos + (size_t) range[i].start; |
85a1570ce960
Removed r->cache/r->cached dependencies in range filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
903 b->last = buf->pos + (size_t) range[i].end; |
962
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
904 } |
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
905 |
960 | 906 dcl = ngx_alloc_chain_link(r->pool); |
907 if (dcl == NULL) { | |
461 | 908 return NGX_ERROR; |
909 } | |
910 | |
960 | 911 dcl->buf = b; |
461 | 912 |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
153
diff
changeset
|
913 *ll = hcl; |
960 | 914 hcl->next = rcl; |
915 rcl->next = dcl; | |
916 ll = &dcl->next; | |
917 } | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
918 |
960 | 919 /* the last boundary CRLF "--0123456789--" CRLF */ |
920 | |
921 b = ngx_calloc_buf(r->pool); | |
922 if (b == NULL) { | |
923 return NGX_ERROR; | |
924 } | |
925 | |
926 b->temporary = 1; | |
927 b->last_buf = 1; | |
928 | |
2049 | 929 b->pos = ngx_pnalloc(r->pool, sizeof(CRLF "--") - 1 + NGX_ATOMIC_T_LEN |
930 + sizeof("--" CRLF) - 1); | |
960 | 931 if (b->pos == NULL) { |
932 return NGX_ERROR; | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
933 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
934 |
1195
4ba6df5d5b53
fix multipart ranges trailing
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
935 b->last = ngx_cpymem(b->pos, ctx->boundary_header.data, |
4ba6df5d5b53
fix multipart ranges trailing
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
936 sizeof(CRLF "--") - 1 + NGX_ATOMIC_T_LEN); |
960 | 937 *b->last++ = '-'; *b->last++ = '-'; |
938 *b->last++ = CR; *b->last++ = LF; | |
939 | |
940 hcl = ngx_alloc_chain_link(r->pool); | |
941 if (hcl == NULL) { | |
942 return NGX_ERROR; | |
943 } | |
944 | |
945 hcl->buf = b; | |
946 hcl->next = NULL; | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
947 |
960 | 948 *ll = hcl; |
949 | |
950 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
|
951 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
952 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
953 |
493 | 954 static ngx_int_t |
681 | 955 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
|
956 { |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
153
diff
changeset
|
957 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
|
958 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
|
959 |
334
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
314
diff
changeset
|
960 return NGX_OK; |
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
314
diff
changeset
|
961 } |
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
314
diff
changeset
|
962 |
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
314
diff
changeset
|
963 |
493 | 964 static ngx_int_t |
681 | 965 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
|
966 { |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
153
diff
changeset
|
967 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
|
968 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
|
969 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
970 return NGX_OK; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
971 } |