nginx-0.0.3-2004-05-18-19:29:08 import
diff --git a/src/http/modules/ngx_http_chunked_filter.c b/src/http/modules/ngx_http_chunked_filter.c
index 61eae5d..3cd6ddd 100644
--- a/src/http/modules/ngx_http_chunked_filter.c
+++ b/src/http/modules/ngx_http_chunked_filter.c
@@ -66,12 +66,16 @@
     }
 
     ngx_test_null(out, ngx_alloc_chain_link(r->pool), NGX_ERROR);
+    out->hunk = NULL;
     ll = &out->next;
 
     size = 0;
     cl = in;
 
     for ( ;; ) {
+        ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+                       "http chunk: %d", ngx_hunk_size(cl->hunk));
+
         size += ngx_hunk_size(cl->hunk);
 
         ngx_test_null(tl, ngx_alloc_chain_link(r->pool), NGX_ERROR);
@@ -86,25 +90,41 @@
         cl = cl->next;
     }
 
-    ngx_test_null(chunk, ngx_palloc(r->pool, 11), NGX_ERROR);
-    len = ngx_snprintf((char *) chunk, 11, SIZE_T_X_FMT CRLF, size);
+    if (size) {
+        ngx_test_null(chunk, ngx_palloc(r->pool, 11), NGX_ERROR);
+        len = ngx_snprintf((char *) chunk, 11, SIZE_T_X_FMT CRLF, size);
 
-    ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR);
-    h->type = NGX_HUNK_IN_MEMORY|NGX_HUNK_TEMP;
-    h->pos = chunk;
-    h->last = chunk + len;
+        ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR);
+        h->type = NGX_HUNK_IN_MEMORY|NGX_HUNK_TEMP;
+        h->pos = chunk;
+        h->last = chunk + len;
 
-    out->hunk = h;
-
-    ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR);
+        out->hunk = h;
+    }
 
     if (cl->hunk->type & NGX_HUNK_LAST) {
-        cl->hunk->type &= ~NGX_HUNK_LAST;
+
+        ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR);
         h->type = NGX_HUNK_IN_MEMORY|NGX_HUNK_MEMORY|NGX_HUNK_LAST;
         h->pos = (u_char *) CRLF "0" CRLF CRLF;
         h->last = h->pos + 7;
 
+        cl->hunk->type &= ~NGX_HUNK_LAST;
+
+        if (size == 0) {
+            out->hunk = h;
+            out->next = NULL;
+
+            return ngx_http_next_body_filter(r, out);
+        }
+
     } else {
+        if (size == 0) {
+            *ll = NULL;
+            return ngx_http_next_body_filter(r, out->next);
+        }
+
+        ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR);
         h->type = NGX_HUNK_IN_MEMORY|NGX_HUNK_MEMORY;
         h->pos = (u_char *) CRLF;
         h->last = h->pos + 2;
diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.c b/src/http/modules/proxy/ngx_http_proxy_handler.c
index 8aa3397..d523fc1 100644
--- a/src/http/modules/proxy/ngx_http_proxy_handler.c
+++ b/src/http/modules/proxy/ngx_http_proxy_handler.c
@@ -278,6 +278,7 @@
                              offsetof(ngx_http_proxy_headers_in_t, location) },
     { ngx_string("Accept-Ranges"),
                         offsetof(ngx_http_proxy_headers_in_t, accept_ranges) },
+    { ngx_string("X-Pad"), offsetof(ngx_http_proxy_headers_in_t, x_pad) },
 
     { ngx_null_string, 0 }
 };
diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.h b/src/http/modules/proxy/ngx_http_proxy_handler.h
index 55eee74..e0f85ee 100644
--- a/src/http/modules/proxy/ngx_http_proxy_handler.h
+++ b/src/http/modules/proxy/ngx_http_proxy_handler.h
@@ -123,6 +123,7 @@
     ngx_table_elt_t                 *last_modified;
     ngx_table_elt_t                 *location;
     ngx_table_elt_t                 *accept_ranges;
+    ngx_table_elt_t                 *x_pad;
 
     off_t                            content_length_n;
 } ngx_http_proxy_headers_in_t;
diff --git a/src/http/modules/proxy/ngx_http_proxy_header.c b/src/http/modules/proxy/ngx_http_proxy_header.c
index cb13034..a3e05e5 100644
--- a/src/http/modules/proxy/ngx_http_proxy_header.c
+++ b/src/http/modules/proxy/ngx_http_proxy_header.c
@@ -26,6 +26,10 @@
             continue;
         }
 
+        if (&h[i] == headers_in->x_pad) {
+            continue;
+        }
+
         if (p->accel) {
             if (&h[i] == headers_in->date
                 || &h[i] == headers_in->accept_ranges) {