diff src/http/ngx_http_core.c @ 41:59e7c7f30d49

nginx-0.0.1-2002-12-26-19:26:23 import
author Igor Sysoev <igor@sysoev.ru>
date Thu, 26 Dec 2002 16:26:23 +0000
parents 83fa61cd3d2f
children cd035a94e0b6
line wrap: on
line diff
--- a/src/http/ngx_http_core.c
+++ b/src/http/ngx_http_core.c
@@ -7,7 +7,6 @@
 #include <ngx_http_config.h>
 
 /* STUB */
-#include <ngx_http_output_filter.h>
 int ngx_http_static_handler(ngx_http_request_t *r);
 int ngx_http_index_handler(ngx_http_request_t *r);
 int ngx_http_proxy_handler(ngx_http_request_t *r);
@@ -18,60 +17,85 @@ static void *ngx_http_core_create_loc_co
 static int ngx_http_core_translate_handler(ngx_http_request_t *r);
 
 
+int (*ngx_http_top_header_filter) (ngx_http_request_t *r);
+
+int ngx_http_max_module;
+
+
 static ngx_command_t ngx_http_core_commands[] = {
 
-    {"send_timeout", ngx_conf_set_time_slot,
-     offsetof(ngx_http_core_loc_conf_t, send_timeout),
-     NGX_HTTP_LOC_CONF, NGX_CONF_TAKE1,
-     "set timeout for sending response"},
+    {ngx_string("send_timeout"),
+     NGX_CONF_TAKE1, 
+     ngx_conf_set_time_slot,
+     NGX_HTTP_LOC_CONF,
+     offsetof(ngx_http_core_loc_conf_t, send_timeout)},
 
-    {NULL}
-
+    {ngx_string(""), 0, NULL, 0, 0}
 };
 
 
-ngx_http_module_t  ngx_http_core_module = {
+ngx_http_module_t  ngx_http_core_module_ctx = {
     NGX_HTTP_MODULE,
 
     ngx_http_core_create_srv_conf,         /* create server config */
     ngx_http_core_create_loc_conf,         /* create location config */
-    ngx_http_core_commands,                /* module directives */
 
-    /* STUB */ NULL,                                  /* init module */
     ngx_http_core_translate_handler,       /* translate handler */
 
-    NULL                                   /* init output body filter */
+    NULL,                                  /* output header filter */
+    NULL,                                  /* next output header filter */
+    NULL,                                  /* output body filter */
+    NULL,                                  /* next output body filter */
+};
+
+
+ngx_module_t  ngx_http_core_module = {
+    &ngx_http_core_module_ctx,             /* module context */
+    ngx_http_core_commands,                /* module directives */
+    NGX_HTTP_MODULE_TYPE,                  /* module type */
+    NULL                                   /* init module */
 };
 
 
 int ngx_http_handler(ngx_http_request_t *r)
 {
     int  rc, i;
+    ngx_http_module_t *module;
 
     r->connection->unexpected_eof = 0;
     r->lingering_close = 1;
     r->keepalive = 0;
 
-#if 1
+#if 0
     r->filter = NGX_HTTP_FILTER_NEED_IN_MEMORY;
 #endif
 
     /* run translation phase */
-    for (i = 0; ngx_http_modules[i]; i++) {
-        if (ngx_http_modules[i]->translate_handler) {
-            rc = ngx_http_modules[i]->translate_handler(r);
-            if (rc == NGX_OK)
-                break;
+    for (i = 0; ngx_modules[i]; i++) {
+        if (ngx_modules[i]->type != NGX_HTTP_MODULE_TYPE) {
+            continue;
+        }
 
-            if (rc >= NGX_HTTP_SPECIAL_RESPONSE)
-                return ngx_http_special_response(r, rc);
+        module = (ngx_http_module_t *) ngx_modules[i]->ctx;
+        if (module->translate_handler == NULL) {
+            continue;
+        }
+
+        rc = module->translate_handler(r);
+        if (rc == NGX_OK) {
+            break;
+        }
+
+        if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
+            return ngx_http_special_response(r, rc);
         }
     }
 
     rc = r->handler(r);
 
-    if (rc >= NGX_HTTP_SPECIAL_RESPONSE)
+    if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
         return ngx_http_special_response(r, rc);
+    }
 
     return rc;
 }
@@ -122,18 +146,20 @@ static int ngx_http_core_translate_handl
                       "ngx_http_core_translate_handler: "
                       ngx_file_type_n " %s failed", r->file.name.data);
 
-        if (err == ERROR_FILE_NOT_FOUND)
+        if (err == ERROR_FILE_NOT_FOUND) {
+            return NGX_HTTP_NOT_FOUND;
+        } else if (err == ERROR_PATH_NOT_FOUND) {
             return NGX_HTTP_NOT_FOUND;
-        else if (err == ERROR_PATH_NOT_FOUND)
-            return NGX_HTTP_NOT_FOUND;
-        else
+        } else {
             return NGX_HTTP_INTERNAL_SERVER_ERROR;
+        }
     }
 
 #else
 
-    if (r->file.fd == NGX_INVALID_FILE)
+    if (r->file.fd == NGX_INVALID_FILE) {
         r->file.fd = ngx_open_file(r->file.name.data, NGX_FILE_RDONLY);
+    }
 
     if (r->file.fd == NGX_INVALID_FILE) {
         err = ngx_errno;
@@ -141,10 +167,11 @@ static int ngx_http_core_translate_handl
                       "ngx_http_core_handler: "
                       ngx_open_file_n " %s failed", r->file.name.data);
 
-        if (err == NGX_ENOENT)
+        if (err == NGX_ENOENT) {
             return NGX_HTTP_NOT_FOUND;
-        else
+        } else {
             return NGX_HTTP_INTERNAL_SERVER_ERROR;
+        }
     }
 
     if (!r->file.info_valid) {
@@ -153,10 +180,11 @@ static int ngx_http_core_translate_handl
                           "ngx_http_core_handler: "
                           ngx_stat_fd_n " %s failed", r->file.name.data);
 
-            if (ngx_close_file(r->file.fd) == NGX_FILE_ERROR)
+            if (ngx_close_file(r->file.fd) == NGX_FILE_ERROR) {
                 ngx_log_error(NGX_LOG_ERR, r->connection->log, ngx_errno,
                               "ngx_http_core_handler: "
                               ngx_close_file_n " %s failed", r->file.name.data);
+            }
 
             return NGX_HTTP_INTERNAL_SERVER_ERROR;
         }
@@ -169,10 +197,11 @@ static int ngx_http_core_translate_handl
         ngx_log_debug(r->connection->log, "HTTP DIR: '%s'" _ r->file.name.data);
 
 #if !(WIN9X)
-        if (ngx_close_file(r->file.fd) == NGX_FILE_ERROR)
+        if (ngx_close_file(r->file.fd) == NGX_FILE_ERROR) {
             ngx_log_error(NGX_LOG_ERR, r->connection->log, ngx_errno,
                           "ngx_http_core_handler: "
                           ngx_close_file_n " %s failed", r->file.name.data);
+        }
 #endif
 
         /* BROKEN: need to include server name */