nginx-0.0.1-2003-10-21-11:47:21 import
diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.c b/src/http/modules/proxy/ngx_http_proxy_handler.c
index 87d472c..16a9ed4 100644
--- a/src/http/modules/proxy/ngx_http_proxy_handler.c
+++ b/src/http/modules/proxy/ngx_http_proxy_handler.c
@@ -742,6 +742,12 @@
 
     ep->preread_size = p->header_in->last - p->header_in->pos;
 
+    /*
+     * event_proxy would do p->header_in->last += ep->preread_size
+     * as these bytes were read.
+     */
+    p->header_in->last = p->header_in->pos;
+
     /* STUB */ ep->cachable = 0;
 
     p->event_proxy = ep;
@@ -806,7 +812,7 @@
         }
 
         if (ep->upstream_done || ep->upstream_eof || ep->upstream_error) {
-            ngx_http_proxy_close_connection(c);
+            ngx_http_proxy_close_connection(p->upstream.connection);
             p->upstream.connection = NULL;
         }
     }
@@ -819,7 +825,7 @@
 
     if (ep->downstream_error) {
         if (!p->cachable && p->upstream.connection) {
-            ngx_http_proxy_close_connection(c);
+            ngx_http_proxy_close_connection(p->upstream.connection);
             p->upstream.connection = NULL;
         }
  
@@ -1052,7 +1058,9 @@
         p->upstream.connection = NULL;
     }
 
-    if (p->header_sent) {
+    if (p->header_sent
+        && (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE))
+    {
         rc = 0;
     }
 
@@ -1152,7 +1160,12 @@
     conf->bufs.num = 10;
     conf->bufs.size = 4096;
     conf->max_busy_len = 8192 + 4096;
+
+
+    /* CHECK in _init conf->max_temp_size >= conf->bufs.size !!! */
     conf->max_temp_file_size = 4096 * 6;
+
+
     conf->temp_file_write_size = 4096 * 2;
 
     ngx_test_null(conf->temp_path, ngx_pcalloc(cf->pool, sizeof(ngx_path_t)),