changeset 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
files ngx_http_bytes_filter_module.c
diffstat 1 files changed, 35 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/ngx_http_bytes_filter_module.c
+++ b/ngx_http_bytes_filter_module.c
@@ -253,6 +253,12 @@ ngx_http_bytes_header_filter(ngx_http_re
             end = r->headers_out.content_length_n - 1;
         }
 
+        if (start > end) {
+            ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+                           "bytes header filter: invalid range specification");
+            return ngx_http_next_header_filter(r);
+        }
+
         range->start = start;
         range->end = end + 1;
         len += range->end - range->start;
@@ -261,7 +267,7 @@ ngx_http_bytes_header_filter(ngx_http_re
 
     default:
         ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
-                      "bytes header filter: invalid range specification");
+                       "bytes header filter: invalid range specification");
         return ngx_http_next_header_filter(r);
 
     }
@@ -336,6 +342,34 @@ ngx_http_bytes_body_filter(ngx_http_requ
 
         size = ngx_buf_size(buf);
 
+        if (range->start > ctx->offset + size || range->end < ctx->offset) {
+
+            ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+                           "bytes body filter: last buffer ignored");
+
+            buf->pos = buf->last;
+
+            cl = ngx_alloc_chain_link(r->pool);
+            if (cl == NULL) {
+                return NGX_ERROR;
+            }
+
+            b = ngx_calloc_buf(r->pool);
+            if (b == NULL) {
+                return NGX_ERROR;
+            }
+
+            b->last_buf = 1;
+
+            cl->buf = b;
+            cl->next = NULL;
+      
+            return ngx_http_next_body_filter(r, cl);
+        }
+
+        ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+                       "bytes body filter: last buffer, %d", size);
+
         if (buf->in_file) {
             if (range->start > ctx->offset) {
                 buf->file_pos += range->start - ctx->offset;