diff src/http/modules/proxy/ngx_http_proxy_handler.c @ 175:e92c2c647c57

nginx-0.0.1-2003-11-05-20:03:41 import
author Igor Sysoev <igor@sysoev.ru>
date Wed, 05 Nov 2003 17:03:41 +0000
parents ea464a6c0581
children c0552e5ab567
line wrap: on
line diff
--- a/src/http/modules/proxy/ngx_http_proxy_handler.c
+++ b/src/http/modules/proxy/ngx_http_proxy_handler.c
@@ -266,7 +266,9 @@ static int ngx_http_proxy_handler(ngx_ht
     ngx_memzero(p->state, sizeof(ngx_http_proxy_state_t));
 
 
-    if (!p->lcf->cache) {
+    if (!p->lcf->cache
+        || (r->method != NGX_HTTP_GET && r->method != NGX_HTTP_HEAD))
+    {
         p->state->cache = NGX_HTTP_PROXY_CACHE_PASS;
 
     } else if (r->bypass_cache) {
@@ -290,16 +292,16 @@ static int ngx_http_proxy_handler(ngx_ht
 
     rc = ngx_http_proxy_get_cached_response(p);
 
+    if (rc == NGX_DONE || rc == NGX_HTTP_INTERNAL_SERVER_ERROR) {
+        return rc;
+    }
+
     p->valid_header_in = 1;
 
     if (rc == NGX_OK) {
         return ngx_http_proxy_send_cached_response(p);
     }
 
-    if (rc == NGX_HTTP_INTERNAL_SERVER_ERROR) {
-        return rc;
-    }
-
     /* rc == NGX_DECLINED || NGX_HTTP_CACHE_STALE || NGX_HTTP_CACHE_AGED */
 
     return ngx_http_proxy_request_upstream(p);
@@ -312,8 +314,7 @@ void ngx_http_proxy_finalize_request(ngx
                   "finalize http proxy request");
 
     if (p->upstream->peer.connection) {
-        ngx_http_proxy_close_connection(p->upstream->peer.connection);
-        p->upstream->peer.connection = NULL;
+        ngx_http_proxy_close_connection(p);
     }
 
     if (p->header_sent
@@ -329,8 +330,17 @@ void ngx_http_proxy_finalize_request(ngx
 }
 
 
-void ngx_http_proxy_close_connection(ngx_connection_t *c)
+void ngx_http_proxy_close_connection(ngx_http_proxy_ctx_t *p)
 {
+    ngx_connection_t  *c;
+
+    c = p->upstream->peer.connection;
+    p->upstream->peer.connection = NULL;
+
+    if (p->lcf->busy_lock) {
+        p->lcf->busy_lock->conn_n--;
+    }
+
     ngx_log_debug(c->log, "proxy close connection: %d" _ c->fd);
 
     if (c->fd == -1) {
@@ -505,6 +515,13 @@ static char *ngx_http_proxy_merge_loc_co
 
     if (conf->busy_lock && conf->cache && conf->busy_lock->busy == NULL) {
 
+        /* ngx_alloc_shared() */
+        conf->busy_lock->busy_mask =
+                     ngx_palloc(cf->pool, (conf->busy_lock->max_conn + 7) / 8);
+        if (conf->busy_lock->busy_mask == NULL) {
+            return NGX_CONF_ERROR;
+        }
+
         /* 16 bytes are 128 bits of the md5 */
 
         /* ngx_alloc_shared() */