nginx-0.0.1-2003-10-09-11:00:45 import
diff --git a/src/http/modules/ngx_http_not_modified_filter.c b/src/http/modules/ngx_http_not_modified_filter.c
index ab22fa6..f1ccd44 100644
--- a/src/http/modules/ngx_http_not_modified_filter.c
+++ b/src/http/modules/ngx_http_not_modified_filter.c
@@ -39,7 +39,7 @@
 
     if (r->headers_out.status != NGX_HTTP_OK
         || r->headers_in.if_modified_since == NULL
-        || r->headers_out.last_modified_time == NULL)
+        || r->headers_out.last_modified_time == -1)
     {
         return next_header_filter(r);
     }
@@ -50,7 +50,7 @@
     ngx_log_debug(r->connection->log, "%d %d" _
                   ims _ r->headers_out.last_modified_time);
 
-    /* I think that the date equality is correcter */
+    /* I think that the equality of the dates is correcter */
 
     if (ims != NGX_ERROR && ims == r->headers_out.last_modified_time) {
         r->headers_out.status = NGX_HTTP_NOT_MODIFIED;
diff --git a/src/http/modules/ngx_http_static_handler.c b/src/http/modules/ngx_http_static_handler.c
index 8ea6a0a..784f3de 100644
--- a/src/http/modules/ngx_http_static_handler.c
+++ b/src/http/modules/ngx_http_static_handler.c
@@ -118,6 +118,7 @@
     }
 
     /* we need to allocate all before the header would be sent */
+
     ngx_test_null(h, ngx_pcalloc(r->pool, sizeof(ngx_hunk_t)),
                   NGX_HTTP_INTERNAL_SERVER_ERROR);
 
@@ -132,18 +133,28 @@
     }
 
     if (r->header_only) {
+        ngx_http_finalize_request(r, rc);
+
+#if 0
         if (rc == NGX_AGAIN) {
             ngx_http_set_write_handler(r);
 
         } else {
             ngx_http_finalize_request(r, 0);
         }
+#endif
 
         return NGX_OK;
     }
 
 
-    h->type = NGX_HUNK_FILE|NGX_HUNK_LAST;
+#if 0
+    h->type = r->main ? NGX_HUNK_FILE : NGX_HUNK_FILE|NGX_HUNK_LAST;
+#else
+    h->type = NGX_HUNK_FILE;
+#endif
+
+
     h->file_pos = 0;
     h->file_last = ngx_file_size(r->file.info);
 
@@ -152,6 +163,9 @@
 
     rc = ngx_http_output_filter(r, h);
 
+    ngx_http_finalize_request(r, rc);
+
+#if 0
     if (r->main == NULL) {
         if (rc == NGX_AGAIN) {
             ngx_http_set_write_handler(r);
@@ -160,6 +174,7 @@
             ngx_http_finalize_request(r, 0);
         }
     }
+#endif
 
     return NGX_OK;
 }
diff --git a/src/http/ngx_http.h b/src/http/ngx_http.h
index 4cdd4c6..3cdd120 100644
--- a/src/http/ngx_http.h
+++ b/src/http/ngx_http.h
@@ -54,6 +54,7 @@
 void ngx_http_set_write_handler(ngx_http_request_t *r);
 
 
+int ngx_http_send_last(ngx_http_request_t *r);
 void ngx_http_close_request(ngx_http_request_t *r, int error);
 void ngx_http_close_connection(ngx_connection_t *c);
 
diff --git a/src/http/ngx_http_output_filter.c b/src/http/ngx_http_output_filter.c
index 0612076..6de9202 100644
--- a/src/http/ngx_http_output_filter.c
+++ b/src/http/ngx_http_output_filter.c
@@ -72,10 +72,11 @@
 #define ngx_next_filter  (*ngx_http_top_body_filter)
 
 #define need_to_copy(r, hunk)                                             \
-            (((r->filter & NGX_HTTP_FILTER_NEED_IN_MEMORY)                \
-               && (hunk->type & NGX_HUNK_IN_MEMORY) == 0)                 \
-             || ((r->filter & NGX_HTTP_FILTER_NEED_TEMP)                  \
-                  && (hunk->type & (NGX_HUNK_MEMORY|NGX_HUNK_MMAP))))
+            (!ngx_hunk_special(hunk)                                      \
+             && (((r->filter & NGX_HTTP_FILTER_NEED_IN_MEMORY)            \
+                   && (hunk->type & NGX_HUNK_IN_MEMORY) == 0)             \
+                 || ((r->filter & NGX_HTTP_FILTER_NEED_TEMP)              \
+                  && (hunk->type & (NGX_HUNK_MEMORY|NGX_HUNK_MMAP)))))
 
 
 
