]> git.kaiwu.me - nginx.git/commitdiff
Upstream: keepalive flag.
authorMaxim Dounin <mdounin@mdounin.ru>
Thu, 15 Sep 2011 19:03:15 +0000 (19:03 +0000)
committerMaxim Dounin <mdounin@mdounin.ru>
Thu, 15 Sep 2011 19:03:15 +0000 (19:03 +0000)
This patch introduces r->upstream->keepalive flag, which is set by protocol
handlers if connection to upstream is in good state and can be kept alive.

src/http/ngx_http_upstream.c
src/http/ngx_http_upstream.h

index 62009f6c702b73907dfcf34ec2ba00f3f6cc294b..4230abc4904016b48e3ad906122d0f10a0ae234c 100644 (file)
@@ -1297,6 +1297,8 @@ ngx_http_upstream_reinit(ngx_http_request_t *r, ngx_http_upstream_t *u)
         return NGX_ERROR;
     }
 
+    u->keepalive = 0;
+
     ngx_memzero(&u->headers_in, sizeof(ngx_http_upstream_headers_in_t));
     u->headers_in.content_length_n = -1;
 
@@ -2006,6 +2008,11 @@ ngx_http_upstream_process_body_in_memory(ngx_http_request_t *r,
         }
     }
 
+    if (u->length == 0) {
+        ngx_http_upstream_finalize_request(r, u, 0);
+        return;
+    }
+
     if (ngx_handle_read_event(rev, 0) != NGX_OK) {
         ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
         return;
@@ -2126,7 +2133,7 @@ ngx_http_upstream_send_response(ngx_http_request_t *r, ngx_http_upstream_t *u)
                 return;
             }
 
-            if (u->peer.connection->read->ready) {
+            if (u->peer.connection->read->ready || u->length == 0) {
                 ngx_http_upstream_process_non_buffered_upstream(r, u);
             }
         }
index c3f706e142460a810586cedc2ca0a0ee50c13ede..6e62044dc11f34958deadf3cea969bc3143736ad 100644 (file)
@@ -308,6 +308,7 @@ struct ngx_http_upstream_s {
 #endif
 
     unsigned                         buffering:1;
+    unsigned                         keepalive:1;
 
     unsigned                         request_sent:1;
     unsigned                         header_sent:1;