nginx-0.1.37-RELEASE import

    *) Change: now the "\n" is added to the end of the "nginx.pid" file.

    *) Bugfix: the responses may be transferred not completely, if many
       parts or the big parts were included by SSI.

    *) Bugfix: if all backends had returned the 404 reponse and the
       "http_404" parameter of the "proxy_next_upstream" or
       "fastcgi_next_upstream" directives was used, then nginx started to
       request all backends again.
diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c
index 51ffbc0..d7ee08f 100644
--- a/src/http/ngx_http_upstream.c
+++ b/src/http/ngx_http_upstream.c
@@ -1230,7 +1230,7 @@
 ngx_http_upstream_next(ngx_http_request_t *r, ngx_http_upstream_t *u,
     ngx_uint_t ft_type)
 {
-    ngx_uint_t  status;
+    ngx_uint_t  status, down;
 
     ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
                    "http next upstream, %xD", ft_type);
@@ -1239,10 +1239,14 @@
     ngx_http_busy_unlock(u->conf->busy_lock, &u->busy_lock);
 #endif
 
-    if (ft_type != NGX_HTTP_UPSTREAM_FT_HTTP_404) {
-        ngx_event_connect_peer_failed(&u->peer);
+    if (ft_type == NGX_HTTP_UPSTREAM_FT_HTTP_404) {
+        down = 0;
+    } else {
+        down = 1;
     }
-    
+
+    ngx_event_connect_peer_failed(&u->peer, down);
+
     if (ft_type == NGX_HTTP_UPSTREAM_FT_TIMEOUT) {
         ngx_log_error(NGX_LOG_ERR, r->connection->log, NGX_ETIMEDOUT,
                       "upstream timed out");
@@ -1285,14 +1289,13 @@
     if (status) {
         u->state->status = status;
 
-        if (u->peer.tries == 0 || !(u->conf->next_upstream & ft_type))
-        {
+        if (u->peer.tries == 0 || !(u->conf->next_upstream & ft_type)) {
 
 #if (NGX_HTTP_CACHE)
 
             if (u->stale && (u->conf->use_stale & ft_type)) {
                 ngx_http_upstream_finalize_request(r, u,
-                                       ngx_http_send_cached_response(r));
+                                             ngx_http_send_cached_response(r));
                 return;
             }