nginx-0.0.1-2003-05-27-16:18:54 import
diff --git a/src/http/modules/ngx_http_index_handler.c b/src/http/modules/ngx_http_index_handler.c
index 49a4e0a..4946214 100644
--- a/src/http/modules/ngx_http_index_handler.c
+++ b/src/http/modules/ngx_http_index_handler.c
@@ -1,25 +1,14 @@
 
-#include <ngx_config.h>
-
-#include <ngx_core.h>
-#include <ngx_errno.h>
-#include <ngx_string.h>
-#include <ngx_files.h>
-#include <ngx_conf_file.h>
-
-#include <ngx_http.h>
-#include <ngx_http_config.h>
-#include <ngx_http_core_module.h>
 #include <ngx_http_index_handler.h>
 
 
 static int ngx_http_index_test_dir(ngx_http_request_t *r);
 static int ngx_http_index_init(ngx_pool_t *pool);
 static void *ngx_http_index_create_conf(ngx_pool_t *pool);
-static char *ngx_http_index_merge_conf(ngx_pool_t *p,
-                                       void *parent, void *child);
+static char *ngx_http_index_merge_conf(ngx_pool_t *p, void *parent,
+                                                                  void *child);
 static char *ngx_http_index_set_index(ngx_conf_t *cf, ngx_command_t *cmd,
-                                      char *conf);
+                                                                   void *conf);
 
 
 static ngx_command_t ngx_http_index_commands[] = {
@@ -31,13 +20,11 @@
      0,
      NULL},
 