@@ -201,6 +202,8 @@
             *ctx->last_out = ce;
             ctx->last_out = &ce->next;
             ctx->hunk = NULL;
+
+            break;
         }
 
         if (ctx->out == NULL && last != NGX_NONE) {
diff --git a/src/http/ngx_http_event.c b/src/http/ngx_http_request.c
similarity index 98%
rename from src/http/ngx_http_event.c
rename to src/http/ngx_http_request.c
index ea81207..0f66b0d 100644
--- a/src/http/ngx_http_event.c
+++ b/src/http/ngx_http_request.c
@@ -785,6 +785,10 @@
     int           rc;
     ngx_event_t  *rev, *wev;
 
+    if (r->main) {
+        return;
+    }
+
     rc = error;
 
     if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
@@ -813,9 +817,25 @@
             return;
         }
 
+#if 1
+        return;
+#endif
+
     } else if (rc == NGX_ERROR) {
         r->keepalive = 0;
         r->lingering_close = 0;
+
+    } else {
+        if (ngx_http_send_last(r) == NGX_ERROR) {
+            ngx_http_close_request(r, 0);
+            ngx_http_close_connection(r->connection);
+            return;
+        }
+
+        if (rc == NGX_AGAIN) {
+            ngx_http_set_write_handler(r);
+            return;
+        }
     }
 
     rev = r->connection->read;
@@ -840,6 +860,8 @@
         ngx_http_close_request(r, 0);
         ngx_http_close_connection(r->connection);
     }
+
+    return;
 }
 
 
@@ -887,6 +909,8 @@
         ngx_http_close_request(r, 0);
         ngx_http_close_connection(r->connection);
     }
+
+    return;
 }
 
 
@@ -951,6 +975,8 @@
         ngx_http_close_request(r, 0);
         ngx_http_close_connection(r->connection);
     }
+
+    return;
 }
 
 
@@ -1046,6 +1072,8 @@
         ngx_http_close_request(r, rc);
         ngx_http_close_connection(c);
     }
+
+    return;
 }
 
 
@@ -1385,6 +1413,17 @@
 }
 
 
+int ngx_http_send_last(ngx_http_request_t *r)
+{
+    ngx_hunk_t  *h;
+
+    ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR);
+    h->type = NGX_HUNK_LAST;
+
+    return ngx_http_output_filter(r, h);
+}
+
+
 void ngx_http_close_request(ngx_http_request_t *r, int error)
 {
     ngx_http_log_ctx_t  *ctx;
diff --git a/src/http/ngx_http_special_response.c b/src/http/ngx_http_special_response.c
index 9e3bb9a..7362116 100644
--- a/src/http/ngx_http_special_response.c
+++ b/src/http/ngx_http_special_response.c
@@ -199,15 +199,19 @@
     }
 
     rc = ngx_http_send_header(r);
+
     if (rc == NGX_ERROR) {
         return NGX_ERROR;
     }
 
     if (r->header_only) {
+        ngx_http_finalize_request(r, rc);
+#if 0
         if (rc == NGX_AGAIN) {
             ngx_http_set_write_handler(r);
             return NGX_AGAIN;
         }
+#endif
 
         return NGX_OK;
     }
@@ -248,12 +252,16 @@
 
     rc = ngx_http_output_filter(r, h);
 
+    ngx_http_finalize_request(r, rc);
+
+#if 0
     if (r->main == NULL) {
         if (rc == NGX_AGAIN) {
             ngx_http_set_write_handler(r);
             return NGX_AGAIN;
         }
     }
+#endif
 
     return NGX_OK;
 
diff --git a/src/http/ngx_http_write_filter.c b/src/http/ngx_http_write_filter.c
index 26c632c..3f43875 100644
--- a/src/http/ngx_http_write_filter.c
+++ b/src/http/ngx_http_write_filter.c
@@ -130,14 +130,16 @@
                   last _ flush _ size);
 #endif
 
-    /* avoid the output if there is no last hunk, no flush point and
-       size of the hunks is smaller then "buffer_output" */
+    /*
+     * avoid the output if there is no last hunk, no flush point and
+     * size of the hunks is smaller then "buffer_output"
+     */
 
     if (!last && flush == 0 && size < conf->buffer_output) {
         return NGX_OK;
     }
 
-    if (r->connection->write->delayed) {
+    if (!r->connection->write->ready || r->connection->write->delayed) {
         return NGX_AGAIN;
     }