comparison ngx_http_bytes_filter_module.c @ 12:48cdd1bfa48e

Correctly handle last ignored buffer.
author Maxim Dounin <mdounin@mdounin.ru>
date Sat, 02 Aug 2008 15:03:13 +0400
parents 47a21c299f11
children b85e679606f4
comparison
equal deleted inserted replaced
11:47a21c299f11 12:48cdd1bfa48e
251 if (suffix) { 251 if (suffix) {
252 start = r->headers_out.content_length_n - end; 252 start = r->headers_out.content_length_n - end;
253 end = r->headers_out.content_length_n - 1; 253 end = r->headers_out.content_length_n - 1;
254 } 254 }
255 255
256 if (start > end) {
257 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
258 "bytes header filter: invalid range specification");
259 return ngx_http_next_header_filter(r);
260 }
261
256 range->start = start; 262 range->start = start;
257 range->end = end + 1; 263 range->end = end + 1;
258 len += range->end - range->start; 264 len += range->end - range->start;
259 265
260 break; 266 break;
261 267
262 default: 268 default:
263 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 269 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
264 "bytes header filter: invalid range specification"); 270 "bytes header filter: invalid range specification");
265 return ngx_http_next_header_filter(r); 271 return ngx_http_next_header_filter(r);
266 272
267 } 273 }
268 274
269 done: 275 done:
334 340
335 if (range == last - 1 && buf->last_buf) { 341 if (range == last - 1 && buf->last_buf) {
336 342
337 size = ngx_buf_size(buf); 343 size = ngx_buf_size(buf);
338 344
345 if (range->start > ctx->offset + size || range->end < ctx->offset) {
346
347 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
348 "bytes body filter: last buffer ignored");
349
350 buf->pos = buf->last;
351
352 cl = ngx_alloc_chain_link(r->pool);
353 if (cl == NULL) {
354 return NGX_ERROR;
355 }
356
357 b = ngx_calloc_buf(r->pool);
358 if (b == NULL) {
359 return NGX_ERROR;
360 }
361
362 b->last_buf = 1;
363
364 cl->buf = b;
365 cl->next = NULL;
366
367 return ngx_http_next_body_filter(r, cl);
368 }
369
370 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
371 "bytes body filter: last buffer, %d", size);
372
339 if (buf->in_file) { 373 if (buf->in_file) {
340 if (range->start > ctx->offset) { 374 if (range->start > ctx->offset) {
341 buf->file_pos += range->start - ctx->offset; 375 buf->file_pos += range->start - ctx->offset;
342 } 376 }
343 if (range->end < ctx->offset + size) { 377 if (range->end < ctx->offset + size) {