diff src/http/ngx_http_upstream.c @ 438:ce4f9ff90bfa NGINX_0_7_31

nginx 0.7.31 *) Change: now the "try_files" directive tests files only and ignores directories. *) Feature: the "fastcgi_split_path_info" directive. *) Bugfixes in an "Expect" request header line support. *) Bugfixes in geo ranges. *) Bugfix: in a miss case ngx_http_memcached_module returned the "END" line as response body instead of default 404 page body; the bug had appeared in 0.7.18. Thanks to Maxim Dounin. *) Bugfix: while SMTP proxying nginx issued message "250 2.0.0 OK" instead of "235 2.0.0 OK"; the bug had appeared in 0.7.22. Thanks to Maxim Dounin.
author Igor Sysoev <http://sysoev.ru>
date Mon, 19 Jan 2009 00:00:00 +0300
parents 49a0eb7ce20c
children 6281966854a5
line wrap: on
line diff
--- a/src/http/ngx_http_upstream.c
+++ b/src/http/ngx_http_upstream.c
@@ -1441,11 +1441,6 @@ ngx_http_upstream_test_next(ngx_http_req
             return NGX_OK;
         }
 
-        if (status == NGX_HTTP_NOT_FOUND && u->conf->intercept_404) {
-            ngx_http_upstream_finalize_request(r, u, NGX_HTTP_NOT_FOUND);
-            return NGX_OK;
-        }
-
 #if (NGX_HTTP_CACHE)
 
         if (u->peer.tries == 0 && u->stale && (u->conf->use_stale & un->mask)) {
@@ -1471,6 +1466,13 @@ ngx_http_upstream_intercept_errors(ngx_h
     ngx_http_err_page_t       *err_page;
     ngx_http_core_loc_conf_t  *clcf;
 
+    status = u->headers_in.status_n;
+
+    if (status == NGX_HTTP_NOT_FOUND && u->conf->intercept_404) {
+        ngx_http_upstream_finalize_request(r, u, NGX_HTTP_NOT_FOUND);
+        return NGX_OK;
+    }
+
     if (!u->conf->intercept_errors) {
         return NGX_DECLINED;
     }
@@ -1481,8 +1483,6 @@ ngx_http_upstream_intercept_errors(ngx_h
         return NGX_DECLINED;
     }
 
-    status = u->headers_in.status_n;
-
     err_page = clcf->error_pages->elts;
     for (i = 0; i < clcf->error_pages->nelts; i++) {
 
@@ -2201,6 +2201,7 @@ ngx_http_upstream_process_upstream(ngx_h
 static void
 ngx_http_upstream_process_request(ngx_http_request_t *r)
 {
+    ngx_uint_t            del;
     ngx_temp_file_t      *tf;
     ngx_event_pipe_t     *p;
     ngx_http_upstream_t  *u;
@@ -2212,20 +2213,25 @@ ngx_http_upstream_process_request(ngx_ht
 
         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) {
+
+                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,