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