diff src/http/ngx_http_upstream.c @ 384:09b703ae3ba5 NGINX_0_6_36

nginx 0.6.36 *) Change: now the "Invalid argument" error returned by setsockopt(TCP_NODELAY) on Solaris, is ignored. *) Change: now POSTs without "Content-Length" header line are allowed. *) Feature: the "try_files" directive. *) Feature: the --with-pcre option in the configure. *) Feature: the "if_modified_since" directive. *) Feature: the "$cookie_..." variables. *) Feature: the "$arg_..." variables. *) Bugfix: compatibility with Tru64 UNIX. Thanks to Dustin Marquess. *) Bugfix: a "ssl_engine" directive did not use a SSL-accelerator for asymmetric ciphers. Thanks to Marcin Gozdalik. *) Bugfix: in a redirect rewrite directive original arguments were concatenated with new arguments by a "?" rather than an "&"; the bug had appeared in 0.1.18. Thanks to Maxim Dounin. *) Bugfix: nginx could not be built on AIX. *) Bugfix: a double response might be returned if the epoll or rtsig methods are used and a redirect was returned to a request with body. Thanks to Eden Li. *) Bugfix: a segmentation fault might occur in worker process if "resolver" directive was used in SMTP proxy. *) Bugfix: fastcgi_store stored files not always. *) Bugfix: nginx did not process a FastCGI server response, if the server send too many messages to stderr before response.
author Igor Sysoev <http://sysoev.ru>
date Thu, 02 Apr 2009 00:00:00 +0400
parents e9979466be2f
children
line wrap: on
line diff
--- a/src/http/ngx_http_upstream.c
+++ b/src/http/ngx_http_upstream.c
@@ -1099,62 +1099,59 @@ ngx_http_upstream_process_header(ngx_eve
 #endif
     }
 
-    n = c->recv(c, u->buffer.last, u->buffer.end - u->buffer.last);
-
-    if (n == NGX_AGAIN) {
+    for ( ;; ) {
+
+        n = c->recv(c, u->buffer.last, u->buffer.end - u->buffer.last);
+
+        if (n == NGX_AGAIN) {
 #if 0
-        ngx_add_timer(rev, u->read_timeout);
+            ngx_add_timer(rev, u->read_timeout);
 #endif
 
-        if (ngx_handle_read_event(rev, 0) == NGX_ERROR) {
-            ngx_http_upstream_finalize_request(r, u,
+            if (ngx_handle_read_event(rev, 0) == NGX_ERROR) {
+                ngx_http_upstream_finalize_request(r, u,
                                                NGX_HTTP_INTERNAL_SERVER_ERROR);
+                return;
+            }
+
+            return;
+        }
+
+        if (n == 0) {
+            ngx_log_error(NGX_LOG_ERR, rev->log, 0,
+                          "upstream prematurely closed connection");
+        }
+
+        if (n == NGX_ERROR || n == 0) {
+            ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR);
             return;
         }
 
-        return;
-    }
-
-    if (n == 0) {
-        ngx_log_error(NGX_LOG_ERR, rev->log, 0,
-                      "upstream prematurely closed connection");
-    }
-
-    if (n == NGX_ERROR || n == 0) {
-        ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR);
-        return;
-    }
-
-    u->buffer.last += n;
+        u->buffer.last += n;
 
 #if 0
-    u->valid_header_in = 0;
-
-    u->peer.cached = 0;
-#endif
-
-    rc = u->process_header(r);
-
-    if (rc == NGX_AGAIN) {
-#if 0
-        ngx_add_timer(rev, u->read_timeout);
+        u->valid_header_in = 0;
+
+        u->peer.cached = 0;
 #endif
 
-        if (u->buffer.pos == u->buffer.end) {
-            ngx_log_error(NGX_LOG_ERR, rev->log, 0,
-                          "upstream sent too big header");
-
-            ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_INVALID_HEADER);
-            return;
+        rc = u->process_header(r);
+
+        if (rc == NGX_AGAIN) {
+
+            if (u->buffer.pos == u->buffer.end) {
+                ngx_log_error(NGX_LOG_ERR, rev->log, 0,
+                              "upstream sent too big header");
+
+                ngx_http_upstream_next(r, u,
+                                       NGX_HTTP_UPSTREAM_FT_INVALID_HEADER);
+                return;
+            }
+
+            continue;
         }
 
-        if (ngx_handle_read_event(rev, 0) == NGX_ERROR) {
-            ngx_http_upstream_finalize_request(r, u,
-                                               NGX_HTTP_INTERNAL_SERVER_ERROR);
-            return;
-        }
-
-        return;
+        break;
     }
 
     if (rc == NGX_HTTP_UPSTREAM_INVALID_HEADER) {
@@ -1962,6 +1959,7 @@ ngx_http_upstream_process_downstream(ngx
 static void
 ngx_http_upstream_process_body(ngx_event_t *ev)
 {
+    ngx_uint_t            del;
     ngx_temp_file_t      *tf;
     ngx_event_pipe_t     *p;
     ngx_connection_t     *c, *downstream;
@@ -2057,20 +2055,25 @@ ngx_http_upstream_process_body(ngx_event
 
         if (u->store) {
 
+            del = p->upstream_error;
+
             tf = u->pipe->temp_file;
 
-            if (p->upstream_eof
-                && u->headers_in.status_n == NGX_HTTP_OK
-                && (u->headers_in.content_length_n == -1
-                    || (u->headers_in.content_length_n == tf->offset)))
-            {
-                ngx_http_upstream_store(r, u);
-
-            } else if ((p->upstream_error
-                        || (p->upstream_eof
-                            && u->headers_in.status_n != NGX_HTTP_OK))
-                       && tf->file.fd != NGX_INVALID_FILE)
-            {
+            if (p->upstream_eof || p->upstream_done) {
+
+                if (u->headers_in.status_n == NGX_HTTP_OK
+                    && (u->headers_in.content_length_n == -1
+                        || (u->headers_in.content_length_n == tf->offset)))
+                {
+                    ngx_http_upstream_store(r, u);
+
+                } else {
+                    del = 1;
+                }
+            }
+
+            if (del && tf->file.fd != NGX_INVALID_FILE) {
+
                 if (ngx_delete_file(tf->file.name.data) == NGX_FILE_ERROR) {
 
                     ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno,