nginx-0.0.3-2004-03-29-21:43:58 import
diff --git a/src/http/modules/proxy/ngx_http_proxy_upstream.c b/src/http/modules/proxy/ngx_http_proxy_upstream.c
index 68c9574..6bc11a2 100644
--- a/src/http/modules/proxy/ngx_http_proxy_upstream.c
+++ b/src/http/modules/proxy/ngx_http_proxy_upstream.c
@@ -46,7 +46,9 @@
 int ngx_http_proxy_request_upstream(ngx_http_proxy_ctx_t *p)
 {
     int                         rc;
+    ngx_temp_file_t            *tf;
     ngx_http_request_t         *r;
+    ngx_http_request_body_t    *rb;
     ngx_http_proxy_upstream_t  *u;
 
     r = p->request;
@@ -63,29 +65,40 @@
 
     u->method = r->method;
 
+    if (!(rb = ngx_pcalloc(r->pool, sizeof(ngx_http_request_body_t)))) {
+        return NGX_HTTP_INTERNAL_SERVER_ERROR;
+    }
+    r->request_body = rb;
+
     if (r->headers_in.content_length_n > 0) {
-        if (!(r->temp_file = ngx_pcalloc(r->pool, sizeof(ngx_temp_file_t)))) {
+
+        if (!(tf = ngx_pcalloc(r->pool, sizeof(ngx_temp_file_t)))) {
             return NGX_HTTP_INTERNAL_SERVER_ERROR;
         }
 
-        r->temp_file->file.fd = NGX_INVALID_FILE;
-        r->temp_file->file.log = r->connection->log;
-        r->temp_file->path = p->lcf->temp_path;
-        r->temp_file->pool = r->pool;
-        r->temp_file->warn = "a client request body is buffered "
-                             "to a temporary file";
-        /* r->temp_file->persistent = 0; */
+        tf->file.fd = NGX_INVALID_FILE;
+        tf->file.log = r->connection->log;
+        tf->path = p->lcf->temp_path;
+        tf->pool = r->pool;
+        tf->warn = "a client request body is buffered to a temporary file";
+        /* tf->persistent = 0; */
 
-        r->request_body_handler = ngx_http_proxy_init_upstream;
-        r->data = p;
+        rb->buf_size = p->lcf->request_buffer_size;
+        rb->handler = ngx_http_proxy_init_upstream;
+        rb->data = p;
+        /* rb->bufs = NULL; */
+        /* rb->buf = NULL; */
+        /* rb->rest = 0; */
 
-        rc = ngx_http_read_client_request_body(r, p->lcf->request_buffer_size);
+        rb->temp_file = tf;
+
+        rc = ngx_http_read_client_request_body(r);
 
         if (rc == NGX_AGAIN) {
             return NGX_DONE;
         }
 
-        if (rc >= NGX_HTTP_SPECIAL_RESPONSE || rc == NGX_ERROR) {
+        if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
             return rc;
         }
     }
@@ -118,7 +131,7 @@
           + 2;                          /* 2 is for "\r\n" at the header end */
 
 
-    if (p->lcf->preserve_host) {
+    if (p->lcf->preserve_host && r->headers_in.host) {
         len += sizeof(host_header) - 1
                + r->headers_in.host_name_len
                + 1                                           /* 1 is for ":" */
@@ -339,11 +352,11 @@
         return;
     }
 
-    if (r->request_hunks) {
-        cl->next = r->request_hunks;
+    if (r->request_body->bufs) {
+        cl->next = r->request_body->bufs;
     }
 
-    r->request_hunks = cl;
+    r->request_body->bufs = cl;
 
     if (!(ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_proxy_log_ctx_t)))) {
         ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR);
@@ -380,7 +393,11 @@
     output->filter_ctx = writer;
     writer->pool = r->pool;
 
+#if 0
+    if (p->lcf->busy_lock && p->busy_lock == NULL) {
+#else
     if (p->lcf->busy_lock && !p->busy_locked) {
+#endif
         ngx_http_proxy_upstream_busy_lock(p);
     } else {
         ngx_http_proxy_connect(p);
@@ -393,17 +410,17 @@
     ngx_chain_t             *cl;
     ngx_output_chain_ctx_t  *output;
 
-    output = p->upstream->output_chain_ctx;
-
     /* reinit the request chain */
 
-    for (cl = p->request->request_hunks; cl; cl = cl->next) {
+    for (cl = p->request->request_body->bufs; cl; cl = cl->next) {
         cl->hunk->pos = cl->hunk->start;
         cl->hunk->file_pos = 0;
     }
 
     /* reinit the ngx_output_chain() context */
 
+    output = p->upstream->output_chain_ctx;
+
     output->hunk = NULL;
     output->in = NULL;
     output->free = NULL;
@@ -434,6 +451,56 @@
 }
 
 
+#if 0
+
+void ngx_http_proxy_upstream_busy_lock(ngx_http_proxy_ctx_t *p)
+{
+    ngx_int_t  rc;
+
+    rc = ngx_event_busy_lock(p->lcf->busy_lock, p->busy_lock);
+
+    if (rc == NGX_AGAIN) {
+        return;
+    }
+
+    if (rc == NGX_OK) {
+        ngx_http_proxy_connect(p);
+        return;
+    }
+
+    if (rc == NGX_ERROR) {
+        p->state->status = NGX_HTTP_INTERNAL_SERVER_ERROR;
+        ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR);
+        return;
+    }
+
+    /* rc == NGX_BUSY */
+
+#if (NGX_HTTP_CACHE)
+
+    if (p->busy_lock->timer) {
+        ft_type = NGX_HTTP_PROXY_FT_MAX_WAITING;
+    } else {
+        ft_type = NGX_HTTP_PROXY_FT_BUSY_LOCK;
+    }
+
+    if (p->stale && (p->lcf->use_stale & ft_type)) {
+        ngx_http_proxy_finalize_request(p,
+                                        ngx_http_proxy_send_cached_response(p));
+        return;
+    }
+
+#endif
+
+    p->state->status = NGX_HTTP_SERVICE_UNAVAILABLE;
+    ngx_http_proxy_finalize_request(p, NGX_HTTP_SERVICE_UNAVAILABLE);
+}
+
+#endif
+
+
+#if 1
+
 void ngx_http_proxy_upstream_busy_lock(ngx_http_proxy_ctx_t *p)
 {
     ngx_int_t  rc;
@@ -481,6 +548,8 @@
     ngx_http_proxy_finalize_request(p, NGX_HTTP_SERVICE_UNAVAILABLE);
 }
 
+#endif
+
 
 static void ngx_http_proxy_connect(ngx_http_proxy_ctx_t *p)
 {
@@ -530,17 +599,17 @@
         ngx_http_proxy_reinit_upstream(p);
     }
 
-    if (r->request_body_hunk) {
+    if (r->request_body->buf) {
         if (!(output->free = ngx_alloc_chain_link(r->pool))) {
             ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR);
             return;
         }
 
-        output->free->hunk = r->request_body_hunk;
+        output->free->hunk = r->request_body->buf;
         output->free->next = NULL;
         output->hunks = 1;
 
-        r->request_body_hunk->pos = r->request_body_hunk->start;
+        r->request_body->buf->pos = r->request_body->buf->start;
     }
 
     p->request_sent = 0;
@@ -590,7 +659,8 @@
     p->action = "sending request to upstream";
 
     rc = ngx_output_chain(p->upstream->output_chain_ctx,
-                          p->request_sent ? NULL : p->request->request_hunks);
+                          p->request_sent ? NULL:
+                                            p->request->request_body->bufs);
 
     if (rc == NGX_ERROR) {
         ngx_http_proxy_next_upstream(p, NGX_HTTP_PROXY_FT_ERROR);
diff --git a/src/http/ngx_http.h b/src/http/ngx_http.h
index ec2778a..3e0385b 100644
--- a/src/http/ngx_http.h
+++ b/src/http/ngx_http.h
@@ -76,8 +76,7 @@
 void ngx_http_close_connection(ngx_connection_t *c);
 
 
-ngx_int_t ngx_http_read_client_request_body(ngx_http_request_t *r,
-                                            size_t request_buffer_size);
+ngx_int_t ngx_http_read_client_request_body(ngx_http_request_t *r);
 
 int ngx_http_send_header(ngx_http_request_t *r);
 int ngx_http_special_response_handler(ngx_http_request_t *r, int error);
diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
index f3f47f8..48b7ba4 100644
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -422,14 +422,19 @@
 int ngx_http_find_location_config(ngx_http_request_t *r)
 {
     int                           rc;
-    ngx_uint_t                    i, exact;
+    ngx_uint_t                    i;
     ngx_str_t                     *auto_redirect;
     ngx_http_core_loc_conf_t      *clcf, **clcfp;
     ngx_http_core_srv_conf_t      *cscf;
+#if (HAVE_PCRE)
+    ngx_uint_t                    exact;
+#endif
 
     cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
     auto_redirect = NULL;
+#if (HAVE_PCRE)
     exact = 0;
+#endif
 
     clcfp = cscf->locations.elts;
     for (i = 0; i < cscf->locations.nelts; i++) {
@@ -473,7 +478,9 @@
             r->connection->log->log_level = clcf->err_log->log_level;
 
             if (clcfp[i]->exact_match && r->uri.len == clcfp[i]->name.len) {
+#if (HAVE_PCRE)
                 exact = 1;
+#endif
                 break;
             }
         }
@@ -751,14 +758,12 @@
 {
 #if 0
     ngx_http_handler_pt        *h;
-#endif
     ngx_http_conf_ctx_t        *ctx;
     ngx_http_core_main_conf_t  *cmcf;
 
     ctx = (ngx_http_conf_ctx_t *) cycle->conf_ctx[ngx_http_module.index];
     cmcf = ctx->main_conf[ngx_http_core_module.ctx_index];
 
-#if 0
     ngx_test_null(h, ngx_push_array(
                              &cmcf->phases[NGX_HTTP_TRANSLATE_PHASE].handlers),
                   NGX_ERROR);
@@ -775,7 +780,7 @@
     char                        *rv;
     ngx_http_module_t           *module;
     ngx_conf_t                   pcf;
-    ngx_http_conf_ctx_t         *ctx, *hctx, *pctx;
+    ngx_http_conf_ctx_t         *ctx, *hctx;
     ngx_http_core_main_conf_t   *cmcf;
     ngx_http_core_srv_conf_t    *cscf, **cscfp;
 
@@ -830,7 +835,9 @@
     /* parse inside server{} */
 
     pcf = *cf;
+#if 0
     pctx = cf->ctx;
+#endif
     cf->ctx = ctx;
     cf->cmd_type = NGX_HTTP_SRV_CONF;
     rv = ngx_conf_parse(cf, NULL);
diff --git a/src/http/ngx_http_request.h b/src/http/ngx_http_request.h
index e86034e..555d555 100644
--- a/src/http/ngx_http_request.h
+++ b/src/http/ngx_http_request.h
@@ -117,18 +117,6 @@
 
 
 typedef struct {
-    ngx_chain_t       chain[4];
-    ngx_hunk_t       *header_out;
-    ngx_hunk_t       *hunk;
-    ngx_hunk_t       *file_hunk;
-    ngx_file_t        temp_file;
-    ngx_path_t       *temp_path;
-    off_t             offset;
-    u_char           *header_in_pos;
-} ngx_http_request_body_t;
-
-
-typedef struct {
     off_t             start;
     off_t             end;
     ngx_str_t         content_range;
@@ -138,7 +126,7 @@
 typedef struct {
     ngx_table_t       headers;   /* it must be first field */
 
-    int               status;
+    ngx_uint_t        status;
     ngx_str_t         status_line;
 
     ngx_table_elt_t  *server;
@@ -161,6 +149,17 @@
 } ngx_http_headers_out_t;
 
 
+typedef struct {
+    ngx_temp_file_t   *temp_file;
+    ngx_chain_t       *bufs;
+    ngx_hunk_t        *buf;
+    size_t             rest;
+    size_t             buf_size;
+    void             (*handler) (void *data); 
+    void              *data;
+} ngx_http_request_body_t;
+
+
 struct ngx_http_cleanup_s {
     union {
         struct {
@@ -191,15 +190,25 @@
 
     ngx_http_cache_t         *cache;
 
-    ngx_file_t           file;
+    ngx_file_t                file;
 
     ngx_pool_t               *pool;
     ngx_hunk_t               *header_in;
-    ngx_http_request_body_t  *request_body;
 
     ngx_http_headers_in_t     headers_in;
     ngx_http_headers_out_t    headers_out;
 
+    ngx_http_request_body_t  *request_body;
+
+#if 0
+    ngx_temp_file_t     *temp_file;
+    ngx_chain_t         *request_hunks;
+    ngx_hunk_t          *request_body_hunk;
+    size_t               remaining_body_len;
+    void               (*request_body_handler) (void *data); 
+    void                *data;
+#endif
+
     time_t               lingering_time;
 
     ngx_uint_t           method;
@@ -225,15 +234,9 @@
     ngx_int_t            phase_handler;
     ngx_http_handler_pt  content_handler;
 
-    ngx_temp_file_t     *temp_file;
-    ngx_chain_t         *request_hunks;
-    ngx_hunk_t          *request_body_hunk;
-    size_t               remaining_body_len;
-    void               (*request_body_handler) (void *data); 
-    void                *data;
-
     ngx_array_t          cleanup;
 
+    /* used to learn the Apache compatible response length without a header */
     size_t               header_size;
 
     u_char              *discarded_buffer;
diff --git a/src/http/ngx_http_request_body.c b/src/http/ngx_http_request_body.c
index f6be9cf..c54674e 100644
--- a/src/http/ngx_http_request_body.c
+++ b/src/http/ngx_http_request_body.c
@@ -9,26 +9,28 @@
 static ngx_int_t ngx_http_do_read_client_request_body(ngx_http_request_t *r);
 
 
-ngx_int_t ngx_http_read_client_request_body(ngx_http_request_t *r,
-                                            size_t request_buffer_size)
+ngx_int_t ngx_http_read_client_request_body(ngx_http_request_t *r)
 {
     ssize_t       size;
     ngx_hunk_t   *h;
     ngx_chain_t  *cl;
 
+
     size = r->header_in->last - r->header_in->pos;
 
     if (size) {
 
         /* there is the pre-read part of the request body */
 
-        ngx_test_null(h, ngx_calloc_hunk(r->pool), NGX_ERROR);
+        ngx_test_null(h, ngx_calloc_hunk(r->pool),
+                      NGX_HTTP_INTERNAL_SERVER_ERROR);
 
         h->type = NGX_HUNK_IN_MEMORY|NGX_HUNK_TEMP;
         h->start = h->pos = r->header_in->pos;
         h->end = h->last = r->header_in->last;
 
-        ngx_alloc_link_and_set_hunk(r->request_hunks, h, r->pool, NGX_ERROR);
+        ngx_alloc_link_and_set_hunk(r->request_body->bufs, h, r->pool,
+                                    NGX_HTTP_INTERNAL_SERVER_ERROR);
 
         if (size >= r->headers_in.content_length_n) {
 
@@ -42,28 +44,28 @@
     }
 
 
-    r->remaining_body_len = r->headers_in.content_length_n - size;
+    r->request_body->rest = r->headers_in.content_length_n - size;
 
-    if (r->remaining_body_len
-                            < request_buffer_size + (request_buffer_size >> 2))
+    if (r->request_body->rest
+                < r->request_body->buf_size + (r->request_body->buf_size >> 2))
     {
-        size = r->remaining_body_len;
+        size = r->request_body->rest;
 
     } else {
-        size = request_buffer_size;
+        size = r->request_body->buf_size;
     }
 
-    ngx_test_null(r->request_body_hunk, ngx_create_temp_hunk(r->pool, size),
-                  NGX_ERROR);
+    ngx_test_null(r->request_body->buf, ngx_create_temp_hunk(r->pool, size),
+                  NGX_HTTP_INTERNAL_SERVER_ERROR);
 
-    ngx_alloc_link_and_set_hunk(cl, r->request_body_hunk, r->pool,
-                                NGX_ERROR);
+    ngx_alloc_link_and_set_hunk(cl, r->request_body->buf, r->pool,
+                                NGX_HTTP_INTERNAL_SERVER_ERROR);
 
-    if (r->request_hunks) {
-        r->request_hunks->next = cl;
+    if (r->request_body->bufs) {
+        r->request_body->bufs->next = cl;
 
     } else {
-        r->request_hunks = cl;
+        r->request_body->bufs = cl;
     }
 
     r->connection->read->event_handler =
@@ -104,10 +106,10 @@
                    "http read client request body");
 
     for ( ;; ) {
-        if (r->request_body_hunk->last == r->request_body_hunk->end) {
-            n = ngx_write_chain_to_temp_file(r->temp_file,
-                               r->request_hunks->next ? r->request_hunks->next:
-                                                        r->request_hunks);
+        if (r->request_body->buf->last == r->request_body->buf->end) {
+            n = ngx_write_chain_to_temp_file(r->request_body->temp_file,
+                     r->request_body->bufs->next ? r->request_body->bufs->next:
+                                                   r->request_body->bufs);
 
             /* TODO: n == 0 or not complete and level event */
 
@@ -115,19 +117,19 @@
                 return NGX_HTTP_INTERNAL_SERVER_ERROR;
             }
 
-            r->temp_file->offset += n;
+            r->request_body->temp_file->offset += n;
 
-            r->request_body_hunk->pos = r->request_body_hunk->start;
-            r->request_body_hunk->last = r->request_body_hunk->start;
+            r->request_body->buf->pos = r->request_body->buf->start;
+            r->request_body->buf->last = r->request_body->buf->start;
         }
 
-        size = r->request_body_hunk->end - r->request_body_hunk->last;
+        size = r->request_body->buf->end - r->request_body->buf->last;
 
-        if (size > r->remaining_body_len) {
-            size = r->remaining_body_len;
+        if (size > r->request_body->rest) {
+            size = r->request_body->rest;
         }
 
-        n = ngx_recv(c, r->request_body_hunk->last, size);
+        n = ngx_recv(c, r->request_body->buf->last, size);
 
         ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
                        "http client request body recv " SIZE_T_FMT, n);
@@ -153,32 +155,32 @@
             return NGX_HTTP_BAD_REQUEST;
         }
 
-        r->request_body_hunk->last += n;
-        r->remaining_body_len -= n;
+        r->request_body->buf->last += n;
+        r->request_body->rest -= n;
 
-        if (r->remaining_body_len == 0) {
+        if (r->request_body->rest == 0) {
             break;
         }
 
-        if (r->request_body_hunk->last < r->request_body_hunk->end) {
+        if (r->request_body->buf->last < r->request_body->buf->end) {
             break;
         }
     }
 
     ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
-                   "http client request body left " SIZE_T_FMT,
-                   r->remaining_body_len);
+                   "http client request body rest " SIZE_T_FMT,
+                   r->request_body->rest);
 
-    if (r->remaining_body_len) {
+    if (r->request_body->rest) {
         return NGX_AGAIN;
     }
 
-    if (r->temp_file->file.fd != NGX_INVALID_FILE) {
+    if (r->request_body->temp_file->file.fd != NGX_INVALID_FILE) {
 
         /* save the last part */
-        n = ngx_write_chain_to_temp_file(r->temp_file,
-                               r->request_hunks->next ? r->request_hunks->next:
-                                                        r->request_hunks);
+        n = ngx_write_chain_to_temp_file(r->request_body->temp_file,
+                     r->request_body->bufs->next ? r->request_body->bufs->next:
+                                                   r->request_body->bufs);
 
         /* TODO: n == 0 or not complete and level event */
 
@@ -193,18 +195,18 @@
 
         h->type = NGX_HUNK_FILE;
         h->file_pos = 0;
-        h->file_last = r->temp_file->file.offset;
-        h->file = &r->temp_file->file;
+        h->file_last = r->request_body->temp_file->file.offset;
+        h->file = &r->request_body->temp_file->file;
 
-        if (r->request_hunks->next) {
-            r->request_hunks->next->hunk = h;
+        if (r->request_body->bufs->next) {
+            r->request_body->bufs->next->hunk = h;
 
         } else {
-            r->request_hunks->hunk = h;
+            r->request_body->bufs->hunk = h;
         }
     }
 
-    r->request_body_handler(r->data);
+    r->request_body->handler(r->request_body->data);
 
     return NGX_OK;
 }