diff src/http/ngx_http_upstream.c @ 78:9db7e0b5b27f NGINX_0_1_39

nginx 0.1.39 *) The changes in the ngx_http_charset_module: the "default_charset" directive was canceled; the "charset" directive sets the response charset; the "source_charset" directive sets the source charset only. *) Bugfix: the backend "WWW-Authenticate" header line did not transferred while the 401 response code redirecting. *) Bugfix: the ngx_http_proxy_module and ngx_http_fastcgi_module may close a connection before anything was transferred to a client; bug appeared in 0.1.38. *) Workaround: the Linux glibc crypt_r() initialization bug. *) Bugfix: the ngx_http_ssi_module did not support the relative URI in the "include virtual" command. *) Bugfix: if the backend response had the "Location" header line and nginx should not rewrite this line, then the 500 code response body was transferred; bug appeared in 0.1.29. *) Bugfix: some directives of the ngx_http_proxy_module and ngx_http_fastcgi_module were not inherited from the server to the location level; bug appeared in 0.1.29. *) Bugfix: the ngx_http_ssl_module did not support the certificate chain. *) Bugfix: the ngx_http_autoindex_module did not show correctly the long file names; bug appeared in 0.1.38. *) Bugfixes in IMAP/POP3 proxy in interaction with a backend at the login state.
author Igor Sysoev <http://sysoev.ru>
date Thu, 14 Jul 2005 00:00:00 +0400
parents da9a3b14312d
children 6ae11d59d10e
line wrap: on
line diff
--- a/src/http/ngx_http_upstream.c
+++ b/src/http/ngx_http_upstream.c
@@ -103,6 +103,11 @@ ngx_http_upstream_header_t  ngx_http_ups
                  ngx_http_upstream_conditional_copy_header_line,
                  offsetof(ngx_http_upstream_conf_t, pass_server), 0 },
 
+    { ngx_string("WWW-Authenticate"),
+                 ngx_http_upstream_process_header_line,
+                 offsetof(ngx_http_upstream_headers_in_t, www_authenticate),
+                 ngx_http_upstream_copy_header_line, 0, 0 },
+
     { ngx_string("Location"),
                  ngx_http_upstream_ignore_header_line, 0,
                  ngx_http_upstream_rewrite_location, 0, 0 },
@@ -113,7 +118,7 @@ ngx_http_upstream_header_t  ngx_http_ups
 
     { ngx_string("Set-Cookie"),
                  ngx_http_upstream_ignore_header_line, 0,
-                 ngx_http_upstream_copy_header_line, 0, 1 },
+                 ngx_http_upstream_copy_header_line, 0, 0 },
 
     { ngx_string("Cache-Control"),
                  ngx_http_upstream_process_multi_header_lines,
@@ -386,9 +391,6 @@ ngx_http_upstream_check_broken_connectio
         return;
     }
 
-    ev->eof = 1;
-    c->closed = 1;
-
     if (n == -1) {
         if (err == NGX_EAGAIN) {
             return;
@@ -400,6 +402,9 @@ ngx_http_upstream_check_broken_connectio
         err = 0;
     }
 
+    ev->eof = 1;
+    c->closed = 1;
+
     if (!u->cachable && u->peer.connection) {
         ngx_log_error(NGX_LOG_INFO, ev->log, err,
                       "client closed prematurely connection, "
@@ -851,7 +856,7 @@ ngx_http_upstream_process_header(ngx_eve
 
     /* rc == NGX_OK */
 
-    if (r->headers_out.status == NGX_HTTP_INTERNAL_SERVER_ERROR) {
+    if (u->headers_in.status_n == NGX_HTTP_INTERNAL_SERVER_ERROR) {
 
         if (u->peer.tries > 1
             && (u->conf->next_upstream & NGX_HTTP_UPSTREAM_FT_HTTP_500))
@@ -867,14 +872,14 @@ ngx_http_upstream_process_header(ngx_eve
             && (u->conf->use_stale & NGX_HTTP_UPSTREAM_FT_HTTP_500))
         {
             ngx_http_upstream_finalize_request(r, u,
-                                             ngx_http_send_cached_response(r));
+                                              ngx_http_send_cached_response(r));
             return;
         }
 
 #endif
     }
 
-    if (r->headers_out.status == NGX_HTTP_NOT_FOUND
+    if (u->headers_in.status_n == NGX_HTTP_NOT_FOUND
         && u->peer.tries > 1
         && u->conf->next_upstream & NGX_HTTP_UPSTREAM_FT_HTTP_404)
     {
@@ -883,7 +888,7 @@ ngx_http_upstream_process_header(ngx_eve
     }
 
 
-    if (r->headers_out.status >= NGX_HTTP_BAD_REQUEST
+    if (u->headers_in.status_n >= NGX_HTTP_BAD_REQUEST
         && u->conf->redirect_errors
         && r->err_ctx == NULL)
     {
@@ -893,9 +898,25 @@ ngx_http_upstream_process_header(ngx_eve
 
             err_page = clcf->error_pages->elts;
             for (i = 0; i < clcf->error_pages->nelts; i++) {
-                if (err_page[i].status == (ngx_int_t) r->headers_out.status) {
+                if (err_page[i].status == (ngx_int_t) u->headers_in.status_n) {
+
+                    if (u->headers_in.status_n == NGX_HTTP_UNAUTHORIZED) {
+
+                        r->headers_out.www_authenticate =
+                                        ngx_list_push(&r->headers_out.headers);
+
+                        if (r->headers_out.www_authenticate == NULL) {
+                            ngx_http_upstream_finalize_request(r, u,
+                                               NGX_HTTP_INTERNAL_SERVER_ERROR);
+                            return;
+                        }
+
+                        *r->headers_out.www_authenticate = 
+                                               *u->headers_in.www_authenticate;
+                    }
+
                     ngx_http_upstream_finalize_request(r, u,
-                                                       r->headers_out.status);
+                                                       u->headers_in.status_n);
                     return;
                 }
             }
@@ -938,8 +959,6 @@ ngx_http_upstream_process_header(ngx_eve
             }
         }
 
-        r->headers_out.status_line.len = 0;
-
         ngx_http_internal_redirect(r,
                               &r->upstream->headers_in.x_accel_redirect->value,
                               NULL);
@@ -1001,6 +1020,9 @@ ngx_http_upstream_send_response(ngx_http
         }
     }
 
+    r->headers_out.status = u->headers_in.status_n;
+    r->headers_out.status_line = u->headers_in.status_line;
+
     rc = ngx_http_send_header(r);
 
     if (rc == NGX_ERROR || rc > NGX_OK) {
@@ -1622,6 +1644,10 @@ ngx_http_upstream_rewrite_location(ngx_h
     if (r->upstream->rewrite_redirect) {
         rc = r->upstream->rewrite_redirect(r, ho, 0);
 
+        if (rc == NGX_DECLINED) {
+            return NGX_OK;
+        }
+
         if (rc == NGX_OK) {
             r->headers_out.location = ho;
 
@@ -1667,6 +1693,10 @@ ngx_http_upstream_rewrite_refresh(ngx_ht
             return NGX_OK;
         }
 
+        if (rc == NGX_DECLINED) {
+            return NGX_OK;
+        }
+
 #if (NGX_DEBUG)
         if (rc == NGX_OK) {
             ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,