Mercurial > hg > nginx
comparison src/http/modules/ngx_http_range_filter_module.c @ 4057:3205a6d6c6ec
Ranges processing small optimization.
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 30 Aug 2011 13:06:12 +0000 |
parents | e9213133993a |
children | d32a2000b766 |
comparison
equal
deleted
inserted
replaced
4056:e9213133993a | 4057:3205a6d6c6ec |
---|---|
232 | 232 |
233 ngx_int_t | 233 ngx_int_t |
234 ngx_http_range_parse(ngx_http_request_t *r, ngx_http_range_filter_ctx_t *ctx) | 234 ngx_http_range_parse(ngx_http_request_t *r, ngx_http_range_filter_ctx_t *ctx) |
235 { | 235 { |
236 u_char *p; | 236 u_char *p; |
237 off_t start, end, size; | 237 off_t start, end, size, content_length; |
238 ngx_uint_t suffix; | 238 ngx_uint_t suffix; |
239 ngx_http_range_t *range; | 239 ngx_http_range_t *range; |
240 | 240 |
241 p = r->headers_in.range->value.data + 6; | 241 p = r->headers_in.range->value.data + 6; |
242 size = 0; | 242 size = 0; |
243 content_length = r->headers_out.content_length_n; | |
243 | 244 |
244 for ( ;; ) { | 245 for ( ;; ) { |
245 start = 0; | 246 start = 0; |
246 end = 0; | 247 end = 0; |
247 suffix = 0; | 248 suffix = 0; |
261 | 262 |
262 if (*p++ != '-') { | 263 if (*p++ != '-') { |
263 return NGX_HTTP_RANGE_NOT_SATISFIABLE; | 264 return NGX_HTTP_RANGE_NOT_SATISFIABLE; |
264 } | 265 } |
265 | 266 |
266 if (start >= r->headers_out.content_length_n) { | 267 if (start >= content_length) { |
267 goto skip; | 268 goto skip; |
268 } | 269 } |
269 | 270 |
270 while (*p == ' ') { p++; } | 271 while (*p == ' ') { p++; } |
271 | 272 |
272 if (*p == ',' || *p == '\0') { | 273 if (*p == ',' || *p == '\0') { |
273 end = r->headers_out.content_length_n; | 274 end = content_length; |
274 goto found; | 275 goto found; |
275 } | 276 } |
276 | 277 |
277 } else { | 278 } else { |
278 suffix = 1; | 279 suffix = 1; |
292 if (*p != ',' && *p != '\0') { | 293 if (*p != ',' && *p != '\0') { |
293 return NGX_HTTP_RANGE_NOT_SATISFIABLE; | 294 return NGX_HTTP_RANGE_NOT_SATISFIABLE; |
294 } | 295 } |
295 | 296 |
296 if (suffix) { | 297 if (suffix) { |
297 start = r->headers_out.content_length_n - end; | 298 start = content_length - end; |
298 end = r->headers_out.content_length_n - 1; | 299 end = content_length - 1; |
299 } | 300 } |
300 | 301 |
301 if (start > end) { | 302 if (start > end) { |
302 goto skip; | 303 goto skip; |
303 } | 304 } |
304 | 305 |
305 if (end >= r->headers_out.content_length_n) { | 306 if (end >= content_length) { |
306 end = r->headers_out.content_length_n; | 307 end = content_length; |
307 | 308 |
308 } else { | 309 } else { |
309 end++; | 310 end++; |
310 } | 311 } |
311 | 312 |
330 | 331 |
331 if (ctx->ranges.nelts == 0) { | 332 if (ctx->ranges.nelts == 0) { |
332 return NGX_HTTP_RANGE_NOT_SATISFIABLE; | 333 return NGX_HTTP_RANGE_NOT_SATISFIABLE; |
333 } | 334 } |
334 | 335 |
335 if (size > r->headers_out.content_length_n) { | 336 if (size > content_length) { |
336 return NGX_DECLINED; | 337 return NGX_DECLINED; |
337 } | 338 } |
338 | 339 |
339 return NGX_OK; | 340 return NGX_OK; |
340 } | 341 } |