diff src/http/ngx_http_core_module.c @ 92:45945fa8b8ba NGINX_0_2_0

nginx 0.2.0 *) The pid-file names used during online upgrade was changed and now is not required a manual rename operation. The old master process adds the ".oldbin" suffix to its pid-file and executes a new binary file. The new master process creates usual pid-file without the ".newbin" suffix. If the master process exits, then old master process renames back its pid-file with the ".oldbin" suffix to the pid-file without suffix. *) Change: the "worker_connections" directive, new name of the "connections" directive; now the directive specifies maximum number of connections, but not maximum socket descriptor number. *) Feature: SSL supports the session cache inside one worker process. *) Feature: the "satisfy_any" directive. *) Change: the ngx_http_access_module and ngx_http_auth_basic_module do not run for subrequests. *) Feature: the "worker_rlimit_nofile" and "worker_rlimit_sigpending" directives. *) Bugfix: if all backend using in load-balancing failed after one error, then nginx did not try do connect to them during 60 seconds. *) Bugfix: in IMAP/POP3 command argument parsing. Thanks to Rob Mueller. *) Bugfix: errors while using SSL in IMAP/POP3 proxy. *) Bugfix: errors while using SSI and gzipping. *) Bugfix: the "Expires" and "Cache-Control" header lines were omitted from the 304 responses. Thanks to Alexandr Kukushkin.
author Igor Sysoev <http://sysoev.ru>
date Fri, 23 Sep 2005 00:00:00 +0400
parents 71c46860eb55
children f63280c59dd5
line wrap: on
line diff
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -284,6 +284,13 @@ static ngx_command_t  ngx_http_core_comm
       0,
       NULL },
 
