diff src/http/ngx_http_upstream.c @ 118:644a7935144b NGINX_0_3_6

nginx 0.3.6 *) Change: now the IMAP/POP3 proxy do not send the empty login to authorization server. *) Feature: the "log_format" supports the variables in the $name form. *) Bugfix: if at least in one server was no the "listen" directive, then nginx did not listen on the 80 port; bug appeared in 0.3.3. *) Bugfix: if the URI part is omitted in "proxy_pass" directive, the the 80 port was always used.
author Igor Sysoev <http://sysoev.ru>
date Mon, 24 Oct 2005 00:00:00 +0400
parents 408f195b3482
children d25a1d6034f1
line wrap: on
line diff
--- a/src/http/ngx_http_upstream.c
+++ b/src/http/ngx_http_upstream.c
@@ -29,6 +29,7 @@ static void ngx_http_upstream_process_bo
 static void ngx_http_upstream_dummy_handler(ngx_event_t *wev);
 static void ngx_http_upstream_next(ngx_http_request_t *r,
     ngx_http_upstream_t *u, ngx_uint_t ft_type);
+static void ngx_http_upstream_cleanup(void *data);
 static void ngx_http_upstream_finalize_request(ngx_http_request_t *r,
     ngx_http_upstream_t *u, ngx_int_t rc);
 
@@ -223,6 +224,7 @@ ngx_http_upstream_init(ngx_http_request_
 {
     ngx_time_t                *tp;
     ngx_connection_t          *c;
+    ngx_http_cleanup_t        *cln;
     ngx_http_upstream_t       *u;
     ngx_http_core_loc_conf_t  *clcf;
 
@@ -277,7 +279,8 @@ ngx_http_upstream_init(ngx_http_request_
     u->writer.pool = r->pool;
 
     if (ngx_array_init(&u->states, r->pool, u->peer.peers->number,
-                       sizeof(ngx_http_upstream_state_t)) != NGX_OK)
+                       sizeof(ngx_http_upstream_state_t))
+        != NGX_OK)
     {
         ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
         return;
@@ -295,6 +298,16 @@ ngx_http_upstream_init(ngx_http_request_
 
     u->state->response_time = tp->sec * 1000 + tp->msec;
 
+    cln = ngx_http_cleanup_add(r, sizeof(void *));
+    if (cln == NULL) {
+        ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
+        return;
+    }
+
+    cln->handler = ngx_http_upstream_cleanup;
+    cln->data = r;
+    u->cleanup = &cln->handler;
+
     ngx_http_upstream_connect(r, u);
 }
 
@@ -1379,8 +1392,7 @@ ngx_http_upstream_next(ngx_http_request_
         }
     }
 
-    if (r->connection->write->eof) {
-        r->connection->closed = 1;
+    if (r->connection->closed) {
         ngx_http_upstream_finalize_request(r, u,
                                            NGX_HTTP_CLIENT_CLOSED_REQUEST);
         return;
@@ -1426,6 +1438,18 @@ ngx_http_upstream_next(ngx_http_request_
 
 
 static void
+ngx_http_upstream_cleanup(void *data)
+{
+    ngx_http_request_t *r = data;
+
+    ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+                   "cleanup http upstream request: \"%V\"", &r->uri);
+
+    ngx_http_upstream_finalize_request(r, r->upstream, NGX_DONE);
+}
+
+
+static void
 ngx_http_upstream_finalize_request(ngx_http_request_t *r,
     ngx_http_upstream_t *u, ngx_int_t rc)
 {
@@ -1434,6 +1458,8 @@ ngx_http_upstream_finalize_request(ngx_h
     ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
                    "finalize http upstream request: %i", rc);
 
+    *u->cleanup = NULL;
+
     if (u->state->response_time) {
         tp = ngx_timeofday();
         u->state->response_time = tp->sec * 1000 + tp->msec
@@ -1864,7 +1890,7 @@ ngx_http_upstream_log_error(ngx_http_req
 
     p = ngx_snprintf(buf, len,
                      ", server: %V, URL: \"%V\","
-                     " upstream: %V%V%s%V",
+                     " upstream: \"%V%V%s%V\"",
                      &r->server_name,
                      &r->unparsed_uri,
                      &u->conf->schema,