nginx-0.0.1-2003-11-11-00:09:22 import
diff --git a/src/http/modules/proxy/ngx_http_proxy_cache.c b/src/http/modules/proxy/ngx_http_proxy_cache.c
index 3c4f5ca..a8c9d77 100644
--- a/src/http/modules/proxy/ngx_http_proxy_cache.c
+++ b/src/http/modules/proxy/ngx_http_proxy_cache.c
@@ -288,6 +288,8 @@
         return;
     }
 
+    ngx_http_busy_unlock(p->lcf->busy_lock, &p->busy_lock);
+
     if (rc == NGX_DONE) {
         ft_type = NGX_HTTP_PROXY_FT_BUSY_LOCK;
 
diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.c b/src/http/modules/proxy/ngx_http_proxy_handler.c
index ad719ca..ecfe658 100644
--- a/src/http/modules/proxy/ngx_http_proxy_handler.c
+++ b/src/http/modules/proxy/ngx_http_proxy_handler.c
@@ -503,7 +503,7 @@
 {
     ngx_http_proxy_ctx_t  *p;
 
-    p = ngx_http_get_module_ctx(r, ngx_http_proxy_module);
+    p = ngx_http_get_module_err_ctx(r, ngx_http_proxy_module);
 
     if (p == NULL) {
         *buf = '-';
@@ -520,11 +520,15 @@
 
     *buf++ = '/';
 
-    *buf++ = 'X';
+    *buf++ = '_';
 
     *buf++ = '/';
 
-    *buf++ = 'X';
+    *buf++ = '_';
+
+    *buf++ = '/';
+
+    *buf++ = '_';
 
     *buf++ = ' ';
 
@@ -554,6 +558,9 @@
         buf += ngx_snprintf(buf, NGX_TIME_LEN, TIME_FMT, p->state->expires);
     }
 
+    *buf++ = ' ';
+    *buf++ = '_';
+
     return buf;
 }
 
@@ -563,7 +570,7 @@
 {
     ngx_http_proxy_ctx_t  *p;
 
-    p = ngx_http_get_module_ctx(r, ngx_http_proxy_module);
+    p = ngx_http_get_module_err_ctx(r, ngx_http_proxy_module);
 
     if (p == NULL || p->state->cache_state == 0) {
         *buf = '-';
@@ -580,7 +587,7 @@
 {
     ngx_http_proxy_ctx_t  *p;
 
-    p = ngx_http_get_module_ctx(r, ngx_http_proxy_module);
+    p = ngx_http_get_module_err_ctx(r, ngx_http_proxy_module);
 
     if (p == NULL || p->state->reason == 0) {
         *buf = '-';
diff --git a/src/http/modules/proxy/ngx_http_proxy_upstream.c b/src/http/modules/proxy/ngx_http_proxy_upstream.c
index d404993..0a5ecd2 100644
--- a/src/http/modules/proxy/ngx_http_proxy_upstream.c
+++ b/src/http/modules/proxy/ngx_http_proxy_upstream.c
@@ -337,6 +337,8 @@
         return;
     }
 
+    ngx_http_busy_unlock(p->lcf->busy_lock, &p->busy_lock);
+
     if (rc == NGX_DONE) {
         ft_type = NGX_HTTP_PROXY_FT_BUSY_LOCK;
 
@@ -1053,27 +1055,24 @@
     if (p->upstream->peer.connection) {
         if (ep->upstream_done && p->cachable) {
             if (ngx_http_proxy_update_cache(p) == NGX_ERROR) {
-                ngx_http_busy_unlock_cachable(p->lcf->busy_lock, &p->busy_lock);
+                ngx_http_busy_unlock(p->lcf->busy_lock, &p->busy_lock);
                 ngx_http_proxy_finalize_request(p, 0);
                 return;
             }
 
-            ngx_http_busy_unlock_cachable(p->lcf->busy_lock, &p->busy_lock);
-
         } else if (ep->upstream_eof && p->cachable) {
 
             /* TODO: check length & update cache */
 
             if (ngx_http_proxy_update_cache(p) == NGX_ERROR) {
-                ngx_http_busy_unlock_cachable(p->lcf->busy_lock, &p->busy_lock);
+                ngx_http_busy_unlock(p->lcf->busy_lock, &p->busy_lock);
                 ngx_http_proxy_finalize_request(p, 0);
                 return;
             }
-
-            ngx_http_busy_unlock_cachable(p->lcf->busy_lock, &p->busy_lock);
         }
 
         if (ep->upstream_done || ep->upstream_eof || ep->upstream_error) {
+            ngx_http_busy_unlock(p->lcf->busy_lock, &p->busy_lock);
             ngx_http_proxy_close_connection(p);
         }
     }
@@ -1104,6 +1103,8 @@
 
 ngx_log_debug(p->request->connection->log, "next upstream: %d" _ ft_type);
 
+    ngx_http_busy_unlock(p->lcf->busy_lock, &p->busy_lock);
+
     if (ft_type != NGX_HTTP_PROXY_FT_HTTP_404) {
         ngx_event_connect_peer_failed(&p->upstream->peer);
     }
diff --git a/src/http/ngx_http.h b/src/http/ngx_http.h
index 26dde7f..aef53e8 100644
--- a/src/http/ngx_http.h
+++ b/src/http/ngx_http.h
@@ -21,6 +21,8 @@
 
 
 #define ngx_http_get_module_ctx(r, module)       r->ctx[module.ctx_index]
+#define ngx_http_get_module_err_ctx(r, module)                                \
+         (r->err_ctx ? r->err_ctx[module.ctx_index] : r->ctx[module.ctx_index])
 
 #define ngx_http_create_ctx(r, cx, module, size, error)                       \
             do {                                                              \
diff --git a/src/http/ngx_http_busy_lock.c b/src/http/ngx_http_busy_lock.c
index 2ed66dc..085cd56 100644
--- a/src/http/ngx_http_busy_lock.c
+++ b/src/http/ngx_http_busy_lock.c
@@ -100,11 +100,14 @@
 }
 
 
-void ngx_http_busy_unlock_cachable(ngx_http_busy_lock_t *bl,
-                                   ngx_http_busy_lock_ctx_t *bc)
+void ngx_http_busy_unlock(ngx_http_busy_lock_t *bl,
+                          ngx_http_busy_lock_ctx_t *bc)
 {
-    bl->md5_mask[bc->slot / 8] &= ~(1 << (bc->slot & 7));
-    bl->cachable--;
+    if (bl->md5) {
+        bl->md5_mask[bc->slot / 8] &= ~(1 << (bc->slot & 7));
+        bl->cachable--;
+    }
+
     bl->busy--;
 }
 
diff --git a/src/http/ngx_http_busy_lock.h b/src/http/ngx_http_busy_lock.h
index d36b9b7..e600b01 100644
--- a/src/http/ngx_http_busy_lock.h
+++ b/src/http/ngx_http_busy_lock.h
@@ -38,8 +38,8 @@
 int ngx_http_busy_lock(ngx_http_busy_lock_t *bl, ngx_http_busy_lock_ctx_t *bc);
 int ngx_http_busy_lock_cachable(ngx_http_busy_lock_t *bl,
                                 ngx_http_busy_lock_ctx_t *bc, int lock);
-void ngx_http_busy_unlock_cachable(ngx_http_busy_lock_t *bl,
-                                   ngx_http_busy_lock_ctx_t *bc);
+void ngx_http_busy_unlock(ngx_http_busy_lock_t *bl,
+                          ngx_http_busy_lock_ctx_t *bc);
 
 char *ngx_http_set_busy_lock_slot(ngx_conf_t *cf, ngx_command_t *cmd,
                                   void *conf);
diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
index a5f5c38..3a0ec8b 100644
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -429,6 +429,11 @@
         return NGX_OK;
     }
 
+    if (r->err_status) {
+        r->headers_out.status = r->err_status;
+        r->headers_out.status_line.len = 0;
+    }
+
     return (*ngx_http_top_header_filter)(r);
 }
 
@@ -495,7 +500,18 @@
     }
 
     /* clear the modules contexts */
-    ngx_memzero(r->ctx, sizeof(void *) * ngx_http_max_module);
+
+    if (r->error_page) {
+        r->err_status = r->headers_out.status;
+        r->err_ctx = r->ctx;
+        r->ctx = ngx_pcalloc(r->pool, sizeof(void *) * ngx_http_max_module);
+        if (r->ctx == NULL) {
+            return NGX_HTTP_INTERNAL_SERVER_ERROR;
+        }
+
+    } else {
+        ngx_memzero(r->ctx, sizeof(void *) * ngx_http_max_module);
+    }
 
     r->phase = 0;
     r->phase_handler = 0;
diff --git a/src/http/ngx_http_header_filter.c b/src/http/ngx_http_header_filter.c
index 64cf4bb..f67c568 100644
--- a/src/http/ngx_http_header_filter.c
+++ b/src/http/ngx_http_header_filter.c
@@ -116,6 +116,7 @@
 #endif
 
     } else {
+
         if (r->headers_out.status < NGX_HTTP_MOVED_PERMANENTLY) {
             /* 2XX */
             status = r->headers_out.status - NGX_HTTP_OK;
@@ -240,7 +241,8 @@
 #if (NGX_HTTP_LOG_ALL_HEADERS_OUT)
         p = h->last;
 #endif
-        h->last += ngx_http_get_time(h->last, ngx_time());
+        h->last = ngx_cpymem(h->last, ngx_cached_http_time.data,
+                             ngx_cached_http_time.len);
 
 #if (NGX_HTTP_LOG_ALL_HEADERS_OUT)
         r->headers_out.date = ngx_palloc(r->pool, sizeof(ngx_table_elt_t));
diff --git a/src/http/ngx_http_log_handler.c b/src/http/ngx_http_log_handler.c
index 7a2bf9e..9d4f65e 100644
--- a/src/http/ngx_http_log_handler.c
+++ b/src/http/ngx_http_log_handler.c
@@ -210,6 +210,10 @@
 
 static char *ngx_http_log_time(ngx_http_request_t *r, char *buf, uintptr_t data)
 {
+    return ngx_cpymem(buf, ngx_cached_http_log_time.data,
+                      ngx_cached_http_log_time.len);
+
+#if 0
     ngx_tm_t  tm;
 
     ngx_localtime(&tm);
@@ -219,6 +223,7 @@
                               tm.ngx_tm_mday, months[tm.ngx_tm_mon - 1],
                               tm.ngx_tm_year,
                               tm.ngx_tm_hour, tm.ngx_tm_min, tm.ngx_tm_sec);
+#endif
 }
 
 
@@ -237,7 +242,8 @@
 static char *ngx_http_log_status(ngx_http_request_t *r, char *buf,
                                  uintptr_t data)
 {
-    return buf + ngx_snprintf(buf, 4, "%d", r->headers_out.status);
+    return buf + ngx_snprintf(buf, 4, "%d",
+                        r->err_status ? r->err_status : r->headers_out.status);
 }
 
 
diff --git a/src/http/ngx_http_log_handler.h b/src/http/ngx_http_log_handler.h
index 40e70df..3d8481c 100644
--- a/src/http/ngx_http_log_handler.h
+++ b/src/http/ngx_http_log_handler.h
@@ -16,9 +16,9 @@
 #define NGX_HTTP_LOG_ARG         (u_int) -1
 
 /* STUB */
-#define NGX_INT32_LEN      sizeof("4294967296") - 1
-#define NGX_TIME_LEN       sizeof("4294967296") - 1
-#define NGX_OFF_LEN        sizeof("18446744073709551616") - 1
+#define NGX_INT32_LEN      sizeof("-2147483648") - 1
+#define NGX_TIME_LEN       sizeof("-2147483648") - 1
+#define NGX_OFF_LEN        sizeof("-9223372036854775808") - 1
 
 
 typedef struct {
diff --git a/src/http/ngx_http_request.h b/src/http/ngx_http_request.h
index 526e13d..a87c6dc 100644
--- a/src/http/ngx_http_request.h
+++ b/src/http/ngx_http_request.h
@@ -192,6 +192,8 @@
     void                *data;
 
     char                *discarded_buffer;
+    void               **err_ctx;
+    int                  err_status;
 
     /* URI is not started with '/' - "GET http://" */
     unsigned             unusual_uri:1;