nginx-0.1.2-RELEASE import

    *) Feature: the --user=USER, --group=GROUP, and --with-ld-opt=OPTIONS
       options in configure.

    *) Feature: the server_name directive supports *.domain.tld.

    *) Bugfix: the portability improvements.

    *) Bugfix: if configuration file was set in command line, the
       reconfiguration was impossible; the bug had appeared in 0.1.1.

    *) Bugfix: proxy module may get caught in an endless loop when sendfile
       is not used.

    *) Bugfix: with sendfile the response was not recoded according to the
       charset module directives; the bug had appeared in 0.1.1.

    *) Bugfix: very seldom bug in the kqueue processing.

    *) Bugfix: the gzip module compressed the proxied responses that was
       already compressed.
diff --git a/src/core/ngx_output_chain.c b/src/core/ngx_output_chain.c
index 74e38e1..23b7846 100644
--- a/src/core/ngx_output_chain.c
+++ b/src/core/ngx_output_chain.c
@@ -24,13 +24,13 @@
     size_t        size, bsize;
     ngx_chain_t  *cl, *out, **last_out;
 
-    /*
-     * the short path for the case when the ctx->in chain is empty
-     * and the incoming chain is empty too or it has the single buf
-     * that does not require the copy
-     */
+    if (ctx->in == NULL && ctx->busy == NULL) {
 
-    if (ctx->in == NULL) {
+       /*
+        * the short path for the case when the ctx->in and ctx->busy chains
+        * are empty, the incoming chain is empty too or has the single buf
+        * that does not require the copy
+        */
 
         if (in == NULL) {
             return ctx->output_filter(ctx->filter_ctx, in);
@@ -192,6 +192,7 @@
     }
 
     if (!ctx->sendfile) {
+
         if (!ngx_buf_in_memory(buf)) {
             return 1;
         }
@@ -228,12 +229,19 @@
         src->pos += size;
         dst->last += size;
 
-        if (src->in_file && sendfile) {
-            dst->in_file = 1;
-            dst->file = src->file;
-            dst->file_pos = src->file_pos;
+        if (src->in_file) {
+
+            if (sendfile) {
+                dst->in_file = 1;
+                dst->file = src->file;
+                dst->file_pos = src->file_pos;
+                dst->file_last = src->file_pos + size;
+
+            } else {
+                dst->in_file = 0;
+            }
+
             src->file_pos += size;
-            dst->file_last = src->file_pos;
 
         } else {
             dst->in_file = 0;
@@ -271,14 +279,14 @@
             dst->in_file = 1;
             dst->file = src->file;
             dst->file_pos = src->file_pos;
-            src->file_pos += size;
-            dst->file_last = src->file_pos;
+            dst->file_last = src->file_pos + n;
 
         } else {
             dst->in_file = 0;
-            src->file_pos += n;
         }
 
+        src->file_pos += n;
+
         if (src->last_buf && src->file_pos == src->file_last) {
             dst->last_buf = 1;
         }