comparison ngx_http_bytes_filter_module.c @ 2:13a2fbcc8bc4

Change Content-Length to match total requested length.
author Maxim Dounin <mdounin@mdounin.ru>
date Sun, 29 Jun 2008 04:24:19 +0400
parents 6b995d5251ec
children 3e8648918913
comparison
equal deleted inserted replaced
1:6b995d5251ec 2:13a2fbcc8bc4
81 81
82 static ngx_int_t 82 static ngx_int_t
83 ngx_http_bytes_header_filter(ngx_http_request_t *r) 83 ngx_http_bytes_header_filter(ngx_http_request_t *r)
84 { 84 {
85 u_char *p, *last; 85 u_char *p, *last;
86 off_t start, end; 86 off_t start, end, len;
87 ngx_uint_t suffix, bad; 87 ngx_uint_t suffix, bad;
88 ngx_http_bytes_t *range; 88 ngx_http_bytes_t *range;
89 ngx_http_bytes_conf_t *conf; 89 ngx_http_bytes_conf_t *conf;
90 ngx_http_bytes_ctx_t *ctx; 90 ngx_http_bytes_ctx_t *ctx;
91 enum { 91 enum {
132 * bytes= contain ranges compatible with RFC 2616, "14.35.1 Byte Ranges", 132 * bytes= contain ranges compatible with RFC 2616, "14.35.1 Byte Ranges",
133 * but no whitespaces permitted 133 * but no whitespaces permitted
134 */ 134 */
135 135
136 bad = 0; 136 bad = 0;
137 len = 0;
137 138
138 while (p < last) { 139 while (p < last) {
139 140
140 switch (state) { 141 switch (state) {
141 142
211 212
212 /* note: range->end isn't inclusive, while last-byte-pos is */ 213 /* note: range->end isn't inclusive, while last-byte-pos is */
213 214
214 range->start = start; 215 range->start = start;
215 range->end = end + 1; 216 range->end = end + 1;
217 len += range->end - range->start;
216 218
217 if (*p == ',') { 219 if (*p == ',') {
218 p++; 220 p++;
219 state = sw_first_byte_pos; 221 state = sw_first_byte_pos;
220 break; 222 break;
249 end = r->headers_out.content_length_n - 1; 251 end = r->headers_out.content_length_n - 1;
250 } 252 }
251 253
252 range->start = start; 254 range->start = start;
253 range->end = end + 1; 255 range->end = end + 1;
256 len += range->end - range->start;
254 257
255 break; 258 break;
256 259
257 default: 260 default:
258 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 261 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
260 return ngx_http_next_header_filter(r); 263 return ngx_http_next_header_filter(r);
261 264
262 } 265 }
263 266
264 done: 267 done:
265 /* ... fix content-length */ 268 r->headers_out.content_length_n = len;
266 269
267 ngx_http_set_ctx(r, ctx, ngx_http_bytes_filter_module); 270 ngx_http_set_ctx(r, ctx, ngx_http_bytes_filter_module);
271
272 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
273 "bytes header filter: new length %O",
274 r->headers_out.content_length_n);
268 275
269 return ngx_http_next_header_filter(r); 276 return ngx_http_next_header_filter(r);
270 } 277 }
271 278
272 279