-    {ngx_string(""), 0, NULL, 0, 0, NULL}
+    ngx_null_command
 };
 
 
 ngx_http_module_t  ngx_http_index_module_ctx = {
-    NGX_HTTP_MODULE,
-
     NULL,                                  /* create main configuration */
     NULL,                                  /* init main configuration */
 
@@ -50,10 +37,10 @@
 
 
 ngx_module_t  ngx_http_index_module = {
+    NGX_MODULE,
     &ngx_http_index_module_ctx,            /* module context */
-    0,                                     /* module index */
     ngx_http_index_commands,               /* module directives */
-    NGX_HTTP_MODULE_TYPE,                  /* module type */
+    NGX_HTTP_MODULE,                       /* module type */
     ngx_http_index_init                    /* init module */
 };
 
@@ -63,42 +50,39 @@
    because the valid requests should be many more then invalid ones.
    If open() failed then stat() should be more quickly because some data
    is already cached in the kernel.
-   Besides Win32 has ERROR_PATH_NOT_FOUND (NGX_ENOTDIR) and
-   Unix has ENOTDIR error (although it less helpfull).
+   Besides Win32 has ERROR_PATH_NOT_FOUND (NGX_ENOTDIR).
+   Unix has ENOTDIR error, although it less helpfull - it shows only
+   that path contains the usual file in place of the directory.
 */
 
 int ngx_http_index_handler(ngx_http_request_t *r)
 {
-    int          i, rc, test_dir;
-    char        *name, *file;
-    ngx_str_t    loc, *index;
-    ngx_err_t    err;
-    ngx_fd_t     fd;
+    int                        i, rc, test_dir;
+    char                      *name, *file;
+    ngx_str_t                  loc, *index;
+    ngx_err_t                  err;
+    ngx_fd_t                   fd;
+    ngx_http_index_conf_t     *icf;
+    ngx_http_core_loc_conf_t  *clcf;
 
-    ngx_http_index_conf_t     *cf;
-    ngx_http_core_loc_conf_t  *core_cf;
-
-    cf = (ngx_http_index_conf_t *)
-                    ngx_http_get_module_loc_conf(r, ngx_http_index_module_ctx);
-
-    core_cf = (ngx_http_core_loc_conf_t *)
-                     ngx_http_get_module_loc_conf(r, ngx_http_core_module_ctx);
+    icf = ngx_http_get_module_loc_conf(r, ngx_http_index_module);
+    clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
 
     ngx_test_null(r->path.data,
                   ngx_palloc(r->pool,
-                             core_cf->doc_root.len + r->uri.len
-                             + cf->max_index_len),
+                             clcf->doc_root.len + r->uri.len
+                             + icf->max_index_len),
                   NGX_HTTP_INTERNAL_SERVER_ERROR);
 
-    loc.data = ngx_cpystrn(r->path.data, core_cf->doc_root.data,
-                           core_cf->doc_root.len + 1);
+    loc.data = ngx_cpystrn(r->path.data, clcf->doc_root.data,
+                           clcf->doc_root.len + 1);
     file = ngx_cpystrn(loc.data, r->uri.data, r->uri.len + 1);
     r->path.len = file - r->path.data;
 
     test_dir = 1;
 
-    index = (ngx_str_t *) cf->indices->elts;
-    for (i = 0; i < cf->indices->nelts; i++) {
+    index = (ngx_str_t *) icf->indices.elts;
+    for (i = 0; i < icf->indices.nelts; i++) {
 
         if (index[i].data[0] != '/') {
             ngx_memcpy(file, index[i].data, index[i].len + 1);
@@ -147,8 +131,8 @@
             return NGX_HTTP_INTERNAL_SERVER_ERROR;
         }
 
-        r->file.name.data = name; 
-        r->file.fd = fd; 
+        r->file.name.data = name;
+        r->file.fd = fd;
 
         if (index[i].data[0] == '/') {
             r->file.name.len = index[i].len;
@@ -157,7 +141,7 @@
 
         } else {
             loc.len = r->uri.len + index[i].len;
-            r->file.name.len = core_cf->doc_root.len + r->uri.len
+            r->file.name.len = clcf->doc_root.len + r->uri.len
                                + index[i].len;
         }
 
@@ -178,9 +162,9 @@
 ngx_log_debug(r->connection->log, "IS_DIR: %s" _ r->path.data);
 
 #if 0
-        if (r->path_err == NGX_EACCES) {
-            return NGX_HTTP_FORBIDDEN;
-        }
+    if (r->path_err == NGX_EACCES) {
+        return NGX_HTTP_FORBIDDEN;
+    }
 #endif
 
     if (ngx_file_type(r->path.data, &r->file.info) == -1) {
@@ -226,76 +210,88 @@
 {
     ngx_http_index_conf_t  *conf;
 
-    ngx_test_null(conf, ngx_pcalloc(pool, sizeof(ngx_http_index_conf_t)),
+    ngx_test_null(conf, ngx_palloc(pool, sizeof(ngx_http_index_conf_t)),
                   NGX_CONF_ERROR);
 
-    ngx_test_null(conf->indices,
-                  ngx_create_array(pool, 3, sizeof(ngx_str_t)),
-                  NGX_CONF_ERROR);
+    ngx_init_array(conf->indices, pool, 3, sizeof(ngx_str_t), NGX_CONF_ERROR);
+    conf->max_index_len = 0;
 
     return conf;
 }
 
 
-/* STUB */
+/* TODO: remove duplicate indices */
+
 static char *ngx_http_index_merge_conf(ngx_pool_t *p, void *parent, void *child)
 {
-#if 0
-    ngx_http_index_conf_t *prev = (ngx_http_index_conf_t *) parent;
-#endif
-    ngx_http_index_conf_t *conf = (ngx_http_index_conf_t *) child;
-    ngx_str_t  *index;
+    ngx_http_index_conf_t *prev = parent;
+    ngx_http_index_conf_t *conf = child;
 
-    if (conf->max_index_len == 0) {
-        ngx_test_null(index, ngx_push_array(conf->indices), NGX_CONF_ERROR);
-        index->len = sizeof(NGX_HTTP_INDEX) - 1;
-        index->data = NGX_HTTP_INDEX;
-        conf->max_index_len = sizeof(NGX_HTTP_INDEX);
-    }
-
-    /* FAIL: if first index is started with '/' */
-
-    return NULL;
-}
-
-
-#if 0
-static char *ngx_http_index_merge_conf(ngx_pool_t *p, void *parent, void *child)
-{
-    ngx_http_index_conf_t *prev = (ngx_http_index_conf_t *) parent;
-    ngx_http_index_conf_t *conf = (ngx_http_index_conf_t *) child;
-    ngx_str_t  *index;
+    int         i;
+    ngx_str_t  *index, *prev_index;
 
     if (conf->max_index_len == 0) {
         if (prev->max_index_len != 0) {
-            return prev;
+            ngx_memcpy(conf, prev, sizeof(ngx_http_index_conf_t)); 
+            return NGX_CONF_OK;
         }
 
-        ngx_test_null(index, ngx_push_array(conf->indices), NULL);
-        index->len = sizeof(NGX_HTTP_INDEX) - 1;
-        index->data = NGX_HTTP_INDEX;
-        conf->max_index_len = sizeof(NGX_HTTP_INDEX);
+        ngx_test_null(index, ngx_push_array(&conf->indices), NGX_CONF_ERROR);
+        index->len = sizeof(NGX_HTTP_DEFAULT_INDEX) - 1;
+        index->data = NGX_HTTP_DEFAULT_INDEX;
+        conf->max_index_len = sizeof(NGX_HTTP_DEFAULT_INDEX);
+
+        return NGX_CONF_OK;
     }
 
-    return conf;
+    if (prev->max_index_len != 0) {
+
+        prev_index = prev->indices.elts;
+        for (i = 0; i < prev->indices.nelts; i++) {
+            ngx_test_null(index, ngx_push_array(&conf->indices),
+                          NGX_CONF_ERROR);
+            index->len = prev_index[i].len;
+            index->data = prev_index[i].data;
+        }
+    }
+
+    if (conf->max_index_len < prev->max_index_len) {
+        conf->max_index_len = prev->max_index_len;
+    }
+
+    return NGX_CONF_OK;
 }
-#endif
+
+
+/* TODO: check duplicate indices */
 
 static char *ngx_http_index_set_index(ngx_conf_t *cf, ngx_command_t *cmd,
-                                      char *conf)
+                                      void *conf)
 {
-    ngx_http_index_conf_t *lcf = (ngx_http_index_conf_t *) conf;
-    int  i;
+    ngx_http_index_conf_t *icf = conf;
+
+    int         i;
     ngx_str_t  *index, *value;
 
-    value = (ngx_str_t *) cf->args->elts;
+    value = cf->args->elts;
+
+    if (value[1].data[0] == '/' && icf->indices.nelts == 0) {
+        ngx_snprintf(ngx_conf_errstr, sizeof(ngx_conf_errstr) - 1,
+                     "first index \"%s\" must not be absolute", value[1].data);
+        return ngx_conf_errstr;
+    }
+
     for (i = 1; i < cf->args->nelts; i++) {
-        ngx_test_null(index, ngx_push_array(lcf->indices), NGX_CONF_ERROR);
+        if (value[i].len == 0) {
+            return "is invalid";
+        }
+
+        ngx_test_null(index, ngx_push_array(&icf->indices), NGX_CONF_ERROR);
         index->len = value[i].len;
         index->data = value[i].data;
 
-        if (lcf->max_index_len < index->len) {
-            lcf->max_index_len = index->len;
+        if (icf->max_index_len < index->len + 1) {
+            icf->max_index_len = index->len + 1;
         }
     }
 
diff --git a/src/http/modules/ngx_http_index_handler.h b/src/http/modules/ngx_http_index_handler.h
index 3dd6bd8..3d2f6f0 100644
--- a/src/http/modules/ngx_http_index_handler.h
+++ b/src/http/modules/ngx_http_index_handler.h
@@ -3,16 +3,16 @@
 
 
 #include <ngx_config.h>
-#include <ngx_array.h>
+#include <ngx_core.h>
 #include <ngx_http.h>
 
 
-#define NGX_HTTP_INDEX   "index.html"
+#define NGX_HTTP_DEFAULT_INDEX   "index.html"
 
 
 typedef struct {
-    ngx_array_t  *indices;
-    size_t        max_index_len;
+    ngx_array_t  indices;
+    size_t       max_index_len;
 } ngx_http_index_conf_t;
 
 
diff --git a/src/http/modules/ngx_http_static_handler.c b/src/http/modules/ngx_http_static_handler.c
index 41f1342..bc88fc9 100644
--- a/src/http/modules/ngx_http_static_handler.c
+++ b/src/http/modules/ngx_http_static_handler.c
@@ -1,38 +1,22 @@
 
 #include <ngx_config.h>
 #include <ngx_core.h>
-#include <ngx_string.h>
-#include <ngx_file.h>
-#include <ngx_hunk.h>
 #include <ngx_http.h>
 #include <ngx_http_config.h>
 #include <ngx_http_core_module.h>
 #include <ngx_http_output_filter.h>
 
 
-ngx_http_module_t  ngx_http_static_module;
-
 
 int ngx_http_static_handler(ngx_http_request_t *r)
 {
-    int                  rc, key, i;
-    ngx_log_e            level;
-    ngx_err_t            err;
-    ngx_hunk_t          *h;
-    ngx_http_type_t     *type;
-    ngx_http_log_ctx_t  *ctx;
-    ngx_http_core_loc_conf_t  *core_lcf; 
-
-    core_lcf = (ngx_http_core_loc_conf_t *)
-                     ngx_http_get_module_loc_conf(r, ngx_http_core_module_ctx);
-
-#if 0
-    ngx_http_event_static_handler_loc_conf_t  *lcf;
-
-    lcf = (ngx_http_event_static_handler_loc_conf_t *)
-         ngx_get_module_loc_conf(r, &ngx_http_event_static_handler_module_ctx);
-
-#endif
+    int                        rc, key, i;
+    ngx_log_e                  level;
+    ngx_err_t                  err;
+    ngx_hunk_t                *h;
+    ngx_http_type_t           *type;
+    ngx_http_log_ctx_t        *ctx;
+    ngx_http_core_loc_conf_t  *clcf;
 
     rc = ngx_http_discard_body(r);
 
@@ -40,6 +24,10 @@
         return rc;
     }
 
+    if (r->method != NGX_HTTP_GET && r->method != NGX_HTTP_HEAD) {
+        return NGX_HTTP_NOT_ALLOWED;
+    }
+
     ctx = r->connection->log->data;
     ctx->action = "sending response";
 
@@ -102,14 +90,18 @@
                   ngx_push_table(r->headers_out.headers),
                   NGX_HTTP_INTERNAL_SERVER_ERROR);
 
-    r->headers_out.content_type->key.len = 12;
-    r->headers_out.content_type->key.data = "Content-Type";
+    r->headers_out.content_type->key.len = 0;
+    r->headers_out.content_type->key.data = NULL;
+    r->headers_out.content_type->value.len = 0;
+    r->headers_out.content_type->value.data = NULL;
+
+    clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
 
     if (r->exten.len) {
         ngx_http_types_hash_key(key, r->exten);
 
-        type = (ngx_http_type_t *) core_lcf->types[key].elts;
-        for (i = 0; i < core_lcf->types[key].nelts; i++) {
+        type = (ngx_http_type_t *) clcf->types[key].elts;
+        for (i = 0; i < clcf->types[key].nelts; i++) {
             if (r->exten.len != type[i].exten.len) {
                 continue;
             }
@@ -117,14 +109,15 @@
             if (ngx_strcasecmp(r->exten.data, type[i].exten.data) == 0) {
                 r->headers_out.content_type->value.len = type[i].type.len;
                 r->headers_out.content_type->value.data = type[i].type.data;
+
+                break;
             }
         }
     }
 
     if (r->headers_out.content_type->value.len == 0) {
-        /* STUB: default type */
-        r->headers_out.content_type->value.len = 25;
-        r->headers_out.content_type->value.data = "text/html; charset=koi8-r";
+        r->headers_out.content_type->value.len = clcf->default_type.len;
+        r->headers_out.content_type->value.data = clcf->default_type.data;
     }
 
     /* we need to allocate all before the header would be sent */
@@ -134,9 +127,19 @@
     ngx_test_null(h->file, ngx_pcalloc(r->pool, sizeof(ngx_file_t)),
                   NGX_HTTP_INTERNAL_SERVER_ERROR);
 
-    ngx_http_send_header(r);
-    if (r->header_only)
+
+    rc = ngx_http_send_header(r);
+
+    if (r->header_only) {
+        if (rc == NGX_AGAIN) {
+            ngx_http_set_write_handler(r);
+
+        } else {
+            ngx_http_finalize_request(r, 0);
+        }
+
         return NGX_OK;
+    }
 
 
     h->type = NGX_HUNK_FILE|NGX_HUNK_LAST;