# HG changeset patch # User Maxim Dounin # Date 1233593652 -10800 # Node ID 314242bda1c130260b4f14f4064de42f08ed67a1 # Parent d1f754919b5d7e22ee633b31514416050b239f35 Correctly handle last ignored buffer again. If we ignore buffer marked as last_buf, make sure we pass out empty buffer marked as last_buf. The same problem was already fixed in rev. 48cdd1bfa48e, but only for optimized special case (last range and last buffer). diff --git a/ngx_http_bytes_filter_module.c b/ngx_http_bytes_filter_module.c --- a/ngx_http_bytes_filter_module.c +++ b/ngx_http_bytes_filter_module.c @@ -399,9 +399,10 @@ ngx_http_bytes_body_filter(ngx_http_requ buf = cl->buf; size = ngx_buf_size(buf); - ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "bytes body filter: b %O, offset %O, range %O-%O", - size, ctx->offset, range->start, range->end); + ngx_log_debug5(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "bytes body filter: b %O, l %d, offset %O, range %O-%O", + size, buf->last_buf, ctx->offset, + range->start, range->end); if (ngx_buf_special(buf)) { ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, @@ -425,7 +426,35 @@ ngx_http_bytes_body_filter(ngx_http_requ if (range->start > ctx->offset + size || range->end < ctx->offset) { ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "bytes body filter: fully ignored buffer"); + buf->pos = buf->last; + + if (!buf->last_buf) { + continue; + } + + /* for last buffer, make sure we pass out empty one */ + + ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "bytes body filter: last buffer ignored"); + + dcl = ngx_alloc_chain_link(r->pool); + if (dcl == NULL) { + return NGX_ERROR; + } + + b = ngx_calloc_buf(r->pool); + if (b == NULL) { + return NGX_ERROR; + } + + b->last_buf = 1; + + *ll = dcl; + dcl->buf = b; + dcl->next = NULL; + ll = &dcl->next; + continue; } diff --git a/t/bytes.t b/t/bytes.t --- a/t/bytes.t +++ b/t/bytes.t @@ -17,7 +17,7 @@ use Test::Nginx; select STDERR; $| = 1; select STDOUT; $| = 1; -my $t = Test::Nginx->new()->plan(24); +my $t = Test::Nginx->new()->plan(25); $t->write_file_expand('nginx.conf', <<'EOF'); @@ -76,6 +76,10 @@ like($t1, qr/200/, 'final bytes'); like($t1, qr/Content-Length: 10/, 'final bytes length'); like($t1, qr/^X099XXXXXX$/m, 'final bytes content'); +# standard error pages contain multiple buffers in one chain + +like(http_get('/notfound?bytes=0-9'), qr/404/, 'not found'); + # various range requests $t1 = http_get_range('/t1?bytes=100-', 'Range: bytes=0-9');