nginx-0.4.0-RELEASE import

    *) Change in internal API: the HTTP modules initialization was moved
       from the init module phase to the HTTP postconfiguration phase.

    *) Change: now the request body is not read beforehand for the
       ngx_http_perl_module: it's required to start the reading using the
       $r->has_request_body method.

    *) Feature: the ngx_http_perl_module supports the DECLINED return code.

    *) Feature: the ngx_http_dav_module supports the incoming "Date" header
       line for the PUT method.

    *) Feature: the "ssi" directive is available inside the "if" block.

    *) Bugfix: a segmentation fault occurred if there was an "index"
       directive with variables and the first index name was without
       variables; the bug had appeared in 0.1.29.
diff --git a/src/http/modules/ngx_http_access_module.c b/src/http/modules/ngx_http_access_module.c
index 93c8652..2cd8a8f 100644
--- a/src/http/modules/ngx_http_access_module.c
+++ b/src/http/modules/ngx_http_access_module.c
@@ -29,7 +29,7 @@
 static void *ngx_http_access_create_loc_conf(ngx_conf_t *cf);
 static char *ngx_http_access_merge_loc_conf(ngx_conf_t *cf,
     void *parent, void *child);
-static ngx_int_t ngx_http_access_init(ngx_cycle_t *cycle);
+static ngx_int_t ngx_http_access_init(ngx_conf_t *cf);
 
 
 static ngx_command_t  ngx_http_access_commands[] = {
@@ -57,7 +57,7 @@
 
 static ngx_http_module_t  ngx_http_access_module_ctx = {
     NULL,                                  /* preconfiguration */
-    NULL,                                  /* postconfiguration */
+    ngx_http_access_init,                  /* postconfiguration */
 
     NULL,                                  /* create main configuration */
     NULL,                                  /* init main configuration */
@@ -76,7 +76,7 @@
     ngx_http_access_commands,              /* module directives */
     NGX_HTTP_MODULE,                       /* module type */
     NULL,                                  /* init master */
-    ngx_http_access_init,                  /* init module */
+    NULL,                                  /* init module */
     NULL,                                  /* init process */
     NULL,                                  /* init thread */
     NULL,                                  /* exit thread */
@@ -215,12 +215,12 @@
 
 
 static ngx_int_t
-ngx_http_access_init(ngx_cycle_t *cycle)
+ngx_http_access_init(ngx_conf_t *cf)
 {
     ngx_http_handler_pt        *h;
     ngx_http_core_main_conf_t  *cmcf;
 
-    cmcf = ngx_http_cycle_get_module_main_conf(cycle, ngx_http_core_module);
+    cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
 
     h = ngx_array_push(&cmcf->phases[NGX_HTTP_ACCESS_PHASE].handlers);
     if (h == NULL) {
diff --git a/src/http/modules/ngx_http_addition_filter_module.c b/src/http/modules/ngx_http_addition_filter_module.c
index 31209f9..9db87bd 100644
--- a/src/http/modules/ngx_http_addition_filter_module.c
+++ b/src/http/modules/ngx_http_addition_filter_module.c
@@ -20,10 +20,10 @@
 } ngx_http_addition_ctx_t;
 
 
-static ngx_int_t ngx_http_addition_filter_init(ngx_cycle_t *cycle);
 static void *ngx_http_addition_create_conf(ngx_conf_t *cf);
 static char *ngx_http_addition_merge_conf(ngx_conf_t *cf, void *parent,
     void *child);
+static ngx_int_t ngx_http_addition_filter_init(ngx_conf_t *cf);
 
 
 static ngx_command_t  ngx_http_addition_commands[] = {
@@ -48,7 +48,7 @@
 
 static ngx_http_module_t  ngx_http_addition_filter_module_ctx = {
     NULL,                                  /* preconfiguration */
-    NULL,                                  /* postconfiguration */
+    ngx_http_addition_filter_init,         /* postconfiguration */
 
     NULL,                                  /* create main configuration */
     NULL,                                  /* init main configuration */
@@ -67,7 +67,7 @@
     ngx_http_addition_commands,            /* module directives */
     NGX_HTTP_MODULE,                       /* module type */
     NULL,                                  /* init master */
-    ngx_http_addition_filter_init,         /* init module */
+    NULL,                                  /* init module */
     NULL,                                  /* init process */
     NULL,                                  /* init thread */
     NULL,                                  /* exit thread */
@@ -178,7 +178,7 @@
 
 
 static ngx_int_t
-ngx_http_addition_filter_init(ngx_cycle_t *cycle)
+ngx_http_addition_filter_init(ngx_conf_t *cf)
 {
     ngx_http_next_header_filter = ngx_http_top_header_filter;
     ngx_http_top_header_filter = ngx_http_addition_header_filter;
diff --git a/src/http/modules/ngx_http_auth_basic_module.c b/src/http/modules/ngx_http_auth_basic_module.c
index 113527f..5a4f9d8 100644
--- a/src/http/modules/ngx_http_auth_basic_module.c
+++ b/src/http/modules/ngx_http_auth_basic_module.c
@@ -32,7 +32,7 @@
 static void *ngx_http_auth_basic_create_loc_conf(ngx_conf_t *cf);
 static char *ngx_http_auth_basic_merge_loc_conf(ngx_conf_t *cf,
     void *parent, void *child);
-static ngx_int_t ngx_http_auth_basic_init(ngx_cycle_t *cycle);
+static ngx_int_t ngx_http_auth_basic_init(ngx_conf_t *cf);
 static char *ngx_http_auth_basic(ngx_conf_t *cf, void *post, void *data);
 
 
@@ -62,7 +62,7 @@
 
 static ngx_http_module_t  ngx_http_auth_basic_module_ctx = {
     NULL,                                  /* preconfiguration */
-    NULL,                                  /* postconfiguration */
+    ngx_http_auth_basic_init,              /* postconfiguration */
 
     NULL,                                  /* create main configuration */
     NULL,                                  /* init main configuration */
@@ -81,7 +81,7 @@
     ngx_http_auth_basic_commands,          /* module directives */
     NGX_HTTP_MODULE,                       /* module type */
     NULL,                                  /* init master */
-    ngx_http_auth_basic_init,              /* init module */
+    NULL,                                  /* init module */
     NULL,                                  /* init process */
     NULL,                                  /* init thread */
     NULL,                                  /* exit thread */
@@ -351,12 +351,12 @@
 
 
 static ngx_int_t
-ngx_http_auth_basic_init(ngx_cycle_t *cycle)
+ngx_http_auth_basic_init(ngx_conf_t *cf)
 {
     ngx_http_handler_pt        *h;
     ngx_http_core_main_conf_t  *cmcf;
 
-    cmcf = ngx_http_cycle_get_module_main_conf(cycle, ngx_http_core_module);
+    cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
 
     h = ngx_array_push(&cmcf->phases[NGX_HTTP_ACCESS_PHASE].handlers);
     if (h == NULL) {
diff --git a/src/http/modules/ngx_http_autoindex_module.c b/src/http/modules/ngx_http_autoindex_module.c
index 7064f37..1c77093 100644
--- a/src/http/modules/ngx_http_autoindex_module.c
+++ b/src/http/modules/ngx_http_autoindex_module.c
@@ -48,7 +48,7 @@
     const void *two);
 static ngx_int_t ngx_http_autoindex_error(ngx_http_request_t *r,
     ngx_dir_t *dir, ngx_str_t *name);
-static ngx_int_t ngx_http_autoindex_init(ngx_cycle_t *cycle);
+static ngx_int_t ngx_http_autoindex_init(ngx_conf_t *cf);
 static void *ngx_http_autoindex_create_loc_conf(ngx_conf_t *cf);
 static char *ngx_http_autoindex_merge_loc_conf(ngx_conf_t *cf,
     void *parent, void *child);
@@ -83,7 +83,7 @@
 
 static ngx_http_module_t  ngx_http_autoindex_module_ctx = {
     NULL,                                  /* preconfiguration */
-    NULL,                                  /* postconfiguration */
+    ngx_http_autoindex_init,               /* postconfiguration */
 
     NULL,                                  /* create main configuration */
     NULL,                                  /* init main configuration */
@@ -102,7 +102,7 @@
     ngx_http_autoindex_commands,           /* module directives */
     NGX_HTTP_MODULE,                       /* module type */
     NULL,                                  /* init master */
-    ngx_http_autoindex_init,               /* init module */
+    NULL,                                  /* init module */
     NULL,                                  /* init process */
     NULL,                                  /* init thread */
     NULL,                                  /* exit thread */
@@ -590,25 +590,6 @@
 }
 
 
-static ngx_int_t
-ngx_http_autoindex_init(ngx_cycle_t *cycle)
-{
-    ngx_http_handler_pt        *h;
-    ngx_http_core_main_conf_t  *cmcf;
-
-    cmcf = ngx_http_cycle_get_module_main_conf(cycle, ngx_http_core_module);
-
-    h = ngx_array_push(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers);
-    if (h == NULL) {
-        return NGX_ERROR;
-    }
-
-    *h = ngx_http_autoindex_handler;
-
-    return NGX_OK;
-}
-
-
 static void *
 ngx_http_autoindex_create_loc_conf(ngx_conf_t *cf)
 {
@@ -639,3 +620,22 @@
 
     return NGX_CONF_OK;
 }
+
+
+static ngx_int_t
+ngx_http_autoindex_init(ngx_conf_t *cf)
+{
+    ngx_http_handler_pt        *h;
+    ngx_http_core_main_conf_t  *cmcf;
+
+    cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
+
+    h = ngx_array_push(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers);
+    if (h == NULL) {
+        return NGX_ERROR;
+    }
+
+    *h = ngx_http_autoindex_handler;
+
+    return NGX_OK;
+}
diff --git a/src/http/modules/ngx_http_charset_filter_module.c b/src/http/modules/ngx_http_charset_filter_module.c
index ab6f5ce..bf6ecc8 100644
--- a/src/http/modules/ngx_http_charset_filter_module.c
+++ b/src/http/modules/ngx_http_charset_filter_module.c
@@ -102,8 +102,6 @@
     void *conf);
 static ngx_int_t ngx_http_add_charset(ngx_array_t *charsets, ngx_str_t *name);
 
-static ngx_int_t ngx_http_charset_filter_init(ngx_cycle_t *cycle);
-
 static void *ngx_http_charset_create_main_conf(ngx_conf_t *cf);
 static void *ngx_http_charset_create_loc_conf(ngx_conf_t *cf);
 static char *ngx_http_charset_merge_loc_conf(ngx_conf_t *cf,
@@ -169,7 +167,7 @@
     ngx_http_charset_filter_commands,      /* module directives */
     NGX_HTTP_MODULE,                       /* module type */
     NULL,                                  /* init master */
-    ngx_http_charset_filter_init,          /* init module */
+    NULL,                                  /* init module */
     NULL,                                  /* init process */
     NULL,                                  /* init thread */
     NULL,                                  /* exit thread */
@@ -1334,19 +1332,6 @@
 }
 
 
-static ngx_int_t
-ngx_http_charset_filter_init(ngx_cycle_t *cycle)
-{
-    ngx_http_next_header_filter = ngx_http_top_header_filter;
-    ngx_http_top_header_filter = ngx_http_charset_header_filter;
-
-    ngx_http_next_body_filter = ngx_http_top_body_filter;
-    ngx_http_top_body_filter = ngx_http_charset_body_filter;
-
-    return NGX_OK;
-}
-
-
 static void *
 ngx_http_charset_create_main_conf(ngx_conf_t *cf)
 {
@@ -1516,5 +1501,11 @@
         dst[tables[t].src] = tables[t].dst2src;
     }
 
+    ngx_http_next_header_filter = ngx_http_top_header_filter;
+    ngx_http_top_header_filter = ngx_http_charset_header_filter;
+
+    ngx_http_next_body_filter = ngx_http_top_body_filter;
+    ngx_http_top_body_filter = ngx_http_charset_body_filter;
+
     return NGX_OK;
 }
diff --git a/src/http/modules/ngx_http_chunked_filter_module.c b/src/http/modules/ngx_http_chunked_filter_module.c
index 4e02194..3cc20eb 100644
--- a/src/http/modules/ngx_http_chunked_filter_module.c
+++ b/src/http/modules/ngx_http_chunked_filter_module.c
@@ -9,12 +9,12 @@
 #include <ngx_http.h>
 
 
-static ngx_int_t ngx_http_chunked_filter_init(ngx_cycle_t *cycle);
+static ngx_int_t ngx_http_chunked_filter_init(ngx_conf_t *cf);
 
 
 static ngx_http_module_t  ngx_http_chunked_filter_module_ctx = {
     NULL,                                  /* preconfiguration */
-    NULL,                                  /* postconfiguration */
+    ngx_http_chunked_filter_init,          /* postconfiguration */
 
     NULL,                                  /* create main configuration */
     NULL,                                  /* init main configuration */
@@ -33,7 +33,7 @@
     NULL,                                  /* module directives */
     NGX_HTTP_MODULE,                       /* module type */
     NULL,                                  /* init master */
-    ngx_http_chunked_filter_init,          /* init module */
+    NULL,                                  /* init module */
     NULL,                                  /* init process */
     NULL,                                  /* init thread */
     NULL,                                  /* exit thread */
@@ -183,7 +183,7 @@
 
 
 static ngx_int_t
-ngx_http_chunked_filter_init(ngx_cycle_t *cycle)
+ngx_http_chunked_filter_init(ngx_conf_t *cf)
 {
     ngx_http_next_header_filter = ngx_http_top_header_filter;
     ngx_http_top_header_filter = ngx_http_chunked_header_filter;
diff --git a/src/http/modules/ngx_http_dav_module.c b/src/http/modules/ngx_http_dav_module.c
index 8bede73..02dd388 100644
--- a/src/http/modules/ngx_http_dav_module.c
+++ b/src/http/modules/ngx_http_dav_module.c
@@ -28,7 +28,7 @@
 static void *ngx_http_dav_create_loc_conf(ngx_conf_t *cf);
 static char *ngx_http_dav_merge_loc_conf(ngx_conf_t *cf,
     void *parent, void *child);
-static ngx_int_t ngx_http_dav_init(ngx_cycle_t *cycle);
+static ngx_int_t ngx_http_dav_init(ngx_conf_t *cf);
 
 
 static ngx_conf_bitmask_t  ngx_http_dav_methods_mask[] = {
@@ -69,7 +69,7 @@
 
 static ngx_http_module_t  ngx_http_dav_module_ctx = {
     NULL,                                  /* preconfiguration */
-    NULL,                                  /* postconfiguration */
+    ngx_http_dav_init,                     /* postconfiguration */
 
     NULL,                                  /* create main configuration */
     NULL,                                  /* init main configuration */
@@ -88,7 +88,7 @@
     ngx_http_dav_commands,                 /* module directives */
     NGX_HTTP_MODULE,                       /* module type */
     NULL,                                  /* init master */
-    ngx_http_dav_init,                     /* init module */
+    NULL,                                  /* init module */
     NULL,                                  /* init process */
     NULL,                                  /* init thread */
     NULL,                                  /* exit thread */
@@ -245,6 +245,7 @@
 {
     char                     *failed;
     u_char                   *name;
+    time_t                    date;
     ngx_err_t                 err;
     ngx_str_t                *temp, path;
     ngx_uint_t                status;
@@ -295,6 +296,24 @@
 
 #endif
 
+    if (r->headers_in.date) {
+        date = ngx_http_parse_time(r->headers_in.date->value.data,
+                                   r->headers_in.date->value.len);
+
+        if (date != NGX_ERROR) {
+            if (ngx_set_file_time(temp->data,
+                                  r->request_body->temp_file->file.fd, date)
+                != NGX_OK)
+            {
+                err = ngx_errno;
+                failed = ngx_set_file_time_n;
+                name = temp->data;
+
+                goto failed;
+            }
+        }
+    }
+
     failed = ngx_rename_file_n;
     name = path.data;
 
@@ -332,13 +351,10 @@
         err = ngx_errno;
     }
 
-
-#else
+#endif
 
 failed:
 
-#endif
-
     if (ngx_delete_file(temp->data) == NGX_FILE_ERROR) {
         ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno,
                       ngx_delete_file_n " \"%s\" failed",
@@ -543,12 +559,12 @@
 
 
 static ngx_int_t
-ngx_http_dav_init(ngx_cycle_t *cycle)
+ngx_http_dav_init(ngx_conf_t *cf)
 {
     ngx_http_handler_pt        *h;
     ngx_http_core_main_conf_t  *cmcf;
 
-    cmcf = ngx_http_cycle_get_module_main_conf(cycle, ngx_http_core_module);
+    cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
 
     h = ngx_array_push(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers);
     if (h == NULL) {
diff --git a/src/http/modules/ngx_http_gzip_filter_module.c b/src/http/modules/ngx_http_gzip_filter_module.c
index 26c1649..e3bf752 100644
--- a/src/http/modules/ngx_http_gzip_filter_module.c
+++ b/src/http/modules/ngx_http_gzip_filter_module.c
@@ -83,7 +83,7 @@
 static ngx_int_t ngx_http_gzip_ratio_variable(ngx_http_request_t *r,
     ngx_http_variable_value_t *v, uintptr_t data);
 
-static ngx_int_t ngx_http_gzip_filter_init(ngx_cycle_t *cycle);
+static ngx_int_t ngx_http_gzip_filter_init(ngx_conf_t *cf);
 static void *ngx_http_gzip_create_conf(ngx_conf_t *cf);
 static char *ngx_http_gzip_merge_conf(ngx_conf_t *cf,
     void *parent, void *child);
@@ -201,7 +201,7 @@
 
 static ngx_http_module_t  ngx_http_gzip_filter_module_ctx = {
     ngx_http_gzip_add_variables,           /* preconfiguration */
-    NULL,                                  /* postconfiguration */
+    ngx_http_gzip_filter_init,             /* postconfiguration */
 
     NULL,                                  /* create main configuration */
     NULL,                                  /* init main configuration */
@@ -220,7 +220,7 @@
     ngx_http_gzip_filter_commands,         /* module directives */
     NGX_HTTP_MODULE,                       /* module type */
     NULL,                                  /* init master */
-    ngx_http_gzip_filter_init,             /* init module */
+    NULL,                                  /* init module */
     NULL,                                  /* init process */
     NULL,                                  /* init thread */
     NULL,                                  /* exit thread */
@@ -1030,19 +1030,6 @@
 }
 
 
-static ngx_int_t
-ngx_http_gzip_filter_init(ngx_cycle_t *cycle)
-{
-    ngx_http_next_header_filter = ngx_http_top_header_filter;
-    ngx_http_top_header_filter = ngx_http_gzip_header_filter;
-
-    ngx_http_next_body_filter = ngx_http_top_body_filter;
-    ngx_http_top_body_filter = ngx_http_gzip_body_filter;
-
-    return NGX_OK;
-}
-
-
 static void *
 ngx_http_gzip_create_conf(ngx_conf_t *cf)
 {
@@ -1123,6 +1110,19 @@
 }
 
 
+static ngx_int_t
+ngx_http_gzip_filter_init(ngx_conf_t *cf)
+{
+    ngx_http_next_header_filter = ngx_http_top_header_filter;
+    ngx_http_top_header_filter = ngx_http_gzip_header_filter;
+
+    ngx_http_next_body_filter = ngx_http_top_body_filter;
+    ngx_http_top_body_filter = ngx_http_gzip_body_filter;
+
+    return NGX_OK;
+}
+
+
 static char *
 ngx_http_gzip_types(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
 {
diff --git a/src/http/modules/ngx_http_headers_filter_module.c b/src/http/modules/ngx_http_headers_filter_module.c
index 8065742..fcb31a7 100644
--- a/src/http/modules/ngx_http_headers_filter_module.c
+++ b/src/http/modules/ngx_http_headers_filter_module.c
@@ -28,10 +28,10 @@
 #define NGX_HTTP_EXPIRES_EPOCH   -2147483645
 
 
-static ngx_int_t ngx_http_headers_filter_init(ngx_cycle_t *cycle);
 static void *ngx_http_headers_create_conf(ngx_conf_t *cf);
 static char *ngx_http_headers_merge_conf(ngx_conf_t *cf,
     void *parent, void *child);
+static ngx_int_t ngx_http_headers_filter_init(ngx_conf_t *cf);
 static char *ngx_http_headers_expires(ngx_conf_t *cf, ngx_command_t *cmd,
     void *conf);
 static char *ngx_http_headers_add(ngx_conf_t *cf, ngx_command_t *cmd,
@@ -62,7 +62,7 @@
 
 static ngx_http_module_t  ngx_http_headers_filter_module_ctx = {
     NULL,                                  /* preconfiguration */
-    NULL,                                  /* postconfiguration */
+    ngx_http_headers_filter_init,          /* postconfiguration */
 
     NULL,                                  /* create main configuration */
     NULL,                                  /* init main configuration */
@@ -81,7 +81,7 @@
     ngx_http_headers_filter_commands,      /* module directives */
     NGX_HTTP_MODULE,                       /* module type */
     NULL,                                  /* init master */
-    ngx_http_headers_filter_init,          /* init module */
+    NULL,                                  /* init module */
     NULL,                                  /* init process */
     NULL,                                  /* init thread */
     NULL,                                  /* exit thread */
@@ -274,16 +274,6 @@
 }
 
 
-static ngx_int_t
-ngx_http_headers_filter_init(ngx_cycle_t *cycle)
-{
-    ngx_http_next_header_filter = ngx_http_top_header_filter;
-    ngx_http_top_header_filter = ngx_http_headers_filter;
-
-    return NGX_OK;
-}
-
-
 static void *
 ngx_http_headers_create_conf(ngx_conf_t *cf)
 {
@@ -331,6 +321,16 @@
 }
 
 
+static ngx_int_t
+ngx_http_headers_filter_init(ngx_conf_t *cf)
+{
+    ngx_http_next_header_filter = ngx_http_top_header_filter;
+    ngx_http_top_header_filter = ngx_http_headers_filter;
+
+    return NGX_OK;
+}
+
+
 static char *
 ngx_http_headers_expires(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
 {
diff --git a/src/http/modules/ngx_http_index_module.c b/src/http/modules/ngx_http_index_module.c
index b93e6fb..cd1c51e 100644
--- a/src/http/modules/ngx_http_index_module.c
+++ b/src/http/modules/ngx_http_index_module.c
@@ -40,7 +40,7 @@
 static ngx_int_t ngx_http_index_error(ngx_http_request_t *r,
     ngx_http_index_ctx_t *ctx, ngx_err_t err);
 
-static ngx_int_t ngx_http_index_init(ngx_cycle_t *cycle);
+static ngx_int_t ngx_http_index_init(ngx_conf_t *cf);
 static void *ngx_http_index_create_loc_conf(ngx_conf_t *cf);
 static char *ngx_http_index_merge_loc_conf(ngx_conf_t *cf,
     void *parent, void *child);
@@ -74,7 +74,7 @@
 
 static ngx_http_module_t  ngx_http_index_module_ctx = {
     NULL,                                  /* preconfiguration */
-    NULL,                                  /* postconfiguration */
+    ngx_http_index_init,                   /* postconfiguration */
 
     NULL,                                  /* create main configuration */
     NULL,                                  /* init main configuration */
@@ -93,7 +93,7 @@
     ngx_http_index_commands,               /* module directives */
     NGX_HTTP_MODULE,                       /* module type */
     NULL,                                  /* init master */
-    ngx_http_index_init,                   /* init module */
+    NULL,                                  /* init module */
     NULL,                                  /* init process */
     NULL,                                  /* init thread */
     NULL,                                  /* exit thread */
@@ -198,7 +198,7 @@
             len += 16;
         }
 
-        if (len > ctx->path.len) {
+        if (len > (size_t) (ctx->path.data + ctx->path.len - ctx->index.data)) {
 
             last = ngx_http_map_uri_to_path(r, &ctx->path, len);
             if (last == NULL) {
@@ -378,7 +378,7 @@
     }
 
     conf->indices = NULL;
-    conf->max_index_len = 1;
+    conf->max_index_len = 0;
 
     return conf;
 }
@@ -422,6 +422,25 @@
 }
 
 
+static ngx_int_t
+ngx_http_index_init(ngx_conf_t *cf)
+{
+    ngx_http_handler_pt        *h;
+    ngx_http_core_main_conf_t  *cmcf;
+
+    cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
+
+    h = ngx_array_push(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers);
+    if (h == NULL) {
+        return NGX_ERROR;
+    }
+
+    *h = ngx_http_index_handler;
+
+    return NGX_OK;
+}
+
+
 /* TODO: warn about duplicate indices */
 
 static char *
@@ -429,8 +448,8 @@
 {
     ngx_http_index_loc_conf_t *ilcf = conf;
 
-    ngx_uint_t                  i, n;
     ngx_str_t                  *value;
+    ngx_uint_t                  i, n;
     ngx_http_index_t           *index;
     ngx_http_script_compile_t   sc;
 
@@ -471,9 +490,7 @@
         n = ngx_http_script_variables_count(&value[i]);
 
         if (n == 0) {
-            if (ilcf->max_index_len != 0
-                && ilcf->max_index_len < index->name.len)
-            {
+            if (ilcf->max_index_len < index->name.len) {
                 ilcf->max_index_len = index->name.len;
             }
 
@@ -496,28 +513,7 @@
         if (ngx_http_script_compile(&sc) != NGX_OK) {
             return NGX_CONF_ERROR;
         }
-
-        ilcf->max_index_len = 0;
     }
 
     return NGX_CONF_OK;
 }
-
-
-static ngx_int_t
-ngx_http_index_init(ngx_cycle_t *cycle)
-{
-    ngx_http_handler_pt        *h;
-    ngx_http_core_main_conf_t  *cmcf;
-
-    cmcf = ngx_http_cycle_get_module_main_conf(cycle, ngx_http_core_module);
-
-    h = ngx_array_push(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers);
-    if (h == NULL) {
-        return NGX_ERROR;
-    }
-
-    *h = ngx_http_index_handler;
-
-    return NGX_OK;
-}
diff --git a/src/http/modules/ngx_http_not_modified_filter_module.c b/src/http/modules/ngx_http_not_modified_filter_module.c
index 6dd8a32..dc62636 100644
--- a/src/http/modules/ngx_http_not_modified_filter_module.c
+++ b/src/http/modules/ngx_http_not_modified_filter_module.c
@@ -10,12 +10,12 @@
 
 
 
-static ngx_int_t ngx_http_not_modified_filter_init(ngx_cycle_t *cycle);
+static ngx_int_t ngx_http_not_modified_filter_init(ngx_conf_t *cf);
 
 
 static ngx_http_module_t  ngx_http_not_modified_filter_module_ctx = {
     NULL,                                  /* preconfiguration */
-    NULL,                                  /* postconfiguration */
+    ngx_http_not_modified_filter_init,     /* postconfiguration */
 
     NULL,                                  /* create main configuration */
     NULL,                                  /* init main configuration */
@@ -34,7 +34,7 @@
     NULL,                                  /* module directives */
     NGX_HTTP_MODULE,                       /* module type */
     NULL,                                  /* init master */
-    ngx_http_not_modified_filter_init,     /* init module */
+    NULL,                                  /* init module */
     NULL,                                  /* init process */
     NULL,                                  /* init thread */
     NULL,                                  /* exit thread */
@@ -47,7 +47,8 @@
 static ngx_http_output_header_filter_pt  ngx_http_next_header_filter;
 
 
-static ngx_int_t ngx_http_not_modified_header_filter(ngx_http_request_t *r)
+static
+ngx_int_t ngx_http_not_modified_header_filter(ngx_http_request_t *r)
 {
     time_t  ims;
 
@@ -80,7 +81,8 @@
 }
 
 
-static ngx_int_t ngx_http_not_modified_filter_init(ngx_cycle_t *cycle)
+static
+ngx_int_t ngx_http_not_modified_filter_init(ngx_conf_t *cf)
 {
     ngx_http_next_header_filter = ngx_http_top_header_filter;
     ngx_http_top_header_filter = ngx_http_not_modified_header_filter;
diff --git a/src/http/modules/ngx_http_range_filter_module.c b/src/http/modules/ngx_http_range_filter_module.c
index 7beb091..ab346f9 100644
--- a/src/http/modules/ngx_http_range_filter_module.c
+++ b/src/http/modules/ngx_http_range_filter_module.c
@@ -49,13 +49,13 @@
 } ngx_http_range_filter_ctx_t;
 
 
-static ngx_int_t ngx_http_range_header_filter_init(ngx_cycle_t *cycle);
-static ngx_int_t ngx_http_range_body_filter_init(ngx_cycle_t *cycle);
+static ngx_int_t ngx_http_range_header_filter_init(ngx_conf_t *cf);
+static ngx_int_t ngx_http_range_body_filter_init(ngx_conf_t *cf);
 
 
 static ngx_http_module_t  ngx_http_range_header_filter_module_ctx = {
     NULL,                                  /* preconfiguration */
-    NULL,                                  /* postconfiguration */
+    ngx_http_range_header_filter_init,     /* postconfiguration */
 
     NULL,                                  /* create main configuration */
     NULL,                                  /* init main configuration */
@@ -74,7 +74,7 @@
     NULL,                                  /* module directives */
     NGX_HTTP_MODULE,                       /* module type */
     NULL,                                  /* init master */
-    ngx_http_range_header_filter_init,     /* init module */
+    NULL,                                  /* init module */
     NULL,                                  /* init process */
     NULL,                                  /* init thread */
     NULL,                                  /* exit thread */
@@ -86,7 +86,7 @@
 
 static ngx_http_module_t  ngx_http_range_body_filter_module_ctx = {
     NULL,                                  /* preconfiguration */
-    NULL,                                  /* postconfiguration */
+    ngx_http_range_body_filter_init,       /* postconfiguration */
 
     NULL,                                  /* create main configuration */
     NULL,                                  /* init main configuration */
@@ -105,7 +105,7 @@
     NULL,                                  /* module directives */
     NGX_HTTP_MODULE,                       /* module type */
     NULL,                                  /* init master */
-    ngx_http_range_body_filter_init,       /* init module */
+    NULL,                                  /* init module */
     NULL,                                  /* init process */
     NULL,                                  /* init thread */
     NULL,                                  /* exit thread */
@@ -588,7 +588,7 @@
 
 
 static ngx_int_t
-ngx_http_range_header_filter_init(ngx_cycle_t *cycle)
+ngx_http_range_header_filter_init(ngx_conf_t *cf)
 {
     ngx_http_next_header_filter = ngx_http_top_header_filter;
     ngx_http_top_header_filter = ngx_http_range_header_filter;
@@ -598,7 +598,7 @@
 
 
 static ngx_int_t
-ngx_http_range_body_filter_init(ngx_cycle_t *cycle)
+ngx_http_range_body_filter_init(ngx_conf_t *cf)
 {
     ngx_http_next_body_filter = ngx_http_top_body_filter;
     ngx_http_top_body_filter = ngx_http_range_body_filter;
diff --git a/src/http/modules/ngx_http_realip_module.c b/src/http/modules/ngx_http_realip_module.c
index 8f128d2..df58598 100644
--- a/src/http/modules/ngx_http_realip_module.c
+++ b/src/http/modules/ngx_http_realip_module.c
@@ -30,7 +30,7 @@
 static void *ngx_http_realip_create_loc_conf(ngx_conf_t *cf);
 static char *ngx_http_realip_merge_loc_conf(ngx_conf_t *cf,
     void *parent, void *child);
-static ngx_int_t ngx_http_realip_init(ngx_cycle_t *cycle);
+static ngx_int_t ngx_http_realip_init(ngx_conf_t *cf);
 
 
 static ngx_conf_enum_t  ngx_http_realip_header[] = {
@@ -63,7 +63,7 @@
 
 static ngx_http_module_t  ngx_http_realip_module_ctx = {
     NULL,                                  /* preconfiguration */
-    NULL,                                  /* postconfiguration */
+    ngx_http_realip_init,                  /* postconfiguration */
 
     NULL,                                  /* create main configuration */
     NULL,                                  /* init main configuration */
@@ -82,7 +82,7 @@
     ngx_http_realip_commands,              /* module directives */
     NGX_HTTP_MODULE,                       /* module type */
     NULL,                                  /* init master */
-    ngx_http_realip_init,                  /* init module */
+    NULL,                                  /* init module */
     NULL,                                  /* init process */
     NULL,                                  /* init thread */
     NULL,                                  /* exit thread */
@@ -250,12 +250,12 @@
 
 
 static ngx_int_t
-ngx_http_realip_init(ngx_cycle_t *cycle)
+ngx_http_realip_init(ngx_conf_t *cf)
 {
     ngx_http_handler_pt        *h;
     ngx_http_core_main_conf_t  *cmcf;
 
-    cmcf = ngx_http_cycle_get_module_main_conf(cycle, ngx_http_core_module);
+    cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
 
     h = ngx_array_push(&cmcf->phases[NGX_HTTP_POST_READ_PHASE].handlers);
     if (h == NULL) {
diff --git a/src/http/modules/ngx_http_rewrite_module.c b/src/http/modules/ngx_http_rewrite_module.c
index 30fbcd8..6db1bc0 100644
--- a/src/http/modules/ngx_http_rewrite_module.c
+++ b/src/http/modules/ngx_http_rewrite_module.c
@@ -23,7 +23,7 @@
 static void *ngx_http_rewrite_create_loc_conf(ngx_conf_t *cf);
 static char *ngx_http_rewrite_merge_loc_conf(ngx_conf_t *cf,
     void *parent, void *child);
-static ngx_int_t ngx_http_rewrite_init(ngx_cycle_t *cycle);
+static ngx_int_t ngx_http_rewrite_init(ngx_conf_t *cf);
 static char *ngx_http_rewrite(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
 static char *ngx_http_rewrite_return(ngx_conf_t *cf, ngx_command_t *cmd,
     void *conf);
@@ -104,7 +104,7 @@
 
 static ngx_http_module_t  ngx_http_rewrite_module_ctx = {
     NULL,                                  /* preconfiguration */
-    NULL,                                  /* postconfiguration */
+    ngx_http_rewrite_init,                 /* postconfiguration */
 
     NULL,                                  /* create main configuration */
     NULL,                                  /* init main configuration */
@@ -123,7 +123,7 @@
     ngx_http_rewrite_commands,             /* module directives */
     NGX_HTTP_MODULE,                       /* module type */
     NULL,                                  /* init master */
-    ngx_http_rewrite_init,                 /* init module */
+    NULL,                                  /* init module */
     NULL,                                  /* init process */
     NULL,                                  /* init thread */
     NULL,                                  /* exit thread */
@@ -267,12 +267,12 @@
 
 
 static ngx_int_t
-ngx_http_rewrite_init(ngx_cycle_t *cycle)
+ngx_http_rewrite_init(ngx_conf_t *cf)
 {
     ngx_http_handler_pt        *h;
     ngx_http_core_main_conf_t  *cmcf;
 
-    cmcf = ngx_http_cycle_get_module_main_conf(cycle, ngx_http_core_module);
+    cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
 
     h = ngx_array_push(&cmcf->phases[NGX_HTTP_SERVER_REWRITE_PHASE].handlers);
     if (h == NULL) {
diff --git a/src/http/modules/ngx_http_ssi_filter_module.c b/src/http/modules/ngx_http_ssi_filter_module.c
index ef870be..5045fd6 100644
--- a/src/http/modules/ngx_http_ssi_filter_module.c
+++ b/src/http/modules/ngx_http_ssi_filter_module.c
@@ -106,13 +106,14 @@
 static void *ngx_http_ssi_create_conf(ngx_conf_t *cf);
 static char *ngx_http_ssi_merge_conf(ngx_conf_t *cf,
     void *parent, void *child);
-static ngx_int_t ngx_http_ssi_filter_init(ngx_cycle_t *cycle);
+static ngx_int_t ngx_http_ssi_filter_init(ngx_conf_t *cf);
 
 
 static ngx_command_t  ngx_http_ssi_filter_commands[] = {
 
     { ngx_string("ssi"),
-      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
+      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
+                        |NGX_CONF_FLAG,
       ngx_conf_set_flag_slot,
       NGX_HTTP_LOC_CONF_OFFSET,
       offsetof(ngx_http_ssi_loc_conf_t, enable),
@@ -160,7 +161,7 @@
 
 static ngx_http_module_t  ngx_http_ssi_filter_module_ctx = {
     ngx_http_ssi_preconfiguration,         /* preconfiguration */
-    NULL,                                  /* postconfiguration */
+    ngx_http_ssi_filter_init,              /* postconfiguration */
 
     ngx_http_ssi_create_main_conf,         /* create main configuration */
     ngx_http_ssi_init_main_conf,           /* init main configuration */
@@ -179,7 +180,7 @@
     ngx_http_ssi_filter_commands,          /* module directives */
     NGX_HTTP_MODULE,                       /* module type */
     NULL,                                  /* init master */
-    ngx_http_ssi_filter_init,              /* init module */
+    NULL,                                  /* init module */
     NULL,                                  /* init process */
     NULL,                                  /* init thread */
     NULL,                                  /* exit thread */
@@ -2654,7 +2655,7 @@
 
 
 static ngx_int_t
-ngx_http_ssi_filter_init(ngx_cycle_t *cycle)
+ngx_http_ssi_filter_init(ngx_conf_t *cf)
 {
     ngx_http_next_header_filter = ngx_http_top_header_filter;
     ngx_http_top_header_filter = ngx_http_ssi_header_filter;
diff --git a/src/http/modules/ngx_http_static_module.c b/src/http/modules/ngx_http_static_module.c
index ad08852..f9df46e 100644
--- a/src/http/modules/ngx_http_static_module.c
+++ b/src/http/modules/ngx_http_static_module.c
@@ -18,7 +18,7 @@
 static void *ngx_http_static_create_loc_conf(ngx_conf_t *cf);
 static char *ngx_http_static_merge_loc_conf(ngx_conf_t *cf,
     void *parent, void *child);
-static ngx_int_t ngx_http_static_init(ngx_cycle_t *cycle);
+static ngx_int_t ngx_http_static_init(ngx_conf_t *cf);
 
 
 static ngx_command_t  ngx_http_static_commands[] = {
@@ -40,7 +40,7 @@
 
 ngx_http_module_t  ngx_http_static_module_ctx = {
     NULL,                                  /* preconfiguration */
-    NULL,                                  /* postconfiguration */
+    ngx_http_static_init,                  /* postconfiguration */
 
     NULL,                                  /* create main configuration */
     NULL,                                  /* init main configuration */
@@ -59,7 +59,7 @@
     ngx_http_static_commands,              /* module directives */
     NGX_HTTP_MODULE,                       /* module type */
     NULL,                                  /* init master */
-    ngx_http_static_init,                  /* init module */
+    NULL,                                  /* init module */
     NULL,                                  /* init process */
     NULL,                                  /* init thread */
     NULL,                                  /* exit thread */
@@ -317,12 +317,12 @@
 
 
 static ngx_int_t
-ngx_http_static_init(ngx_cycle_t *cycle)
+ngx_http_static_init(ngx_conf_t *cf)
 {
     ngx_http_handler_pt        *h;
     ngx_http_core_main_conf_t  *cmcf;
 
-    cmcf = ngx_http_cycle_get_module_main_conf(cycle, ngx_http_core_module);
+    cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
 
     h = ngx_array_push(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers);
     if (h == NULL) {
diff --git a/src/http/modules/ngx_http_userid_filter_module.c b/src/http/modules/ngx_http_userid_filter_module.c
index 648f1ad..c341a08 100644
--- a/src/http/modules/ngx_http_userid_filter_module.c
+++ b/src/http/modules/ngx_http_userid_filter_module.c
@@ -59,7 +59,7 @@
 static ngx_int_t ngx_http_userid_variable(ngx_http_request_t *r,
     ngx_http_variable_value_t *v, uintptr_t data);
 
-static ngx_int_t ngx_http_userid_init(ngx_cycle_t *cycle);
+static ngx_int_t ngx_http_userid_init(ngx_conf_t *cf);
 static void *ngx_http_userid_create_conf(ngx_conf_t *cf);
 static char *ngx_http_userid_merge_conf(ngx_conf_t *cf, void *parent,
     void *child);
@@ -162,7 +162,7 @@
 
 static ngx_http_module_t  ngx_http_userid_filter_module_ctx = {
     ngx_http_userid_add_variables,         /* preconfiguration */
-    NULL,                                  /* postconfiguration */
+    ngx_http_userid_init,                  /* postconfiguration */
 
     NULL,                                  /* create main configuration */
     NULL,                                  /* init main configuration */
@@ -181,7 +181,7 @@
     ngx_http_userid_commands,              /* module directives */
     NGX_HTTP_MODULE,                       /* module type */
     NULL,                                  /* init master */
-    ngx_http_userid_init,                  /* init module */
+    NULL,                                  /* init module */
     NULL,                                  /* init process */
     NULL,                                  /* init thread */
     NULL,                                  /* exit thread */
@@ -622,16 +622,6 @@
 }
 
 
-static ngx_int_t
-ngx_http_userid_init(ngx_cycle_t *cycle)
-{
-    ngx_http_next_header_filter = ngx_http_top_header_filter;
-    ngx_http_top_header_filter = ngx_http_userid_filter;
-
-    return NGX_OK;
-}
-
-
 static void *
 ngx_http_userid_create_conf(ngx_conf_t *cf)
 {
@@ -693,6 +683,16 @@
 }
 
 
+static ngx_int_t
+ngx_http_userid_init(ngx_conf_t *cf)
+{
+    ngx_http_next_header_filter = ngx_http_top_header_filter;
+    ngx_http_top_header_filter = ngx_http_userid_filter;
+
+    return NGX_OK;
+}
+
+
 static char *
 ngx_http_userid_domain(ngx_conf_t *cf, void *post, void *data)
 {
diff --git a/src/http/modules/perl/Makefile.PL b/src/http/modules/perl/Makefile.PL
index 48f1ebc..c33b1fc 100644
--- a/src/http/modules/perl/Makefile.PL
+++ b/src/http/modules/perl/Makefile.PL
@@ -12,7 +12,7 @@
     ABSTRACT_FROM     => 'nginx.pm',     # retrieve abstract from module
     AUTHOR            => 'Igor Sysoev',
 
-    CCFLAGS           => "$ENV{NGX_PERL_CFLAGS}",
+    CCFLAGS           => "$ENV{NGX_PM_CFLAGS}",
     OPTIMIZE          => '-O',
 
     INC               => "-I ../../../../../src/core " .
@@ -22,8 +22,9 @@
                          "-I ../../../../../src/http/modules " .
                          "-I ../../../../../src/http/modules/perl " .
                          "-I ../../../../../$ENV{NGX_OBJS} " .
-                         "-I ../../../../../$ENV{NGX_PCRE} " .
-                         "-I ../../../../../$ENV{NGX_ZLIB} ",
+                         ($ENV{NGX_PCRE} =~ /^(YES|NO)/ ? "" :
+                             ($ENV{NGX_PCRE} =~ m#^/# ? "-I $ENV{NGX_PCRE} " :
+                                  "-I ../../../../../$ENV{NGX_PCRE} ")),
 
     depend => {
         'nginx.c'     =>
diff --git a/src/http/modules/perl/nginx.pm b/src/http/modules/perl/nginx.pm
index badd494..309eaa5 100644
--- a/src/http/modules/perl/nginx.pm
+++ b/src/http/modules/perl/nginx.pm
@@ -17,7 +17,7 @@
     HTTP_SERVER_ERROR
 );
 
-our $VERSION = '0.3.43';
+our $VERSION = '0.4.0';
 
 require XSLoader;
 XSLoader::load('nginx', $VERSION);
diff --git a/src/http/modules/perl/nginx.xs b/src/http/modules/perl/nginx.xs
index 53b6a92..6e6afed 100644
--- a/src/http/modules/perl/nginx.xs
+++ b/src/http/modules/perl/nginx.xs
@@ -329,6 +329,42 @@
 
 
 void
+has_request_body(r, next)
+    CODE:
+
+    dXSTARG;
+    ngx_http_request_t   *r;
+    SV                   *next;
+    ngx_http_perl_ctx_t  *ctx;
+
+    ngx_http_perl_set_request(r);
+
+    if (r->headers_in.content_length_n <= 0) {
+        XSRETURN_UNDEF;
+    }
+
+    next = ST(1);
+
+    ctx = ngx_http_get_module_ctx(r, ngx_http_perl_module);
+    ctx->next = next;
+
+    r->request_body_in_single_buf = 1;
+    r->request_body_in_persistent_file = 1;
+    r->request_body_delete_incomplete_file = 1;
+
+    if (r->request_body_in_file_only) {
+        r->request_body_file_log_level = 0;
+    }
+
+    ngx_http_read_client_request_body(r, ngx_http_perl_handle_request);
+
+    sv_upgrade(TARG, SVt_IV);
+    sv_setiv(TARG, 1);
+
+    ST(0) = TARG;
+
+
+void
 request_body(r)
     CODE:
 
diff --git a/src/http/modules/perl/ngx_http_perl_module.c b/src/http/modules/perl/ngx_http_perl_module.c
index 6f979c6..e59ece4 100644
--- a/src/http/modules/perl/ngx_http_perl_module.c
+++ b/src/http/modules/perl/ngx_http_perl_module.c
@@ -45,7 +45,6 @@
     ngx_http_ssi_ctx_t *ssi_ctx, ngx_str_t **params);
 #endif
 
-static void ngx_http_perl_handle_request(ngx_http_request_t *r);
 static ngx_int_t
     ngx_http_perl_get_interpreter(ngx_http_perl_main_conf_t *pmcf,
     PerlInterpreter **perl, ngx_log_t *log);
@@ -176,6 +175,9 @@
 #endif
 
 
+static ngx_str_t  ngx_null_name = ngx_null_string;
+
+
 static HV  *nginx_stash;
 
 static void
@@ -190,13 +192,16 @@
 static ngx_int_t
 ngx_http_perl_handler(ngx_http_request_t *r)
 {
-    ngx_int_t  rc;
-
     /* TODO: Win32 */
     if (r->zero_in_uri) {
         return NGX_HTTP_NOT_FOUND;
     }
 
+    ngx_http_perl_handle_request(r);
+
+    return NGX_DONE;
+
+#if 0
     r->request_body_in_single_buf = 1;
     r->request_body_in_persistent_file = 1;
     r->request_body_delete_incomplete_file = 1;
@@ -212,14 +217,16 @@
     }
 
     return NGX_DONE;
+#endif
 }
 
 
-static void
+void
 ngx_http_perl_handle_request(ngx_http_request_t *r)
 {
+    SV                         *sub;
     ngx_int_t                   rc;
-    ngx_str_t                   uri, args;
+    ngx_str_t                   uri, args, *handler;
     ngx_http_perl_ctx_t        *ctx;
     ngx_http_perl_loc_conf_t   *plcf;
     ngx_http_perl_main_conf_t  *pmcf;
@@ -231,7 +238,7 @@
     if (ctx == NULL) {
         ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_perl_ctx_t));
         if (ctx == NULL) {
-            ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
+            ngx_http_finalize_request(r, NGX_ERROR);
 	    return;
         }
 
@@ -251,10 +258,18 @@
 
     dTHXa(ctx->perl);
 
-    plcf = ngx_http_get_module_loc_conf(r, ngx_http_perl_module);
+    if (ctx->next == NULL) {
+        plcf = ngx_http_get_module_loc_conf(r, ngx_http_perl_module);
+        sub = plcf->sub;
+        handler = &plcf->handler;
 
-    rc = ngx_http_perl_call_handler(aTHX_ r, plcf->sub, NULL,
-                                    &plcf->handler, NULL);
+    } else {
+        sub = ctx->next;
+        handler = &ngx_null_name;
+        ctx->next = NULL;
+    }
+
+    rc = ngx_http_perl_call_handler(aTHX_ r, sub, NULL, handler, NULL);
 
     }
 
@@ -278,6 +293,10 @@
     ctx->filename.data = NULL;
     ctx->redirect_uri.len = 0;
 
+    if (ctx->done || ctx->next) {
+        return;
+    }
+
     if (uri.len) {
         ngx_http_internal_redirect(r, &uri, &args);
         return;
@@ -285,6 +304,7 @@
 
     if (rc == NGX_OK || rc == NGX_HTTP_OK) {
         ngx_http_send_special(r, NGX_HTTP_LAST);
+        ctx->done = 1;
     }
 
     ngx_http_finalize_request(r, rc);
@@ -666,14 +686,6 @@
 }
 
 
-#if (__INTEL_COMPILER)
-/*
- * disable 'declaration hides parameter "my_perl"' warning for ENTER and LEAVE
- */
-#pragma warning(disable:1599)
-#endif
-
-
 static ngx_int_t
 ngx_http_perl_call_handler(pTHX_ ngx_http_request_t *r, SV *sub,
     ngx_str_t **args, ngx_str_t *handler, ngx_str_t *rv)
@@ -773,11 +785,6 @@
 }
 
 
-#if (__INTEL_COMPILER)
-#pragma warning(default:1599)
-#endif
-
-
 static void
 ngx_http_perl_eval_anon_sub(pTHX_ ngx_str_t *handler, SV **sv)
 {
diff --git a/src/http/modules/perl/ngx_http_perl_module.h b/src/http/modules/perl/ngx_http_perl_module.h
index 1609c47..66d15da 100644
--- a/src/http/modules/perl/ngx_http_perl_module.h
+++ b/src/http/modules/perl/ngx_http_perl_module.h
@@ -24,6 +24,9 @@
     ngx_str_t                 filename;
     ngx_str_t                 redirect_uri;
     ngx_str_t                 redirect_args;
+    SV                       *next;
+
+    ngx_uint_t                done;   /* unsigned  done:1; */
 
 #if (NGX_HTTP_SSI)
     ngx_http_ssi_ctx_t       *ssi;
@@ -47,4 +50,7 @@
 extern void  boot_DynaLoader(pTHX_ CV* cv);
 
 
+void ngx_http_perl_handle_request(ngx_http_request_t *r);
+
+
 #endif /* _NGX_HTTP_PERL_MODULE_H_INCLUDED_ */