+    { ngx_string("satisfy_any"),
+      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
+      ngx_conf_set_flag_slot,
+      NGX_HTTP_LOC_CONF_OFFSET,
+      offsetof(ngx_http_core_loc_conf_t, satisfy_any),
+      NULL },
+
     { ngx_string("internal"),
       NGX_HTTP_LOC_CONF|NGX_CONF_NOARGS,
       ngx_http_core_internal,
@@ -401,50 +408,43 @@ ngx_http_handler(ngx_http_request_t *r)
 
     r->connection->unexpected_eof = 0;
 
-    switch (r->headers_in.connection_type) {
-    case 0:
-        if (r->http_version > NGX_HTTP_VERSION_10) {
+    if (r->err_ctx == NULL) {
+        switch (r->headers_in.connection_type) {
+        case 0:
+            if (r->http_version > NGX_HTTP_VERSION_10) {
+                r->keepalive = 1;
+            } else {
+                r->keepalive = 0;
+            }
+            break;
+
+        case NGX_HTTP_CONNECTION_CLOSE:
+            r->keepalive = 0;
+            break;
+
+        case NGX_HTTP_CONNECTION_KEEP_ALIVE:
             r->keepalive = 1;
-        } else {
+            break;
+        }
+
+        if (r->keepalive && r->headers_in.msie && r->method == NGX_HTTP_POST) {
+
+            /*
+             * MSIE may wait for some time if the response for the POST request
+             * is sent over the keepalive connection
+             */
+
             r->keepalive = 0;
         }
-        break;
-
-    case NGX_HTTP_CONNECTION_CLOSE:
-        r->keepalive = 0;
-        break;
-
-    case NGX_HTTP_CONNECTION_KEEP_ALIVE:
-        r->keepalive = 1;
-        break;
+
+        if (r->headers_in.content_length_n > 0) {
+            r->lingering_close = 1;
+
+        } else {
+            r->lingering_close = 0;
+        }
     }
 
-    if (r->keepalive && r->headers_in.msie && r->method == NGX_HTTP_POST) {
-
-        /*
-         * MSIE may wait for some time if the response for the POST request
-         * is sent over the keepalive connection
-         */
-
-        r->keepalive = 0;
-    }
-
-#if 0
-    /* TEST STUB */ r->http_version = NGX_HTTP_VERSION_10;
-    /* TEST STUB */ r->keepalive = 0;
-#endif
-
-    if (r->headers_in.content_length_n > 0) {
-        r->lingering_close = 1;
-
-    } else {
-        r->lingering_close = 0;
-    }
-
-#if 0
-    /* TEST STUB */ r->lingering_close = 1;
-#endif
-
     r->write_event_handler = ngx_http_core_run_phases;
 
     r->valid_unparsed_uri = 1;
@@ -498,6 +498,10 @@ ngx_http_core_run_phases(ngx_http_reques
             r->phase = NGX_HTTP_FIND_CONFIG_PHASE;
         }
 
+        if (r->phase == NGX_HTTP_ACCESS_PHASE && r->main) {
+            continue;
+        }
+
         if (r->phase == NGX_HTTP_CONTENT_PHASE && r->content_handler) {
             r->write_event_handler = ngx_http_request_empty_handler;
             ngx_http_finalize_request(r, r->content_handler(r));
@@ -515,7 +519,7 @@ ngx_http_core_run_phases(ngx_http_reques
 
                 /*
                  * we should never use r here because 
-                 * it could point to already freed data
+                 * it may point to already freed data
                  */
 
                 return;
@@ -525,6 +529,30 @@ ngx_http_core_run_phases(ngx_http_reques
                 continue;
             }
 
+            if (r->phase == NGX_HTTP_ACCESS_PHASE) {
+                clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
+
+                if (clcf->satisfy_any) {
+
+                    if (rc == NGX_OK) {
+                        r->access_code = 0;
+
+                        if (r->headers_out.www_authenticate) {
+                            r->headers_out.www_authenticate->hash = 0;
+                        }
+
+                        break;
+                    }
+
+                    if (rc == NGX_HTTP_FORBIDDEN || rc == NGX_HTTP_UNAUTHORIZED)
+                    {
+                        r->access_code = rc;
+
+                        continue;
+                    }
+                }
+            }
+
             if (rc >= NGX_HTTP_SPECIAL_RESPONSE
                 || rc == NGX_HTTP_NO_CONTENT
                 || rc == NGX_ERROR)
@@ -545,6 +573,12 @@ ngx_http_core_run_phases(ngx_http_reques
             if (rc == NGX_OK && cmcf->phases[r->phase].type == NGX_OK) {
                 break;
             }
+
+        }
+
+        if (r->phase == NGX_HTTP_ACCESS_PHASE && r->access_code) {
+            ngx_http_finalize_request(r, r->access_code);
+            return;
         }
     }
 
@@ -1102,6 +1136,7 @@ ngx_http_subrequest(ngx_http_request_t *
 
     sr->internal = 1;
 
+    sr->discard_body = r->discard_body;
     sr->main_filter_need_in_memory = r->main_filter_need_in_memory;
 
     ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
@@ -1793,6 +1828,7 @@ ngx_http_core_create_loc_conf(ngx_conf_t
     lcf->client_max_body_size = NGX_CONF_UNSET_SIZE;
     lcf->client_body_buffer_size = NGX_CONF_UNSET_SIZE;
     lcf->client_body_timeout = NGX_CONF_UNSET_MSEC;
+    lcf->satisfy_any = NGX_CONF_UNSET;
     lcf->internal = NGX_CONF_UNSET;
     lcf->sendfile = NGX_CONF_UNSET;
     lcf->tcp_nopush = NGX_CONF_UNSET;
@@ -1895,6 +1931,7 @@ ngx_http_core_merge_loc_conf(ngx_conf_t 
     ngx_conf_merge_msec_value(conf->client_body_timeout,
                               prev->client_body_timeout, 60000);
 
+    ngx_conf_merge_value(conf->satisfy_any, prev->satisfy_any, 0);
     ngx_conf_merge_value(conf->internal, prev->internal, 0);
     ngx_conf_merge_value(conf->sendfile, prev->sendfile, 0);
     ngx_conf_merge_value(conf->tcp_nopush, prev->tcp_nopush, 0);