Mercurial > hg > nginx
annotate src/http/modules/ngx_http_range_filter_module.c @ 7957:f5732fa038ad stable-1.20
gRPC: handling GOAWAY with a higher last stream identifier.
Previously, once received from upstream, it couldn't limit
opening additional streams in a cached keepalive connection.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Thu, 17 Jun 2021 11:43:55 +0300 |
parents | c30a20e06c21 |
children | d26db4f82d7d |
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; |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3331
diff
changeset
|
261 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
|
262 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
|
263 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
264 return ngx_http_next_header_filter(r); |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
265 } |
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 |
4058
d32a2000b766
ngx_http_range_parse() should be static.
Igor Sysoev <igor@sysoev.ru>
parents:
4057
diff
changeset
|
268 static ngx_int_t |
4062 | 269 ngx_http_range_parse(ngx_http_request_t *r, ngx_http_range_filter_ctx_t *ctx, |
270 ngx_uint_t ranges) | |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
271 { |
6317 | 272 u_char *p; |
273 off_t start, end, size, content_length, cutoff, | |
274 cutlim; | |
275 ngx_uint_t suffix; | |
276 ngx_http_range_t *range; | |
277 ngx_http_range_filter_ctx_t *mctx; | |
278 | |
279 if (r != r->main) { | |
280 mctx = ngx_http_get_module_ctx(r->main, | |
281 ngx_http_range_body_filter_module); | |
282 if (mctx) { | |
283 ctx->ranges = mctx->ranges; | |
284 return NGX_OK; | |
285 } | |
286 } | |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
287 |
6798
2decd6b34306
Range filter: only initialize ctx->ranges in main request.
hucongcong <hucong.c@foxmail.com>
parents:
6722
diff
changeset
|
288 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
|
289 != NGX_OK) |
2decd6b34306
Range filter: only initialize ctx->ranges in main request.
hucongcong <hucong.c@foxmail.com>
parents:
6722
diff
changeset
|
290 { |
2decd6b34306
Range filter: only initialize ctx->ranges in main request.
hucongcong <hucong.c@foxmail.com>
parents:
6722
diff
changeset
|
291 return NGX_ERROR; |
2decd6b34306
Range filter: only initialize ctx->ranges in main request.
hucongcong <hucong.c@foxmail.com>
parents:
6722
diff
changeset
|
292 } |
2decd6b34306
Range filter: only initialize ctx->ranges in main request.
hucongcong <hucong.c@foxmail.com>
parents:
6722
diff
changeset
|
293 |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
294 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
|
295 size = 0; |
4057
3205a6d6c6ec
Ranges processing small optimization.
Igor Sysoev <igor@sysoev.ru>
parents:
4056
diff
changeset
|
296 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
|
297 |
6013
9653092a79fd
Overflow detection in ngx_http_range_parse().
Ruslan Ermilov <ru@nginx.com>
parents:
5621
diff
changeset
|
298 cutoff = NGX_MAX_OFF_T_VALUE / 10; |
9653092a79fd
Overflow detection in ngx_http_range_parse().
Ruslan Ermilov <ru@nginx.com>
parents:
5621
diff
changeset
|
299 cutlim = NGX_MAX_OFF_T_VALUE % 10; |
9653092a79fd
Overflow detection in ngx_http_range_parse().
Ruslan Ermilov <ru@nginx.com>
parents:
5621
diff
changeset
|
300 |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
301 for ( ;; ) { |
231
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
302 start = 0; |
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
303 end = 0; |
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
304 suffix = 0; |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
305 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
306 while (*p == ' ') { p++; } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
307 |
231
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
308 if (*p != '-') { |
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
309 if (*p < '0' || *p > '9') { |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
310 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
|
311 } |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
312 |
231
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
313 while (*p >= '0' && *p <= '9') { |
6013
9653092a79fd
Overflow detection in ngx_http_range_parse().
Ruslan Ermilov <ru@nginx.com>
parents:
5621
diff
changeset
|
314 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
|
315 return NGX_HTTP_RANGE_NOT_SATISFIABLE; |
9653092a79fd
Overflow detection in ngx_http_range_parse().
Ruslan Ermilov <ru@nginx.com>
parents:
5621
diff
changeset
|
316 } |
9653092a79fd
Overflow detection in ngx_http_range_parse().
Ruslan Ermilov <ru@nginx.com>
parents:
5621
diff
changeset
|
317 |
7067
e3723f2a11b7
Parenthesized ASCII-related calculations.
Valentin Bartenev <vbart@nginx.com>
parents:
7055
diff
changeset
|
318 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
|
319 } |
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 while (*p == ' ') { p++; } |
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
322 |
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
323 if (*p++ != '-') { |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
324 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
|
325 } |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
326 |
231
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
327 while (*p == ' ') { p++; } |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
328 |
231
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
329 if (*p == ',' || *p == '\0') { |
4057
3205a6d6c6ec
Ranges processing small optimization.
Igor Sysoev <igor@sysoev.ru>
parents:
4056
diff
changeset
|
330 end = content_length; |
4055
9cce506be97d
Ranges processing small optimization.
Igor Sysoev <igor@sysoev.ru>
parents:
4054
diff
changeset
|
331 goto found; |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
332 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
333 |
231
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
334 } else { |
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
335 suffix = 1; |
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
336 p++; |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
337 } |
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 if (*p < '0' || *p > '9') { |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
340 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
|
341 } |
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 while (*p >= '0' && *p <= '9') { |
6013
9653092a79fd
Overflow detection in ngx_http_range_parse().
Ruslan Ermilov <ru@nginx.com>
parents:
5621
diff
changeset
|
344 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
|
345 return NGX_HTTP_RANGE_NOT_SATISFIABLE; |
9653092a79fd
Overflow detection in ngx_http_range_parse().
Ruslan Ermilov <ru@nginx.com>
parents:
5621
diff
changeset
|
346 } |
9653092a79fd
Overflow detection in ngx_http_range_parse().
Ruslan Ermilov <ru@nginx.com>
parents:
5621
diff
changeset
|
347 |
7067
e3723f2a11b7
Parenthesized ASCII-related calculations.
Valentin Bartenev <vbart@nginx.com>
parents:
7055
diff
changeset
|
348 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
|
349 } |
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 while (*p == ' ') { p++; } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
352 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
353 if (*p != ',' && *p != '\0') { |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
354 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
|
355 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
356 |
231
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
357 if (suffix) { |
7055
887c8c58ffeb
Range filter: avoid negative range start.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7054
diff
changeset
|
358 start = (end < content_length) ? content_length - end : 0; |
4057
3205a6d6c6ec
Ranges processing small optimization.
Igor Sysoev <igor@sysoev.ru>
parents:
4056
diff
changeset
|
359 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
|
360 } |
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
361 |
4057
3205a6d6c6ec
Ranges processing small optimization.
Igor Sysoev <igor@sysoev.ru>
parents:
4056
diff
changeset
|
362 if (end >= content_length) { |
3205a6d6c6ec
Ranges processing small optimization.
Igor Sysoev <igor@sysoev.ru>
parents:
4056
diff
changeset
|
363 end = content_length; |
4055
9cce506be97d
Ranges processing small optimization.
Igor Sysoev <igor@sysoev.ru>
parents:
4054
diff
changeset
|
364 |
9cce506be97d
Ranges processing small optimization.
Igor Sysoev <igor@sysoev.ru>
parents:
4054
diff
changeset
|
365 } else { |
9cce506be97d
Ranges processing small optimization.
Igor Sysoev <igor@sysoev.ru>
parents:
4054
diff
changeset
|
366 end++; |
9cce506be97d
Ranges processing small optimization.
Igor Sysoev <igor@sysoev.ru>
parents:
4054
diff
changeset
|
367 } |
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 found: |
9cce506be97d
Ranges processing small optimization.
Igor Sysoev <igor@sysoev.ru>
parents:
4054
diff
changeset
|
370 |
4060
45de8d258085
*) fix of r4060: start value should be tested after the "found" label;
Igor Sysoev <igor@sysoev.ru>
parents:
4059
diff
changeset
|
371 if (start < end) { |
4061
bd2ec6ce5d58
Style fix: removal of tabs introduced in the previous commit.
Igor Sysoev <igor@sysoev.ru>
parents:
4060
diff
changeset
|
372 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
|
373 if (range == NULL) { |
bd2ec6ce5d58
Style fix: removal of tabs introduced in the previous commit.
Igor Sysoev <igor@sysoev.ru>
parents:
4060
diff
changeset
|
374 return NGX_ERROR; |
bd2ec6ce5d58
Style fix: removal of tabs introduced in the previous commit.
Igor Sysoev <igor@sysoev.ru>
parents:
4060
diff
changeset
|
375 } |
461 | 376 |
4061
bd2ec6ce5d58
Style fix: removal of tabs introduced in the previous commit.
Igor Sysoev <igor@sysoev.ru>
parents:
4060
diff
changeset
|
377 range->start = start; |
bd2ec6ce5d58
Style fix: removal of tabs introduced in the previous commit.
Igor Sysoev <igor@sysoev.ru>
parents:
4060
diff
changeset
|
378 range->end = end; |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
379 |
7054
e02555553d0b
Range filter: protect from total size overflows.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7043
diff
changeset
|
380 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
|
381 return NGX_HTTP_RANGE_NOT_SATISFIABLE; |
e02555553d0b
Range filter: protect from total size overflows.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7043
diff
changeset
|
382 } |
e02555553d0b
Range filter: protect from total size overflows.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7043
diff
changeset
|
383 |
4061
bd2ec6ce5d58
Style fix: removal of tabs introduced in the previous commit.
Igor Sysoev <igor@sysoev.ru>
parents:
4060
diff
changeset
|
384 size += end - start; |
4062 | 385 |
4063
8d70904b6c48
Now if client requests more ranges than "max_ranges" permits,
Igor Sysoev <igor@sysoev.ru>
parents:
4062
diff
changeset
|
386 if (ranges-- == 0) { |
8d70904b6c48
Now if client requests more ranges than "max_ranges" permits,
Igor Sysoev <igor@sysoev.ru>
parents:
4062
diff
changeset
|
387 return NGX_DECLINED; |
4062 | 388 } |
7043
aeaac3ccee4f
Range filter: allowed ranges on empty files (ticket #1031).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6986
diff
changeset
|
389 |
aeaac3ccee4f
Range filter: allowed ranges on empty files (ticket #1031).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6986
diff
changeset
|
390 } else if (start == 0) { |
aeaac3ccee4f
Range filter: allowed ranges on empty files (ticket #1031).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6986
diff
changeset
|
391 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
|
392 } |
4056
e9213133993a
Now unsatisfiable ranges are processed according to RFC 2616.
Igor Sysoev <igor@sysoev.ru>
parents:
4055
diff
changeset
|
393 |
231
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
394 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
|
395 break; |
231
92db0aa1e83f
nginx-0.0.1-2004-01-16-21:29:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
195
diff
changeset
|
396 } |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
397 } |
4035
c2a91088b0c0
Now if total size of all ranges is greater than source response size,
Igor Sysoev <igor@sysoev.ru>
parents:
3516
diff
changeset
|
398 |
4056
e9213133993a
Now unsatisfiable ranges are processed according to RFC 2616.
Igor Sysoev <igor@sysoev.ru>
parents:
4055
diff
changeset
|
399 if (ctx->ranges.nelts == 0) { |
e9213133993a
Now unsatisfiable ranges are processed according to RFC 2616.
Igor Sysoev <igor@sysoev.ru>
parents:
4055
diff
changeset
|
400 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
|
401 } |
e9213133993a
Now unsatisfiable ranges are processed according to RFC 2616.
Igor Sysoev <igor@sysoev.ru>
parents:
4055
diff
changeset
|
402 |
4057
3205a6d6c6ec
Ranges processing small optimization.
Igor Sysoev <igor@sysoev.ru>
parents:
4056
diff
changeset
|
403 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
|
404 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
|
405 } |
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 return NGX_OK; |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
408 } |
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 static ngx_int_t |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
412 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
|
413 ngx_http_range_filter_ctx_t *ctx) |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
414 { |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
415 ngx_table_elt_t *content_range; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
416 ngx_http_range_t *range; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
417 |
6317 | 418 if (r != r->main) { |
419 return ngx_http_next_header_filter(r); | |
420 } | |
421 | |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
422 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
|
423 if (content_range == NULL) { |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
424 return NGX_ERROR; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
425 } |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
426 |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
427 r->headers_out.content_range = content_range; |
461 | 428 |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
429 content_range->hash = 1; |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3331
diff
changeset
|
430 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
|
431 |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
432 content_range->value.data = ngx_pnalloc(r->pool, |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
433 sizeof("bytes -/") - 1 + 3 * NGX_OFF_T_LEN); |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
434 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
|
435 content_range->hash = 0; |
0cdee26605f3
Cleaned up r->headers_out.headers allocation error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6798
diff
changeset
|
436 r->headers_out.content_range = NULL; |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
437 return NGX_ERROR; |
461 | 438 } |
439 | |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
440 /* "Content-Range: bytes SSSS-EEEE/TTTT" header */ |
461 | 441 |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
442 range = ctx->ranges.elts; |
461 | 443 |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
444 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
|
445 "bytes %O-%O/%O", |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
446 range->start, range->end - 1, |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
447 r->headers_out.content_length_n) |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
448 - content_range->value.data; |
461 | 449 |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
450 r->headers_out.content_length_n = range->end - range->start; |
6317 | 451 r->headers_out.content_offset = range->start; |
461 | 452 |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
453 if (r->headers_out.content_length) { |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
454 r->headers_out.content_length->hash = 0; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
455 r->headers_out.content_length = NULL; |
461 | 456 } |
457 | |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
458 return ngx_http_next_header_filter(r); |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
459 } |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
460 |
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 static ngx_int_t |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
463 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
|
464 ngx_http_range_filter_ctx_t *ctx) |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
465 { |
7090
a2f5e25d6a28
Range filter: changed type for total length to off_t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7067
diff
changeset
|
466 off_t len; |
a2f5e25d6a28
Range filter: changed type for total length to off_t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7067
diff
changeset
|
467 size_t size; |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
468 ngx_uint_t i; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
469 ngx_http_range_t *range; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
470 ngx_atomic_uint_t boundary; |
461 | 471 |
7090
a2f5e25d6a28
Range filter: changed type for total length to off_t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7067
diff
changeset
|
472 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
|
473 + 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
|
474 + 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
|
475 + sizeof(CRLF "Content-Range: bytes ") - 1; |
461 | 476 |
5558
eeb3c2719147
Range filter: fixed duplicate charset.
Ruslan Ermilov <ru@nginx.com>
parents:
5538
diff
changeset
|
477 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
|
478 && r->headers_out.charset.len) |
eeb3c2719147
Range filter: fixed duplicate charset.
Ruslan Ermilov <ru@nginx.com>
parents:
5538
diff
changeset
|
479 { |
7090
a2f5e25d6a28
Range filter: changed type for total length to off_t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7067
diff
changeset
|
480 size += sizeof("; charset=") - 1 + r->headers_out.charset.len; |
461 | 481 } |
482 | |
7090
a2f5e25d6a28
Range filter: changed type for total length to off_t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7067
diff
changeset
|
483 ctx->boundary_header.data = ngx_pnalloc(r->pool, size); |
501 | 484 if (ctx->boundary_header.data == NULL) { |
461 | 485 return NGX_ERROR; |
486 } | |
487 | |
493 | 488 boundary = ngx_next_temp_number(0); |
461 | 489 |
490 /* | |
491 * The boundary header of the range: | |
492 * CRLF | |
493 * "--0123456789" CRLF | |
494 * "Content-Type: image/jpeg" CRLF | |
495 * "Content-Range: bytes " | |
496 */ | |
497 | |
5558
eeb3c2719147
Range filter: fixed duplicate charset.
Ruslan Ermilov <ru@nginx.com>
parents:
5538
diff
changeset
|
498 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
|
499 && r->headers_out.charset.len) |
eeb3c2719147
Range filter: fixed duplicate charset.
Ruslan Ermilov <ru@nginx.com>
parents:
5538
diff
changeset
|
500 { |
461 | 501 ctx->boundary_header.len = ngx_sprintf(ctx->boundary_header.data, |
493 | 502 CRLF "--%0muA" CRLF |
461 | 503 "Content-Type: %V; charset=%V" CRLF |
504 "Content-Range: bytes ", | |
505 boundary, | |
509 | 506 &r->headers_out.content_type, |
461 | 507 &r->headers_out.charset) |
508 - ctx->boundary_header.data; | |
509 | |
2119
0799703985ef
fix ranges without Content-Type
Igor Sysoev <igor@sysoev.ru>
parents:
2118
diff
changeset
|
510 } else if (r->headers_out.content_type.len) { |
461 | 511 ctx->boundary_header.len = ngx_sprintf(ctx->boundary_header.data, |
493 | 512 CRLF "--%0muA" CRLF |
461 | 513 "Content-Type: %V" CRLF |
514 "Content-Range: bytes ", | |
515 boundary, | |
509 | 516 &r->headers_out.content_type) |
461 | 517 - ctx->boundary_header.data; |
2119
0799703985ef
fix ranges without Content-Type
Igor Sysoev <igor@sysoev.ru>
parents:
2118
diff
changeset
|
518 |
0799703985ef
fix ranges without Content-Type
Igor Sysoev <igor@sysoev.ru>
parents:
2118
diff
changeset
|
519 } else { |
0799703985ef
fix ranges without Content-Type
Igor Sysoev <igor@sysoev.ru>
parents:
2118
diff
changeset
|
520 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
|
521 CRLF "--%0muA" CRLF |
0799703985ef
fix ranges without Content-Type
Igor Sysoev <igor@sysoev.ru>
parents:
2118
diff
changeset
|
522 "Content-Range: bytes ", |
0799703985ef
fix ranges without Content-Type
Igor Sysoev <igor@sysoev.ru>
parents:
2118
diff
changeset
|
523 boundary) |
0799703985ef
fix ranges without Content-Type
Igor Sysoev <igor@sysoev.ru>
parents:
2118
diff
changeset
|
524 - ctx->boundary_header.data; |
461 | 525 } |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
526 |
509 | 527 r->headers_out.content_type.data = |
2049 | 528 ngx_pnalloc(r->pool, |
529 sizeof("Content-Type: multipart/byteranges; boundary=") - 1 | |
530 + 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
|
531 |
509 | 532 if (r->headers_out.content_type.data == NULL) { |
461 | 533 return NGX_ERROR; |
534 } | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
535 |
2882
896db5a09bd2
reset content_type hash value, this fixes a bug when XSLT responses
Igor Sysoev <igor@sysoev.ru>
parents:
2592
diff
changeset
|
536 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
|
537 |
461 | 538 /* "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
|
539 |
509 | 540 r->headers_out.content_type.len = |
541 ngx_sprintf(r->headers_out.content_type.data, | |
493 | 542 "multipart/byteranges; boundary=%0muA", |
461 | 543 boundary) |
509 | 544 - 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
|
545 |
2882
896db5a09bd2
reset content_type hash value, this fixes a bug when XSLT responses
Igor Sysoev <igor@sysoev.ru>
parents:
2592
diff
changeset
|
546 r->headers_out.content_type_len = r->headers_out.content_type.len; |
493 | 547 |
5558
eeb3c2719147
Range filter: fixed duplicate charset.
Ruslan Ermilov <ru@nginx.com>
parents:
5538
diff
changeset
|
548 r->headers_out.charset.len = 0; |
eeb3c2719147
Range filter: fixed duplicate charset.
Ruslan Ermilov <ru@nginx.com>
parents:
5538
diff
changeset
|
549 |
461 | 550 /* the size of the last boundary CRLF "--0123456789--" CRLF */ |
493 | 551 |
552 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
|
553 |
963
78e70dae89f0
move ranges array to ngx_http_range_filter_ctx_t
Igor Sysoev <igor@sysoev.ru>
parents:
962
diff
changeset
|
554 range = ctx->ranges.elts; |
78e70dae89f0
move ranges array to ngx_http_range_filter_ctx_t
Igor Sysoev <igor@sysoev.ru>
parents:
962
diff
changeset
|
555 for (i = 0; i < ctx->ranges.nelts; i++) { |
455 | 556 |
461 | 557 /* the size of the range: "SSSS-EEEE/TTTT" CRLF CRLF */ |
455 | 558 |
461 | 559 range[i].content_range.data = |
2049 | 560 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
|
561 |
461 | 562 if (range[i].content_range.data == NULL) { |
563 return NGX_ERROR; | |
564 } | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
565 |
461 | 566 range[i].content_range.len = ngx_sprintf(range[i].content_range.data, |
567 "%O-%O/%O" CRLF CRLF, | |
568 range[i].start, range[i].end - 1, | |
569 r->headers_out.content_length_n) | |
570 - 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
|
571 |
461 | 572 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
|
573 + (range[i].end - range[i].start); |
461 | 574 } |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
575 |
461 | 576 r->headers_out.content_length_n = len; |
960 | 577 |
578 if (r->headers_out.content_length) { | |
579 r->headers_out.content_length->hash = 0; | |
580 r->headers_out.content_length = NULL; | |
581 } | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
582 |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
153
diff
changeset
|
583 return ngx_http_next_header_filter(r); |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
584 } |
1630 | 585 |
586 | |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
587 static ngx_int_t |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
588 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
|
589 { |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
590 ngx_table_elt_t *content_range; |
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 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
|
593 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
594 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
|
595 if (content_range == NULL) { |
1630 | 596 return NGX_ERROR; |
597 } | |
598 | |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
599 r->headers_out.content_range = content_range; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
600 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
601 content_range->hash = 1; |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3331
diff
changeset
|
602 ngx_str_set(&content_range->key, "Content-Range"); |
1630 | 603 |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
604 content_range->value.data = ngx_pnalloc(r->pool, |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
605 sizeof("bytes */") - 1 + NGX_OFF_T_LEN); |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
606 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
|
607 content_range->hash = 0; |
0cdee26605f3
Cleaned up r->headers_out.headers allocation error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6798
diff
changeset
|
608 r->headers_out.content_range = NULL; |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
609 return NGX_ERROR; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
610 } |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
611 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
612 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
|
613 "bytes */%O", |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
614 r->headers_out.content_length_n) |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
615 - content_range->value.data; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
616 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
617 ngx_http_clear_content_length(r); |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
618 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
619 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
|
620 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
621 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
622 |
493 | 623 static ngx_int_t |
624 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
|
625 { |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
626 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
|
627 |
963
78e70dae89f0
move ranges array to ngx_http_range_filter_ctx_t
Igor Sysoev <igor@sysoev.ru>
parents:
962
diff
changeset
|
628 if (in == NULL) { |
78e70dae89f0
move ranges array to ngx_http_range_filter_ctx_t
Igor Sysoev <igor@sysoev.ru>
parents:
962
diff
changeset
|
629 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
|
630 } |
78e70dae89f0
move ranges array to ngx_http_range_filter_ctx_t
Igor Sysoev <igor@sysoev.ru>
parents:
962
diff
changeset
|
631 |
78e70dae89f0
move ranges array to ngx_http_range_filter_ctx_t
Igor Sysoev <igor@sysoev.ru>
parents:
962
diff
changeset
|
632 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
|
633 |
78e70dae89f0
move ranges array to ngx_http_range_filter_ctx_t
Igor Sysoev <igor@sysoev.ru>
parents:
962
diff
changeset
|
634 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
|
635 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
|
636 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
637 |
2121
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
638 if (ctx->ranges.nelts == 1) { |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
639 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
|
640 } |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
641 |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
642 /* |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
643 * 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
|
644 */ |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
645 |
962
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
646 if (ngx_buf_special(in->buf)) { |
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
647 return ngx_http_next_body_filter(r, in); |
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
648 } |
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
649 |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
650 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
|
651 return NGX_ERROR; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
652 } |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
653 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
654 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
|
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 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
658 static ngx_int_t |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
659 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
|
660 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
|
661 { |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
662 off_t start, last; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
663 ngx_buf_t *buf; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
664 ngx_uint_t i; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
665 ngx_http_range_t *range; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
666 |
962
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
667 if (ctx->offset) { |
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
668 goto overlapped; |
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
669 } |
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
670 |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
671 buf = in->buf; |
960 | 672 |
673 if (!buf->last_buf) { | |
4467
85a1570ce960
Removed r->cache/r->cached dependencies in range filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
674 start = ctx->offset; |
85a1570ce960
Removed r->cache/r->cached dependencies in range filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
675 last = ctx->offset + ngx_buf_size(buf); |
962
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
676 |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
677 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
|
678 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
|
679 if (start > range[i].start || last < range[i].end) { |
6474 | 680 goto overlapped; |
960 | 681 } |
682 } | |
683 } | |
684 | |
962
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
685 ctx->offset = ngx_buf_size(buf); |
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
686 |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
687 return NGX_OK; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
688 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
689 overlapped: |
960 | 690 |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
691 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
|
692 "range in overlapped buffers"); |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
693 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
694 return NGX_ERROR; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
695 } |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
696 |
962
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
697 |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
698 static ngx_int_t |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
699 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
|
700 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
|
701 { |
2121
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
702 off_t start, last; |
7507
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
703 ngx_int_t rc; |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
704 ngx_buf_t *buf; |
7507
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
705 ngx_chain_t *out, *cl, *tl, **ll; |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
706 ngx_http_range_t *range; |
960 | 707 |
2121
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
708 out = NULL; |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
709 ll = &out; |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
710 range = ctx->ranges.elts; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
711 |
2121
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
712 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
|
713 |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
714 buf = cl->buf; |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
715 |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
716 start = ctx->offset; |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
717 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
|
718 |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
719 ctx->offset = last; |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
720 |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
721 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
|
722 "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
|
723 |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
724 if (ngx_buf_special(buf)) { |
7507
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
725 |
7508
c30a20e06c21
Range filter: fixed duplicate last buffers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7507
diff
changeset
|
726 if (range->end <= start) { |
c30a20e06c21
Range filter: fixed duplicate last buffers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7507
diff
changeset
|
727 continue; |
c30a20e06c21
Range filter: fixed duplicate last buffers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7507
diff
changeset
|
728 } |
c30a20e06c21
Range filter: fixed duplicate last buffers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7507
diff
changeset
|
729 |
7507
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
730 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
|
731 if (tl == NULL) { |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
732 return NGX_ERROR; |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
733 } |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
734 |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
735 tl->buf = buf; |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
736 tl->next = NULL; |
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 *ll = tl; |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
739 ll = &tl->next; |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
740 |
2121
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
741 continue; |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
742 } |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
743 |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
744 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
|
745 |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
746 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
|
747 "http range body skip"); |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
748 |
2269 | 749 if (buf->in_file) { |
750 buf->file_pos = buf->file_last; | |
751 } | |
752 | |
2121
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
753 buf->pos = buf->last; |
2269 | 754 buf->sync = 1; |
755 | |
2121
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
756 continue; |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
757 } |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
758 |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
759 if (range->start > start) { |
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 if (buf->in_file) { |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
762 buf->file_pos += 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 |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
765 if (ngx_buf_in_memory(buf)) { |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
766 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
|
767 } |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
768 } |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
769 |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
770 if (range->end <= last) { |
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 if (buf->in_file) { |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
773 buf->file_last -= last - range->end; |
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 |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
776 if (ngx_buf_in_memory(buf)) { |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
777 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
|
778 } |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
779 |
6722
6136a51f9c21
Do not set last_buf flag in subrequests.
Roman Arutyunyan <arut@nginx.com>
parents:
6480
diff
changeset
|
780 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
|
781 buf->last_in_chain = 1; |
7507
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
782 |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
783 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
|
784 if (tl == NULL) { |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
785 return NGX_ERROR; |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
786 } |
2121
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
787 |
7507
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
788 tl->buf = buf; |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
789 tl->next = NULL; |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
790 |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
791 *ll = tl; |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
792 ll = &tl->next; |
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 continue; |
2121
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
795 } |
b39c0040b3e4
support several buf's for single-part range
Igor Sysoev <igor@sysoev.ru>
parents:
2119
diff
changeset
|
796 |
7507
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
797 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
|
798 if (tl == NULL) { |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
799 return NGX_ERROR; |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
800 } |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
801 |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
802 tl->buf = buf; |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
803 tl->next = NULL; |
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 *ll = tl; |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
806 ll = &tl->next; |
960 | 807 } |
808 | |
7507
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
809 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
|
810 |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
811 while (out) { |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
812 cl = out; |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
813 out = out->next; |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
814 ngx_free_chain(r->pool, cl); |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
815 } |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
816 |
ea05113adbdb
Range filter: fixed loss of incoming chain links.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7090
diff
changeset
|
817 return rc; |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
818 } |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
819 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
820 |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
821 static ngx_int_t |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
822 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
|
823 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
|
824 { |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
825 ngx_buf_t *b, *buf; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
826 ngx_uint_t i; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
827 ngx_chain_t *out, *hcl, *rcl, *dcl, **ll; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
828 ngx_http_range_t *range; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
829 |
960 | 830 ll = &out; |
2118
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
831 buf = in->buf; |
c1f589732d8c
split ngx_http_range_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
832 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
|
833 |
963
78e70dae89f0
move ranges array to ngx_http_range_filter_ctx_t
Igor Sysoev <igor@sysoev.ru>
parents:
962
diff
changeset
|
834 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
|
835 |
960 | 836 /* |
837 * The boundary header of the range: | |
838 * CRLF | |
839 * "--0123456789" CRLF | |
840 * "Content-Type: image/jpeg" CRLF | |
841 * "Content-Range: bytes " | |
842 */ | |
843 | |
844 b = ngx_calloc_buf(r->pool); | |
845 if (b == NULL) { | |
846 return NGX_ERROR; | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
847 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
848 |
960 | 849 b->memory = 1; |
850 b->pos = ctx->boundary_header.data; | |
851 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
|
852 |
960 | 853 hcl = ngx_alloc_chain_link(r->pool); |
854 if (hcl == NULL) { | |
855 return NGX_ERROR; | |
856 } | |
461 | 857 |
960 | 858 hcl->buf = b; |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
859 |
461 | 860 |
960 | 861 /* "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
|
862 |
501 | 863 b = ngx_calloc_buf(r->pool); |
864 if (b == NULL) { | |
461 | 865 return NGX_ERROR; |
866 } | |
867 | |
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
|
868 b->temporary = 1; |
960 | 869 b->pos = range[i].content_range.data; |
870 b->last = range[i].content_range.data + range[i].content_range.len; | |
871 | |
872 rcl = ngx_alloc_chain_link(r->pool); | |
873 if (rcl == NULL) { | |
874 return NGX_ERROR; | |
875 } | |
876 | |
877 rcl->buf = b; | |
878 | |
879 | |
880 /* the range data */ | |
461 | 881 |
960 | 882 b = ngx_calloc_buf(r->pool); |
883 if (b == NULL) { | |
884 return NGX_ERROR; | |
885 } | |
886 | |
962
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
887 b->in_file = buf->in_file; |
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
888 b->temporary = buf->temporary; |
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
889 b->memory = buf->memory; |
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
890 b->mmap = buf->mmap; |
960 | 891 b->file = buf->file; |
892 | |
962
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
893 if (buf->in_file) { |
4467
85a1570ce960
Removed r->cache/r->cached dependencies in range filter.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
894 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
|
895 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
|
896 } |
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
897 |
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
898 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
|
899 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
|
900 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
|
901 } |
69754fb59ba1
support ranges for single memory buffer
Igor Sysoev <igor@sysoev.ru>
parents:
961
diff
changeset
|
902 |
960 | 903 dcl = ngx_alloc_chain_link(r->pool); |
904 if (dcl == NULL) { | |
461 | 905 return NGX_ERROR; |
906 } | |
907 | |
960 | 908 dcl->buf = b; |
461 | 909 |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
153
diff
changeset
|
910 *ll = hcl; |
960 | 911 hcl->next = rcl; |
912 rcl->next = dcl; | |
913 ll = &dcl->next; | |
914 } | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
915 |
960 | 916 /* the last boundary CRLF "--0123456789--" CRLF */ |
917 | |
918 b = ngx_calloc_buf(r->pool); | |
919 if (b == NULL) { | |
920 return NGX_ERROR; | |
921 } | |
922 | |
923 b->temporary = 1; | |
924 b->last_buf = 1; | |
925 | |
2049 | 926 b->pos = ngx_pnalloc(r->pool, sizeof(CRLF "--") - 1 + NGX_ATOMIC_T_LEN |
927 + sizeof("--" CRLF) - 1); | |
960 | 928 if (b->pos == NULL) { |
929 return NGX_ERROR; | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
930 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
931 |
1195
4ba6df5d5b53
fix multipart ranges trailing
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
932 b->last = ngx_cpymem(b->pos, ctx->boundary_header.data, |
4ba6df5d5b53
fix multipart ranges trailing
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
933 sizeof(CRLF "--") - 1 + NGX_ATOMIC_T_LEN); |
960 | 934 *b->last++ = '-'; *b->last++ = '-'; |
935 *b->last++ = CR; *b->last++ = LF; | |
936 | |
937 hcl = ngx_alloc_chain_link(r->pool); | |
938 if (hcl == NULL) { | |
939 return NGX_ERROR; | |
940 } | |
941 | |
942 hcl->buf = b; | |
943 hcl->next = NULL; | |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
944 |
960 | 945 *ll = hcl; |
946 | |
947 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
|
948 } |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
949 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
950 |
493 | 951 static ngx_int_t |
681 | 952 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
|
953 { |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
153
diff
changeset
|
954 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
|
955 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
|
956 |
334
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
314
diff
changeset
|
957 return NGX_OK; |
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
314
diff
changeset
|
958 } |
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
314
diff
changeset
|
959 |
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
314
diff
changeset
|
960 |
493 | 961 static ngx_int_t |
681 | 962 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
|
963 { |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
153
diff
changeset
|
964 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
|
965 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
|
966 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
967 return NGX_OK; |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
968 } |