annotate src/http/modules/ngx_http_range_filter_module.c @ 570:8246d8a2c2be NGINX_0_8_37

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