nginx-0.1.25-RELEASE import

    *) Bugfix: nginx did run on Linux parisc.

    *) Feature: nginx now does not start under FreeBSD if the sysctl
       kern.ipc.somaxconn value is too big.

    *) Bugfix: if a request was internally redirected by the
       ngx_http_index_module module to the ngx_http_proxy_module or
       ngx_http_fastcgi_module modules, then the index file was not closed
       after request completion.

    *) Feature: the "proxy_pass" can be used in location with regular
       expression.

    *) Feature: the ngx_http_rewrite_filter_module module supports the
       condition like "if ($HTTP_USER_AGENT ~ MSIE)".

    *) Bugfix: nginx started too slow if the large number of addresses and
       text values were used in the "geo" directive.

    *) Change: a variable name must be declared as "$name" in the "geo"
       directive. The previous variant without "$" is still supported, but
       will be removed soon.

    *) Feature: the "%{VARIABLE}v" logging parameter.

    *) Feature: the "set $name value" directive.

    *) Bugfix: gcc 4.0 compatibility.

    *) Feature: the --with-openssl-opt=OPTIONS autoconfiguration directive.
diff --git a/src/http/modules/ngx_http_access_handler.c b/src/http/modules/ngx_http_access_module.c
similarity index 85%
rename from src/http/modules/ngx_http_access_handler.c
rename to src/http/modules/ngx_http_access_module.c
index 285570f..685d15d 100644
--- a/src/http/modules/ngx_http_access_handler.c
+++ b/src/http/modules/ngx_http_access_module.c
@@ -25,10 +25,10 @@
 
 static ngx_int_t ngx_http_access_handler(ngx_http_request_t *r);
 static char *ngx_http_access_rule(ngx_conf_t *cf, ngx_command_t *cmd,
-                                  void *conf);
+    void *conf);
 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);
+    void *parent, void *child);
 static ngx_int_t ngx_http_access_init(ngx_cycle_t *cycle);
 
 
@@ -77,7 +77,8 @@
 };
 
 
-static ngx_int_t ngx_http_access_handler(ngx_http_request_t *r)
+static ngx_int_t
+ngx_http_access_handler(ngx_http_request_t *r)
 {
     ngx_uint_t                   i;
     struct sockaddr_in          *sin;
@@ -117,8 +118,8 @@
 }
 
 
-static char *ngx_http_access_rule(ngx_conf_t *cf, ngx_command_t *cmd,
-                                  void *conf)
+static char *
+ngx_http_access_rule(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
 {
     ngx_http_access_loc_conf_t *alcf = conf;
 
@@ -127,14 +128,15 @@
     ngx_http_access_rule_t  *rule;
 
     if (alcf->rules == NULL) {
-        alcf->rules = ngx_create_array(cf->pool, 4,
+        alcf->rules = ngx_array_create(cf->pool, 4,
                                        sizeof(ngx_http_access_rule_t));
         if (alcf->rules == NULL) {
             return NGX_CONF_ERROR;
         }
     }
 
-    if (!(rule = ngx_push_array(alcf->rules))) {
+    rule = ngx_array_push(alcf->rules);
+    if (rule == NULL) {
         return NGX_CONF_ERROR;
     }
 
@@ -170,11 +172,13 @@
 }
 
 
-static void *ngx_http_access_create_loc_conf(ngx_conf_t *cf)
+static void *
+ngx_http_access_create_loc_conf(ngx_conf_t *cf)
 {
     ngx_http_access_loc_conf_t  *conf;
 
-    if (!(conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_access_loc_conf_t)))) {
+    conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_access_loc_conf_t));
+    if (conf == NULL) {
         return NGX_CONF_ERROR;
     }
 
@@ -182,8 +186,8 @@
 }
 
 
-static char *ngx_http_access_merge_loc_conf(ngx_conf_t *cf,
-                                            void *parent, void *child)
+static char *
+ngx_http_access_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
 {
     ngx_http_access_loc_conf_t  *prev = parent;
     ngx_http_access_loc_conf_t  *conf = child;
@@ -196,14 +200,15 @@
 }
 
 
-static ngx_int_t ngx_http_access_init(ngx_cycle_t *cycle)
+static ngx_int_t
+ngx_http_access_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_push_array(&cmcf->phases[NGX_HTTP_ACCESS_PHASE].handlers);
+    h = ngx_array_push(&cmcf->phases[NGX_HTTP_ACCESS_PHASE].handlers);
     if (h == NULL) {
         return NGX_ERROR;
     }
diff --git a/src/http/modules/ngx_http_autoindex_handler.c b/src/http/modules/ngx_http_autoindex_module.c
similarity index 96%
rename from src/http/modules/ngx_http_autoindex_handler.c
rename to src/http/modules/ngx_http_autoindex_module.c
index 8976ad5..a7b9986 100644
--- a/src/http/modules/ngx_http_autoindex_handler.c
+++ b/src/http/modules/ngx_http_autoindex_module.c
@@ -218,10 +218,7 @@
         if (ngx_read_dir(&dir) == NGX_ERROR) {
             err = ngx_errno;
 
-            if (err == NGX_ENOMOREFILES) {
-                rc = NGX_OK;
-
-            } else {
+            if (err != NGX_ENOMOREFILES) {
                 ngx_log_error(NGX_LOG_CRIT, r->connection->log, err,
                               ngx_read_dir_n " \"%s\" failed", dname.data);
                 return ngx_http_autoindex_error(r, &dir, dname.data);
@@ -251,7 +248,8 @@
             if (dname.len + 1 + len > fname.len) {
                 fname.len = dname.len + 1 + len + 32;
 
-                if (!(fname.data = ngx_palloc(pool, fname.len))) {
+                fname.data = ngx_palloc(pool, fname.len);
+                if (fname.data == NULL) {
                     return ngx_http_autoindex_error(r, &dir, dname.data);
                 }
 
@@ -280,7 +278,8 @@
             }
         }
 
-        if (!(entry = ngx_array_push(&entries))) {
+        entry = ngx_array_push(&entries);
+        if (entry == NULL) {
             return ngx_http_autoindex_error(r, &dir, dname.data);
         }
 
@@ -288,7 +287,8 @@
         entry->escape = 2 * ngx_escape_uri(NULL, ngx_de_name(&dir), len,
                                            NGX_ESCAPE_HTML);
 
-        if (!(entry->name.data = ngx_palloc(pool, len + entry->escape + 1))) {
+        entry->name.data = ngx_palloc(pool, len + entry->escape + 1);
+        if (entry->name.data == NULL) {
             return ngx_http_autoindex_error(r, &dir, dname.data);
         }
 
@@ -326,7 +326,8 @@
                + 2;
     }
 
-    if (!(b = ngx_create_temp_buf(r->pool, len))) {
+    b = ngx_create_temp_buf(r->pool, len);
+    if (b == NULL) {
         return NGX_HTTP_INTERNAL_SERVER_ERROR;
     }
 
@@ -481,11 +482,13 @@
         ctx->size += ctx->buf->last - ctx->buf->pos;
     }
 
-    if (!(ctx->buf = ngx_create_temp_buf(ctx->pool, ctx->alloc_size))) {
+    ctx->buf = ngx_create_temp_buf(ctx->pool, ctx->alloc_size);
+    if (ctx->buf == NULL) {
         return NULL;
     }
 
-    if (!(cl = ngx_alloc_chain_link(ctx->pool))) {
+    cl = ngx_alloc_chain_link(ctx->pool);
+    if (cl == NULL) {
         return NULL;
     }
 
diff --git a/src/http/modules/ngx_http_charset_filter.c b/src/http/modules/ngx_http_charset_filter_module.c
similarity index 86%
rename from src/http/modules/ngx_http_charset_filter.c
rename to src/http/modules/ngx_http_charset_filter_module.c
index cbd0fca..dad26ba 100644
--- a/src/http/modules/ngx_http_charset_filter.c
+++ b/src/http/modules/ngx_http_charset_filter_module.c
@@ -48,11 +48,11 @@
 static ngx_uint_t ngx_charset_recode(ngx_buf_t *b, char *table);
 
 static char *ngx_charset_map_block(ngx_conf_t *cf, ngx_command_t *cmd,
-                                   void *conf);
+    void *conf);
 static char *ngx_charset_map(ngx_conf_t *cf, ngx_command_t *dummy, void *conf);
 
 static char *ngx_http_set_charset_slot(ngx_conf_t *cf, ngx_command_t *cmd,
-                                       void *conf);
+    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);
@@ -61,7 +61,7 @@
 static char *ngx_http_charset_init_main_conf(ngx_conf_t *cf, void *conf);
 static void *ngx_http_charset_create_loc_conf(ngx_conf_t *cf);
 static char *ngx_http_charset_merge_loc_conf(ngx_conf_t *cf,
-                                             void *parent, void *child);
+    void *parent, void *child);
 
 
 static ngx_command_t  ngx_http_charset_filter_commands[] = {
@@ -133,7 +133,8 @@
 static ngx_http_output_body_filter_pt    ngx_http_next_body_filter;
 
 
-static ngx_int_t ngx_http_charset_header_filter(ngx_http_request_t *r)
+static ngx_int_t
+ngx_http_charset_header_filter(ngx_http_request_t *r)
 {
     ngx_http_charset_t            *charsets;
     ngx_http_charset_ctx_t        *ctx;
@@ -165,7 +166,7 @@
     }
 
     if (r->headers_out.status == NGX_HTTP_MOVED_PERMANENTLY
-        && r->headers_out.status == NGX_HTTP_MOVED_TEMPORARILY)
+        || r->headers_out.status == NGX_HTTP_MOVED_TEMPORARILY)
     {
         /*
          * do not set charset for the redirect because NN 4.x uses this
@@ -187,8 +188,14 @@
         return ngx_http_next_header_filter(r);
     }
 
-    ngx_http_create_ctx(r, ctx, ngx_http_charset_filter_module,
-                        sizeof(ngx_http_charset_ctx_t), NGX_ERROR);
+
+    ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_charset_ctx_t));
+    if (ctx == NULL) {
+        return NGX_ERROR;
+    }
+
+    ngx_http_set_ctx(r, ctx, ngx_http_charset_filter_module);
+
 
     r->filter_need_in_memory = 1;
 
@@ -196,8 +203,8 @@
 }
 
 
-static ngx_int_t ngx_http_charset_body_filter(ngx_http_request_t *r,
-                                              ngx_chain_t *in)
+static ngx_int_t
+ngx_http_charset_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
 {
     char                          *table;
     ngx_chain_t                   *cl;
@@ -226,7 +233,8 @@
 }
 
 
-static ngx_uint_t ngx_charset_recode(ngx_buf_t *b, char *table)
+static ngx_uint_t
+ngx_charset_recode(ngx_buf_t *b, char *table)
 {
     u_char      *p;
     ngx_uint_t   change;
@@ -254,8 +262,8 @@
 }
 
 
-static char *ngx_charset_map_block(ngx_conf_t *cf, ngx_command_t *cmd,
-                                   void *conf)
+static char *
+ngx_charset_map_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
 {
     ngx_http_charset_main_conf_t  *mcf = conf;
 
@@ -297,18 +305,21 @@
         }
     }
 
-    if (!(table = ngx_push_array(&mcf->tables))) {
+    table = ngx_array_push(&mcf->tables);
+    if (table == NULL) {
         return NGX_CONF_ERROR;
     }
 
     table->src = src;
     table->dst = dst;
 
-    if (!(table->src2dst = ngx_palloc(cf->pool, 256))) {
+    table->src2dst = ngx_palloc(cf->pool, 256);
+    if (table->src2dst == NULL) {
         return NGX_CONF_ERROR;
     }
 
-    if (!(table->dst2src = ngx_palloc(cf->pool, 256))) {
+    table->dst2src = ngx_palloc(cf->pool, 256);
+    if (table->dst2src == NULL) {
         return NGX_CONF_ERROR;
     }
 
@@ -326,14 +337,17 @@
     cf->ctx = table;
     cf->handler = ngx_charset_map;
     cf->handler_conf = conf;
+
     rv = ngx_conf_parse(cf, NULL);
+
     *cf = pvcf;
 
     return rv;
 }
 
 
-static char *ngx_charset_map(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
+static char *
+ngx_charset_map(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
 {
     ngx_int_t                   src, dst;
     ngx_str_t                  *value;
@@ -369,8 +383,8 @@
 }
 
 
-static char *ngx_http_set_charset_slot(ngx_conf_t *cf, ngx_command_t *cmd,
-                                       void *conf)
+static char *
+ngx_http_set_charset_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
 {
     char  *p = conf;
 
@@ -404,7 +418,8 @@
 }
 
 
-static ngx_int_t ngx_http_add_charset(ngx_array_t *charsets, ngx_str_t *name)
+static ngx_int_t
+ngx_http_add_charset(ngx_array_t *charsets, ngx_str_t *name)
 {
     ngx_uint_t           i;
     ngx_http_charset_t  *c;
@@ -424,7 +439,8 @@
         return i;
     }
 
-    if (!(c = ngx_push_array(charsets))) {
+    c = ngx_array_push(charsets);
+    if (c == NULL) {
         return NGX_ERROR;
     }
 
@@ -436,7 +452,8 @@
 }
 
 
-static ngx_int_t ngx_http_charset_filter_init(ngx_cycle_t *cycle)
+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;
@@ -448,25 +465,34 @@
 }
 
 
-static void *ngx_http_charset_create_main_conf(ngx_conf_t *cf)
+static void *
+ngx_http_charset_create_main_conf(ngx_conf_t *cf)
 {
     ngx_http_charset_main_conf_t  *mcf;
 
-    if (!(mcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_charset_main_conf_t)))) {
+    mcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_charset_main_conf_t));
+    if (mcf == NULL) {
         return NGX_CONF_ERROR;
     }
 
-    ngx_init_array(mcf->charsets, cf->pool, 2, sizeof(ngx_http_charset_t),
-                   NGX_CONF_ERROR);
+    if (ngx_array_init(&mcf->charsets, cf->pool, 2, sizeof(ngx_http_charset_t))
+                                                                  == NGX_ERROR)
+    {
+        return NGX_CONF_ERROR;
+    }
 
-    ngx_init_array(mcf->tables, cf->pool, 4, sizeof(ngx_http_charset_tables_t),
-                   NGX_CONF_ERROR);
+    if (ngx_array_init(&mcf->tables, cf->pool, 4,
+                       sizeof(ngx_http_charset_tables_t)) == NGX_ERROR)
+    {
+        return NGX_CONF_ERROR;
+    }
 
     return mcf;
 }
 
 
-static char *ngx_http_charset_init_main_conf(ngx_conf_t *cf, void *conf)
+static char *
+ngx_http_charset_init_main_conf(ngx_conf_t *cf, void *conf)
 {
     ngx_http_charset_main_conf_t *mcf = conf;
 
@@ -484,7 +510,6 @@
 
         charset[i].tables = ngx_pcalloc(cf->pool,
                                         sizeof(char *) * mcf->charsets.nelts);
-
         if (charset[i].tables == NULL) {
             return NGX_CONF_ERROR;
         }
@@ -527,11 +552,13 @@
 }
 
 
-static void *ngx_http_charset_create_loc_conf(ngx_conf_t *cf)
+static void *
+ngx_http_charset_create_loc_conf(ngx_conf_t *cf)
 {
     ngx_http_charset_loc_conf_t  *lcf;
 
-    if (!(lcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_charset_loc_conf_t)))) {
+    lcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_charset_loc_conf_t));
+    if (lcf == NULL) {
         return NGX_CONF_ERROR;
     }
 
@@ -544,8 +571,8 @@
 }
 
 
-static char *ngx_http_charset_merge_loc_conf(ngx_conf_t *cf,
-                                             void *parent, void *child)
+static char *
+ngx_http_charset_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
 {
     ngx_http_charset_loc_conf_t *prev = parent;
     ngx_http_charset_loc_conf_t *conf = child;
diff --git a/src/http/modules/ngx_http_chunked_filter.c b/src/http/modules/ngx_http_chunked_filter_module.c
similarity index 87%
rename from src/http/modules/ngx_http_chunked_filter.c
rename to src/http/modules/ngx_http_chunked_filter_module.c
index 5145ff6..b742dbb 100644
--- a/src/http/modules/ngx_http_chunked_filter.c
+++ b/src/http/modules/ngx_http_chunked_filter_module.c
@@ -40,7 +40,8 @@
 static ngx_http_output_body_filter_pt    ngx_http_next_body_filter;
 
 
-static ngx_int_t ngx_http_chunked_header_filter(ngx_http_request_t *r)
+static ngx_int_t
+ngx_http_chunked_header_filter(ngx_http_request_t *r)
 {
     if (r->headers_out.status == NGX_HTTP_NOT_MODIFIED) {
         return ngx_http_next_header_filter(r);
@@ -59,8 +60,8 @@
 }
 
 
-static ngx_int_t ngx_http_chunked_body_filter(ngx_http_request_t *r,
-                                              ngx_chain_t *in)
+static ngx_int_t
+ngx_http_chunked_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
 {
     u_char       *chunk;
     off_t         size;
@@ -85,7 +86,8 @@
 
         if (cl->buf->flush || ngx_buf_in_memory(cl->buf) || cl->buf->in_file) {
 
-            if (!(tl = ngx_alloc_chain_link(r->pool))) {
+            tl = ngx_alloc_chain_link(r->pool);
+            if (tl == NULL) {
                 return NGX_ERROR;
             }
 
@@ -102,10 +104,13 @@
     }
 
     if (size) {
-        if (!(b = ngx_calloc_buf(r->pool))) {
+        b = ngx_calloc_buf(r->pool);
+        if (b == NULL) {
             return NGX_ERROR;
         }
 
+        /* the "0000000000000000" is 64-bit hexadimal string */
+
         chunk = ngx_palloc(r->pool, sizeof("0000000000000000" CRLF) - 1);
         if (chunk == NULL) {
             return NGX_ERROR;
@@ -119,7 +124,8 @@
     }
 
     if (cl->buf->last_buf) {
-        if (!(b = ngx_calloc_buf(r->pool))) {
+        b = ngx_calloc_buf(r->pool);
+        if (b == NULL) {
             return NGX_ERROR;
         }
 
@@ -144,7 +150,8 @@
             return ngx_http_next_body_filter(r, out.next);
         }
 
-        if (!(b = ngx_calloc_buf(r->pool))) {
+        b = ngx_calloc_buf(r->pool);
+        if (b == NULL) {
             return NGX_ERROR;
         }
 
@@ -161,7 +168,8 @@
 }
 
 
-static ngx_int_t ngx_http_chunked_filter_init(ngx_cycle_t *cycle)
+static ngx_int_t
+ngx_http_chunked_filter_init(ngx_cycle_t *cycle)
 {
     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_fastcgi_handler.c b/src/http/modules/ngx_http_fastcgi_module.c
similarity index 96%
rename from src/http/modules/ngx_http_fastcgi_handler.c
rename to src/http/modules/ngx_http_fastcgi_module.c
index 5b384b8..a5f9a02 100644
--- a/src/http/modules/ngx_http_fastcgi_handler.c
+++ b/src/http/modules/ngx_http_fastcgi_module.c
@@ -377,7 +377,8 @@
 
     flcf = ngx_http_get_module_loc_conf(r, ngx_http_fastcgi_module);
 
-    if (!(u = ngx_pcalloc(r->pool, sizeof(ngx_http_upstream_t)))) {
+    u = ngx_pcalloc(r->pool, sizeof(ngx_http_upstream_t));
+    if (u == NULL) {
         return NGX_HTTP_INTERNAL_SERVER_ERROR;
     }
 
@@ -492,25 +493,24 @@
     index = (r->uri.data[r->uri.len - 1] == '/') ? flcf->index.len : 0;
 
     len += 1 + ((flcf->root.len + r->uri.len + index > 127) ? 4 : 1)
-             + sizeof("PATH_TRANSLATED") - 1
-             + flcf->root.len + r->uri.len + index;
+        + sizeof("PATH_TRANSLATED") - 1 + flcf->root.len + r->uri.len + index;
 
     if (r->args.len) {
         len += 1 + ((r->args.len > 127) ? 4 : 1) + sizeof("QUERY_STRING") - 1
-                                                 + r->args.len;
+            + r->args.len;
     }
 
     if (r->headers_in.content_length_n > 0) {
         len += 1 + ((r->headers_in.content_length->value.len > 127) ? 4 : 1)
-                 + sizeof("CONTENT_LENGTH") - 1
-                 + r->headers_in.content_length->value.len;
+            + sizeof("CONTENT_LENGTH") - 1
+            + r->headers_in.content_length->value.len;
     }
 
 
     if (r->headers_in.content_type) {
         len += 1 + ((r->headers_in.content_type->value.len > 127) ? 4 : 1)
-                 + sizeof("CONTENT_TYPE") - 1
-                 + r->headers_in.content_type->value.len;
+            + sizeof("CONTENT_TYPE") - 1
+            + r->headers_in.content_type->value.len;
     }
 
 
@@ -520,24 +520,24 @@
 
     if (flcf->params & NGX_HTTP_FASTCGI_REQUEST_URI) {
         len += 1 + ((r->unparsed_uri.len > 127) ? 4 : 1)
-                 + sizeof("REQUEST_URI") - 1 + r->unparsed_uri.len;
+            + sizeof("REQUEST_URI") - 1 + r->unparsed_uri.len;
     }
 
     if (flcf->params & NGX_HTTP_FASTCGI_DOCUMENT_ROOT) {
         clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
         len += 1 + ((clcf->root.len > 127) ? 4 : 1)
-                 + sizeof("DOCUMENT_ROOT") - 1 + clcf->root.len;
+            + sizeof("DOCUMENT_ROOT") - 1 + clcf->root.len;
     }
 
     if (flcf->params & NGX_HTTP_FASTCGI_SCRIPT_FILENAME) {
         len += 1 + ((flcf->root.len + r->uri.len + index > 127) ? 4 : 1)
-                 + sizeof("SCRIPT_FILENAME") - 1
-                 + flcf->root.len + r->uri.len + index;
+            + sizeof("SCRIPT_FILENAME") - 1
+            + flcf->root.len + r->uri.len + index;
     }
 
     if (flcf->params & NGX_HTTP_FASTCGI_SCRIPT_NAME) {
         len += 1 + ((r->uri.len + index > 127) ? 4 : 1)
-                 + sizeof("SCRIPT_NAME") - 1 + r->uri.len + index ;
+            + sizeof("SCRIPT_NAME") - 1 + r->uri.len + index ;
     }
 
     if (flcf->params & NGX_HTTP_FASTCGI_REMOTE_ADDR) {
@@ -579,7 +579,7 @@
         && r->http_protocol.len)
     {
         len += 1 + ((r->http_protocol.len > 127) ? 4 : 1)
-                 + sizeof("SERVER_PROTOCOL") - 1 + r->http_protocol.len;
+            + sizeof("SERVER_PROTOCOL") - 1 + r->http_protocol.len;
     }
 
     if (flcf->params & NGX_HTTP_FASTCGI_SERVER_SOFTWARE) {
@@ -599,7 +599,8 @@
 
         for (i = 0; i < flcf->vars->nelts; i++) {
 
-            if (!(value = ngx_http_get_indexed_variable(r, vindex[i]))) {
+            value = ngx_http_get_indexed_variable(r, vindex[i]);
+            if (value == NULL) {
                 continue;
             }
 
@@ -626,8 +627,8 @@
         }
 
         len += ((header[i].key.len > 127) ? 4 : 1)
-               + ((header[i].value.len > 127) ? 4 : 1)
-               + 5 + header[i].key.len + header[i].value.len;
+            + ((header[i].value.len > 127) ? 4 : 1)
+            + 5 + header[i].key.len + header[i].value.len;
     }
 
 
@@ -652,11 +653,13 @@
            + sizeof(ngx_http_fastcgi_header_t); /* NGX_HTTP_FASTCGI_STDIN */
 
 
-    if (!(b = ngx_create_temp_buf(r->pool, size))) {
+    b = ngx_create_temp_buf(r->pool, size);
+    if (b == NULL) {
         return NGX_ERROR;
     }
 
-    if (!(cl = ngx_alloc_chain_link(r->pool))) {
+    cl = ngx_alloc_chain_link(r->pool);
+    if (cl == NULL) {
         return NGX_ERROR;
     }
 
@@ -998,7 +1001,8 @@
     if (flcf->vars) {
         for (i = 0; i < flcf->vars->nelts; i++) {
 
-            if (!(value = ngx_http_get_indexed_variable(r, vindex[i]))) {
+            value = ngx_http_get_indexed_variable(r, vindex[i]);
+            if (value == NULL) {
                 continue;
             }
 
@@ -1115,7 +1119,8 @@
         next = 0;
 
         do {
-            if (!(b = ngx_alloc_buf(r->pool))) {
+            b = ngx_alloc_buf(r->pool);
+            if (b == NULL) {
                 return NGX_ERROR;
             }
 
@@ -1158,7 +1163,8 @@
             h->padding_length = (u_char) padding;
             h->reserved = 0;
 
-            if (!(cl->next = ngx_alloc_chain_link(r->pool))) {
+            cl->next = ngx_alloc_chain_link(r->pool);
+            if (cl->next == NULL) {
                 return NGX_ERROR;
             }
 
@@ -1179,7 +1185,8 @@
             h = (ngx_http_fastcgi_header_t *) b->last;
             b->last += sizeof(ngx_http_fastcgi_header_t);
 
-            if (!(cl->next = ngx_alloc_chain_link(r->pool))) {
+            cl->next = ngx_alloc_chain_link(r->pool);
+            if (cl->next == NULL) {
                 return NGX_ERROR;
             }
 
@@ -1248,7 +1255,8 @@
     f = ngx_http_get_module_ctx(r, ngx_http_fastcgi_module);
 
     if (f == NULL) {
-        if (!(f = ngx_pcalloc(r->pool, sizeof(ngx_http_fastcgi_ctx_t)))) {
+        f = ngx_pcalloc(r->pool, sizeof(ngx_http_fastcgi_ctx_t));
+        if (f == NULL) {
             return NGX_HTTP_INTERNAL_SERVER_ERROR;
         }
 
@@ -1413,7 +1421,8 @@
 
                 /* a header line has been parsed successfully */
 
-                if (!(h = ngx_list_push(&f->upstream->headers_in.headers))) {
+                h = ngx_list_push(&f->upstream->headers_in.headers);
+                if (h == NULL) {
                     return NGX_HTTP_INTERNAL_SERVER_ERROR;
                 }
 
@@ -1580,7 +1589,8 @@
 
         /* copy some header pointers and set up r->headers_out */
 
-        if (!(ho = ngx_list_push(&r->headers_out.headers))) {
+        ho = ngx_list_push(&r->headers_out.headers);
+        if (ho == NULL) {
             return NGX_HTTP_INTERNAL_SERVER_ERROR;
         }
 
@@ -1733,7 +1743,8 @@
             p->free = p->free->next;
 
         } else {
-            if (!(b = ngx_alloc_buf(p->pool))) {
+            b = ngx_alloc_buf(p->pool);
+            if (b == NULL) {
                 return NGX_ERROR;
             }
         }
@@ -1750,18 +1761,26 @@
         *prev = b;
         prev = &b->shadow;
 
-        if (!(cl = ngx_alloc_chain_link(p->pool))) {
+        cl = ngx_alloc_chain_link(p->pool);
+        if (cl == NULL) {
             return NGX_ERROR;
         }
 
         cl->buf = b;
         cl->next = NULL;
 
+        if (p->in) {
+            *p->last_in = cl;
+        } else {
+            p->in = cl;
+        }
+        p->last_in = &cl->next;
+
+
         /* STUB */ b->num = buf->num;
 
         ngx_log_debug1(NGX_LOG_DEBUG_EVENT, p->log, 0, "input buf #%d", b->num);
 
-        ngx_chain_add_link(p->in, p->last_in, cl);
 
         if (f->pos + f->length < f->last) {
 
@@ -1820,11 +1839,8 @@
     ngx_http_fastcgi_ctx_t *f)
 {
     u_char                     ch, *p;
-    ngx_http_upstream_t       *u;
     ngx_http_fastcgi_state_e   state;
 
-    u = r->upstream;
-
     state = f->state;
 
     for (p = f->pos; p < f->last; p++) {
@@ -1968,7 +1984,8 @@
         unix_upstream.name = value[1];
         unix_upstream.url = value[1];
 
-        if (!(lcf->peers = ngx_unix_upstream_parse(cf, &unix_upstream))) {
+        lcf->peers = ngx_unix_upstream_parse(cf, &unix_upstream);
+        if (lcf->peers == NULL) {
             return NGX_CONF_ERROR;
         }
 
@@ -1986,7 +2003,8 @@
         inet_upstream.name = value[1];
         inet_upstream.url = value[1];
     
-        if (!(lcf->peers = ngx_inet_upstream_parse(cf, &inet_upstream))) {
+        lcf->peers = ngx_inet_upstream_parse(cf, &inet_upstream);
+        if (lcf->peers == NULL) {
             return NGX_CONF_ERROR;
         }
     }
@@ -1996,7 +2014,7 @@
     clcf->handler = ngx_http_fastcgi_handler;
 
 #if (NGX_PCRE)
-    lcf->location = clcf->regex ? &ngx_http_fastcgi_uri: &clcf->name;
+    lcf->location = clcf->regex ? &ngx_http_fastcgi_uri : &clcf->name;
 #else
     lcf->location = &clcf->name;
 #endif
@@ -2035,7 +2053,8 @@
     for (i = 0; i < cmcf->variables.nelts; i++) {
         if (ngx_strcasecmp(var[i].name.data, value[1].data) == 0) {
 
-            if (!(index = ngx_array_push(lcf->vars))) {
+            index = ngx_array_push(lcf->vars);
+            if (index == NULL) {
                 return NGX_CONF_ERROR;
             }
 
@@ -2084,7 +2103,8 @@
 {
     ngx_http_fastcgi_loc_conf_t  *conf;
 
-    if (!(conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_fastcgi_loc_conf_t)))) {
+    conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_fastcgi_loc_conf_t));
+    if (conf == NULL) {
         return NGX_CONF_ERROR;
     }
 
diff --git a/src/http/modules/ngx_http_geo_module.c b/src/http/modules/ngx_http_geo_module.c
index 0d8267d..865f825 100644
--- a/src/http/modules/ngx_http_geo_module.c
+++ b/src/http/modules/ngx_http_geo_module.c
@@ -64,9 +64,9 @@
 /* AF_INET only */
 
 static ngx_http_variable_value_t *
-ngx_http_geo_variable(ngx_http_request_t *r, void *data)
+ngx_http_geo_variable(ngx_http_request_t *r, uintptr_t data)
 {
-    ngx_radix_tree_t *tree = data;
+    ngx_radix_tree_t *tree = (ngx_radix_tree_t *) data;
 
     struct sockaddr_in         *sin;
     ngx_http_variable_value_t  *var;
@@ -90,33 +90,46 @@
 ngx_http_geo_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
 {
     char                 *rv;
-    ngx_str_t            *value;
+    ngx_str_t            *value, name;
     ngx_conf_t            save;
     ngx_pool_t           *pool;
     ngx_radix_tree_t     *tree;
     ngx_http_geo_conf_t   geo;
     ngx_http_variable_t  *var;
 
-    if (!(var = ngx_http_add_variable(cf))) {
-        return NGX_CONF_ERROR;
-    }
-
-    if (!(tree = ngx_radix_tree_create(cf->pool, -1))) {
-        return NGX_CONF_ERROR;
-    }
-
     value = cf->args->elts;
 
-    var->name = value[1];
+    name = value[1];
+
+    if (name.data[0] != '$') {
+        ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
+                           "\"%V\" variable name should start with '$'",
+                           &value[1]);
+    } else {
+        name.len--;
+        name.data++;
+    }
+
+    var = ngx_http_add_variable(cf, &name, 1);
+    if (var == NULL) {
+        return NGX_CONF_ERROR;
+    }
+
+    tree = ngx_radix_tree_create(cf->pool, -1);
+    if (tree == NULL) {
+        return NGX_CONF_ERROR;
+    }
+
     var->handler = ngx_http_geo_variable;
-    var->data = tree;
+    var->data = (uintptr_t) tree;
 
     /*
      * create the temporary pool of a huge initial size
      * to process quickly a large number of geo lines
      */
 
-    if (!(pool = ngx_create_pool(512 * 1024, cf->log))) {
+    pool = ngx_create_pool(512 * 1024, cf->log);
+    if (pool == NULL) {
         return NGX_CONF_ERROR;
     }
 
@@ -212,7 +225,12 @@
 
     if (n == NGX_ERROR) {
         for (i = 0; i < geo->values.nelts; i++) {
-            if (ngx_strcmp(value[1].data, v[i]->text.data) == 0) {
+            if (v[i]->text.len != value[1].len) {
+                continue;
+            }
+
+            if (ngx_strncmp(value[1].data, v[i]->text.data, value[1].len) == 0)
+            {
                 var = v[i];
                 break;
             }
@@ -227,20 +245,22 @@
         }
     }
 
-    if (i == geo->values.nelts) {
+    if (var == NULL) {
         var = ngx_palloc(geo->pool, sizeof(ngx_http_variable_value_t));
         if (var == NULL) {
             return NGX_CONF_ERROR;
         }
 
         var->text.len = value[1].len;
-        if (!(var->text.data = ngx_pstrdup(geo->pool, &value[1]))) {
+        var->text.data = ngx_pstrdup(geo->pool, &value[1]);
+        if (var->text.data == NULL) {
             return NGX_CONF_ERROR;
         }
 
         var->value = (n == NGX_ERROR) ? 0 : n;
 
-        if (!(v = ngx_array_push(&geo->values))) {
+        v = ngx_array_push(&geo->values);
+        if (v == NULL) {
             return NGX_CONF_ERROR;
         }
 
diff --git a/src/http/modules/ngx_http_gzip_filter.c b/src/http/modules/ngx_http_gzip_filter_module.c
similarity index 94%
rename from src/http/modules/ngx_http_gzip_filter.c
rename to src/http/modules/ngx_http_gzip_filter_module.c
index eec6a13..4a4da7f 100644
--- a/src/http/modules/ngx_http_gzip_filter.c
+++ b/src/http/modules/ngx_http_gzip_filter_module.c
@@ -331,9 +331,14 @@
         return ngx_http_next_header_filter(r);
     }
 
+    ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_gzip_ctx_t));
+    if (ctx == NULL) {
+        return NGX_ERROR;
+    }
 
-    ngx_http_create_ctx(r, ctx, ngx_http_gzip_filter_module,
-                        sizeof(ngx_http_gzip_ctx_t), NGX_ERROR);
+    ngx_http_set_ctx(r, ctx, ngx_http_gzip_filter_module);
+
+
     ctx->request = r;
 
     r->headers_out.content_encoding = ngx_list_push(&r->headers_out.headers);
@@ -445,7 +450,7 @@
     ngx_int_t              last;
     struct gztrailer      *trailer;
     ngx_buf_t             *b;
-    ngx_chain_t           *cl;
+    ngx_chain_t           *cl, out;
     ngx_http_gzip_ctx_t   *ctx;
     ngx_http_gzip_conf_t  *conf;
 
@@ -485,7 +490,8 @@
 
         ctx->allocated = 8192 + (1 << (wbits + 2)) + (1 << (memlevel + 9));
 
-        if (!(ctx->preallocated = ngx_palloc(r->pool, ctx->allocated))) {
+        ctx->preallocated = ngx_palloc(r->pool, ctx->allocated);
+        if (ctx->preallocated == NULL) {
             return NGX_ERROR;
         }
 
@@ -505,7 +511,8 @@
             return NGX_ERROR;
         }
 
-        if (!(b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t)))) {
+        b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t));
+        if (b == NULL) {
             ngx_http_gzip_error(ctx);
             return NGX_ERROR;
         }
@@ -514,12 +521,8 @@
         b->pos = gzheader;
         b->last = b->pos + 10;
 
-        if (!(cl = ngx_alloc_chain_link(r->pool))) {
-            ngx_http_gzip_error(ctx);
-            return NGX_ERROR;
-        }
-        cl->buf = b;
-        cl->next = NULL;
+        out.buf = b;
+        out.next = NULL;
 
         /*
          * We pass the gzheader to the next filter now to avoid its linking
@@ -528,7 +531,7 @@
          * to the ctx->busy chain would be flushed by ngx_http_write_filter().
          */
 
-        if (ngx_http_next_body_filter(r, cl) == NGX_ERROR) {
+        if (ngx_http_next_body_filter(r, &out) == NGX_ERROR) {
             ngx_http_gzip_error(ctx);
             return NGX_ERROR;
         }
@@ -673,10 +676,12 @@
 
                 /* zlib wants to output some more gzipped data */
 
-                if (!(cl = ngx_alloc_chain_link(r->pool))) {
+                cl = ngx_alloc_chain_link(r->pool);
+                if (cl == NULL) {
                     ngx_http_gzip_error(ctx);
                     return NGX_ERROR;
                 }
+
                 cl->buf = ctx->out_buf;
                 cl->next = NULL;
                 *ctx->last_out = cl;
@@ -694,10 +699,12 @@
                 ctx->out_buf->flush = 0;
                 ctx->flush = Z_NO_FLUSH;
 
-                if (!(cl = ngx_alloc_chain_link(r->pool))) {
+                cl = ngx_alloc_chain_link(r->pool);
+                if (cl == NULL) {
                     ngx_http_gzip_error(ctx);
                     return NGX_ERROR;
                 }
+
                 cl->buf = ctx->out_buf;
                 cl->next = NULL;
                 *ctx->last_out = cl;
@@ -722,10 +729,12 @@
 
                 ngx_pfree(r->pool, ctx->preallocated);
 
-                if (!(cl = ngx_alloc_chain_link(r->pool))) {
+                cl = ngx_alloc_chain_link(r->pool);
+                if (cl == NULL) {
                     ngx_http_gzip_error(ctx);
                     return NGX_ERROR;
                 }
+
                 cl->buf = ctx->out_buf;
                 cl->next = NULL;
                 *ctx->last_out = cl;
@@ -737,17 +746,20 @@
                     ctx->out_buf->last_buf = 1;
 
                 } else {
-                    if (!(b = ngx_create_temp_buf(r->pool, 8))) {
+                    b = ngx_create_temp_buf(r->pool, 8);
+                    if (b == NULL) {
                         ngx_http_gzip_error(ctx);
                         return NGX_ERROR;
                     }
 
                     b->last_buf = 1;
 
-                    if (!(cl = ngx_alloc_chain_link(r->pool))) {
+                    cl = ngx_alloc_chain_link(r->pool);
+                    if (cl == NULL) {
                         ngx_http_gzip_error(ctx);
                         return NGX_ERROR;
                     }
+
                     cl->buf = b;
                     cl->next = NULL;
                     *ctx->last_out = cl;
@@ -782,10 +794,13 @@
             }
 
             if (conf->no_buffer && ctx->in == NULL) {
-                if (!(cl = ngx_alloc_chain_link(r->pool))) {
+
+                cl = ngx_alloc_chain_link(r->pool);
+                if (cl == NULL) {
                     ngx_http_gzip_error(ctx);
                     return NGX_ERROR;
                 }
+
                 cl->buf = ctx->out_buf;
                 cl->next = NULL;
                 *ctx->last_out = cl;
@@ -816,7 +831,7 @@
         }
 
         ngx_chain_update_chains(&ctx->free, &ctx->busy, &ctx->out,
-                                 (ngx_buf_tag_t) &ngx_http_gzip_filter_module);
+                                (ngx_buf_tag_t) &ngx_http_gzip_filter_module);
         ctx->last_out = &ctx->out;
 
         if (ctx->done) {
@@ -969,7 +984,8 @@
 {
     ngx_http_gzip_conf_t  *conf;
 
-    if (!(conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_gzip_conf_t)))) {
+    conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_gzip_conf_t));
+    if (conf == NULL) {
         return NGX_CONF_ERROR;
     }
 
@@ -1027,7 +1043,8 @@
                 return NGX_CONF_ERROR;
             }
 
-            if (!(type = ngx_array_push(conf->types))) {
+            type = ngx_array_push(conf->types);
+            if (type == NULL) {
                 return NGX_CONF_ERROR;
             }
 
@@ -1055,12 +1072,13 @@
 
     if (gcf->types == NULL) {
         gcf->types = ngx_array_create(cf->pool, 4,
-                                       sizeof(ngx_http_gzip_type_t));
+                                      sizeof(ngx_http_gzip_type_t));
         if (gcf->types == NULL) {
             return NGX_CONF_ERROR;
         }
 
-        if (!(type = ngx_array_push(gcf->types))) {
+        type = ngx_array_push(gcf->types);
+        if (type == NULL) {
             return NGX_CONF_ERROR;
         }
 
@@ -1077,13 +1095,15 @@
             continue;
         }
 
-        if (!(type = ngx_array_push(gcf->types))) {
+        type = ngx_array_push(gcf->types);
+        if (type == NULL) {
             return NGX_CONF_ERROR;
         }
 
         type->name.len = value[i].len;
 
-        if (!(type->name.data = ngx_palloc(cf->pool, type->name.len + 1))) {
+        type->name.data = ngx_palloc(cf->pool, type->name.len + 1);
+        if (type->name.data == NULL) {
             return NGX_CONF_ERROR;
         }
 
diff --git a/src/http/modules/ngx_http_headers_filter.c b/src/http/modules/ngx_http_headers_filter_module.c
similarity index 88%
rename from src/http/modules/ngx_http_headers_filter.c
rename to src/http/modules/ngx_http_headers_filter_module.c
index 39b3583..793cefd 100644
--- a/src/http/modules/ngx_http_headers_filter.c
+++ b/src/http/modules/ngx_http_headers_filter_module.c
@@ -23,7 +23,8 @@
 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);
-char *ngx_http_headers_expires(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
+static char *ngx_http_headers_expires(ngx_conf_t *cf, ngx_command_t *cmd,
+    void *conf);
 
 
 static ngx_command_t  ngx_http_headers_filter_commands[] = {
@@ -66,7 +67,8 @@
 static ngx_http_output_header_filter_pt  ngx_http_next_header_filter;
 
 
-static ngx_int_t ngx_http_headers_filter(ngx_http_request_t *r)
+static ngx_int_t
+ngx_http_headers_filter(ngx_http_request_t *r)
 {
     size_t                    len;
     ngx_table_elt_t          *expires, *cc;
@@ -80,13 +82,15 @@
 
     if (conf->expires != NGX_HTTP_EXPIRES_OFF) {
 
-        if (!(expires = ngx_list_push(&r->headers_out.headers))) {
+        expires = ngx_list_push(&r->headers_out.headers);
+        if (expires == NULL) {
             return NGX_ERROR;
         }
 
         r->headers_out.expires = expires;
 
-        if (!(cc = ngx_list_push(&r->headers_out.headers))) {
+        cc = ngx_list_push(&r->headers_out.headers);
+        if (cc == NULL) {
             return NGX_ERROR;
         }
 
@@ -147,7 +151,8 @@
 }
 
 
-static ngx_int_t ngx_http_headers_filter_init(ngx_cycle_t *cycle)
+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;
@@ -156,11 +161,13 @@
 }
 
 
-static void *ngx_http_headers_create_conf(ngx_conf_t *cf)
+static void *
+ngx_http_headers_create_conf(ngx_conf_t *cf)
 {   
     ngx_http_headers_conf_t  *conf;
 
-    if (!(conf = ngx_palloc(cf->pool, sizeof(ngx_http_headers_conf_t)))) {
+    conf = ngx_palloc(cf->pool, sizeof(ngx_http_headers_conf_t));
+    if (conf == NULL) {
         return NGX_CONF_ERROR;
     }
 
@@ -170,8 +177,8 @@
 }
 
 
-static char *ngx_http_headers_merge_conf(ngx_conf_t *cf,
-                                         void *parent, void *child)
+static char *
+ngx_http_headers_merge_conf(ngx_conf_t *cf, void *parent, void *child)
 {
     ngx_http_headers_conf_t *prev = parent;
     ngx_http_headers_conf_t *conf = child;
@@ -185,7 +192,8 @@
 }
 
 
-char *ngx_http_headers_expires(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
+static char *
+ngx_http_headers_expires(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
 {
     ngx_http_headers_conf_t *hcf = conf;
 
@@ -223,6 +231,7 @@
     }
 
     hcf->expires = ngx_parse_time(&value[1], 1);
+
     if (hcf->expires == NGX_ERROR) {
         return "invalid value";
     }
diff --git a/src/http/modules/ngx_http_index_handler.c b/src/http/modules/ngx_http_index_module.c
similarity index 92%
rename from src/http/modules/ngx_http_index_handler.c
rename to src/http/modules/ngx_http_index_module.c
index 4e37557..373c315 100644
--- a/src/http/modules/ngx_http_index_handler.c
+++ b/src/http/modules/ngx_http_index_module.c
@@ -93,10 +93,10 @@
 /*
  * Try to open the first index file before the test of the directory existence
  * because the valid requests should be many more than invalid ones.
- * If open() failed then stat() should be more quickly because some data
+ * If open() would fail, then stat() should be more quickly because some data
  * is already cached in the kernel.
- * Besides Win32 has ERROR_PATH_NOT_FOUND (NGX_ENOTDIR).
- * Unix has ENOTDIR error, although it less helpfull - it shows only
+ * Besides, Win32 has ERROR_PATH_NOT_FOUND (NGX_ENOTDIR).
+ * Unix has ENOTDIR error, although it less helpfull - it points only
  * that path contains the usual file in place of the directory.
  */
 
@@ -137,9 +137,13 @@
 
     ctx = ngx_http_get_module_ctx(r, ngx_http_index_module);
     if (ctx == NULL) {
-        ngx_http_create_ctx(r, ctx, ngx_http_index_module,
-                            sizeof(ngx_http_index_ctx_t),
-                            NGX_HTTP_INTERNAL_SERVER_ERROR);
+
+        ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_index_ctx_t));
+        if (ctx == NULL) {
+            return NGX_HTTP_INTERNAL_SERVER_ERROR;
+        }
+
+        ngx_http_set_ctx(r, ctx, ngx_http_index_module);
 
 #if (NGX_HTTP_CACHE)
 
@@ -417,7 +421,7 @@
 
     cmcf = ngx_http_cycle_get_module_main_conf(cycle, ngx_http_core_module);
 
-    h = ngx_push_array(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers);
+    h = ngx_array_push(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers);
     if (h == NULL) {
         return NGX_ERROR;
     }
@@ -432,11 +436,17 @@
 {
     ngx_http_index_loc_conf_t  *conf;
 
-    ngx_test_null(conf, ngx_palloc(cf->pool, sizeof(ngx_http_index_loc_conf_t)),
-                  NGX_CONF_ERROR);
+    conf = ngx_palloc(cf->pool, sizeof(ngx_http_index_loc_conf_t));
+    if (conf == NULL) {
+        return NGX_CONF_ERROR;
+    }
 
-    ngx_init_array(conf->indices, cf->pool, 3, sizeof(ngx_str_t),
-                   NGX_CONF_ERROR);
+    if (ngx_array_init(&conf->indices, cf->pool, 2, sizeof(ngx_str_t))
+                                                                  == NGX_ERROR)
+    {
+        return NGX_CONF_ERROR;
+    }
+
     conf->max_index_len = 0;
 
     conf->index_cache = NULL;
@@ -461,7 +471,11 @@
             return NGX_CONF_OK;
         }
 
-        ngx_test_null(index, ngx_push_array(&conf->indices), NGX_CONF_ERROR);
+        index = ngx_array_push(&conf->indices);
+        if (index == NULL) {
+            return NGX_CONF_ERROR;
+        }
+
         index->len = sizeof(NGX_HTTP_DEFAULT_INDEX) - 1;
         index->data = (u_char *) NGX_HTTP_DEFAULT_INDEX;
         conf->max_index_len = sizeof(NGX_HTTP_DEFAULT_INDEX);
@@ -475,8 +489,11 @@
 
         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 = ngx_array_push(&conf->indices);
+            if (index == NULL) {
+                return NGX_CONF_ERROR;
+            }
+
             index->len = prev_index[i].len;
             index->data = prev_index[i].data;
         }
@@ -524,7 +541,11 @@
             return NGX_CONF_ERROR;
         }
 
-        ngx_test_null(index, ngx_push_array(&ilcf->indices), NGX_CONF_ERROR);
+        index = ngx_array_push(&ilcf->indices);
+        if (index == NULL) {
+            return NGX_CONF_ERROR;
+        }
+
         index->len = value[i].len;
         index->data = value[i].data;
 
diff --git a/src/http/modules/ngx_http_not_modified_filter.c b/src/http/modules/ngx_http_not_modified_filter_module.c
similarity index 100%
rename from src/http/modules/ngx_http_not_modified_filter.c
rename to src/http/modules/ngx_http_not_modified_filter_module.c
diff --git a/src/http/modules/ngx_http_range_filter.c b/src/http/modules/ngx_http_range_filter_module.c
similarity index 91%
rename from src/http/modules/ngx_http_range_filter.c
rename to src/http/modules/ngx_http_range_filter_module.c
index 03f2745..84381c9 100644
--- a/src/http/modules/ngx_http_range_filter.c
+++ b/src/http/modules/ngx_http_range_filter_module.c
@@ -186,7 +186,8 @@
             while (*p == ' ') { p++; }
 
             if (*p == ',' || *p == '\0') {
-                if (!(range = ngx_array_push(&r->headers_out.ranges))) {
+                range = ngx_array_push(&r->headers_out.ranges);
+                if (range == NULL) {
                     return NGX_ERROR;
                 }
 
@@ -231,7 +232,8 @@
             break;
         }
 
-        if (!(range = ngx_array_push(&r->headers_out.ranges))) {
+        range = ngx_array_push(&r->headers_out.ranges);
+        if (range == NULL) {
             return NGX_ERROR;
         }
 
@@ -260,7 +262,8 @@
         r->headers_out.status = rc;
         r->headers_out.ranges.nelts = 0;
 
-        if (!(content_range = ngx_list_push(&r->headers_out.headers))) {
+        content_range = ngx_list_push(&r->headers_out.headers);
+        if (content_range == NULL) {
             return NGX_ERROR;
         }
 
@@ -269,9 +272,8 @@
         content_range->key.len = sizeof("Content-Range") - 1;
         content_range->key.data = (u_char *) "Content-Range";
 
-        content_range->value.data =
-                   ngx_palloc(r->pool, sizeof("bytes */") - 1 + NGX_OFF_T_LEN);
-
+        content_range->value.data = ngx_palloc(r->pool,
+                                       sizeof("bytes */") - 1 + NGX_OFF_T_LEN);
         if (content_range->value.data == NULL) {
             return NGX_ERROR;
         }
@@ -294,7 +296,8 @@
 
     if (r->headers_out.ranges.nelts == 1) {
 
-        if (!(content_range = ngx_list_push(&r->headers_out.headers))) {
+        content_range = ngx_list_push(&r->headers_out.headers);
+        if (content_range == NULL) {
             return NGX_ERROR;
         }
 
@@ -325,8 +328,12 @@
 
     /* TODO: what if no content_type ?? */
 
-    ngx_http_create_ctx(r, ctx, ngx_http_range_body_filter_module,
-                        sizeof(ngx_http_range_filter_ctx_t), NGX_ERROR);
+    ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_range_filter_ctx_t));
+    if (ctx == NULL) {
+        return NGX_ERROR;
+    }
+    
+    ngx_http_set_ctx(r, ctx, ngx_http_range_body_filter_module);
 
 
     len = sizeof(CRLF "--") - 1 + NGX_ATOMIC_T_LEN
@@ -338,7 +345,8 @@
         len += sizeof("; charset=") - 1 + r->headers_out.charset.len;
     }
 
-    if (!(ctx->boundary_header.data = ngx_palloc(r->pool, len))) {
+    ctx->boundary_header.data = ngx_palloc(r->pool, len);
+    if (ctx->boundary_header.data == NULL) {
         return NGX_ERROR;
     }
 
@@ -466,7 +474,8 @@
              * "Content-Range: bytes "
              */
 
-            if (!(b = ngx_calloc_buf(r->pool))) {
+            b = ngx_calloc_buf(r->pool);
+            if (b == NULL) {
                 return NGX_ERROR;
             }
 
@@ -474,7 +483,8 @@
             b->pos = ctx->boundary_header.data;
             b->last = ctx->boundary_header.data + ctx->boundary_header.len;
 
-            if (!(hcl = ngx_alloc_chain_link(r->pool))) {
+            hcl = ngx_alloc_chain_link(r->pool);
+            if (hcl == NULL) {
                 return NGX_ERROR;
             }
 
@@ -483,7 +493,8 @@
 
             /* "SSSS-EEEE/TTTT" CRLF CRLF */
 
-            if (!(b = ngx_calloc_buf(r->pool))) {
+            b = ngx_calloc_buf(r->pool);
+            if (b == NULL) {
                 return NGX_ERROR;
             }
 
@@ -491,7 +502,8 @@
             b->pos = range[i].content_range.data;
             b->last = range[i].content_range.data + range[i].content_range.len;
 
-            if (!(rcl = ngx_alloc_chain_link(r->pool))) {
+            rcl = ngx_alloc_chain_link(r->pool);
+            if (rcl == NULL) {
                 return NGX_ERROR;
             }
 
@@ -500,7 +512,8 @@
 
             /* the range data */
 
-            if (!(b = ngx_calloc_buf(r->pool))) {
+            b = ngx_calloc_buf(r->pool);
+            if (b == NULL) {
                 return NGX_ERROR;
             }
 
@@ -509,7 +522,8 @@
             b->file_last = range[i].end;
             b->file = in->buf->file;
 
-            if (!(dcl = ngx_alloc_chain_link(r->pool))) {
+            dcl = ngx_alloc_chain_link(r->pool);
+            if (dcl == NULL) {
                 return NGX_ERROR;
             }
 
@@ -523,7 +537,8 @@
 
         /* the last boundary CRLF "--0123456789--" CRLF  */
 
-        if (!(b = ngx_calloc_buf(r->pool))) {
+        b = ngx_calloc_buf(r->pool);
+        if (b == NULL) {
             return NGX_ERROR;
         }
 
@@ -540,7 +555,8 @@
         *b->last++ = '-'; *b->last++ = '-';
         *b->last++ = CR; *b->last++ = LF;
 
-        if (!(hcl = ngx_alloc_chain_link(r->pool))) {
+        hcl = ngx_alloc_chain_link(r->pool);
+        if (hcl == NULL) {
             return NGX_ERROR;
         }
 
diff --git a/src/http/modules/ngx_http_rewrite_handler.c b/src/http/modules/ngx_http_rewrite_module.c
similarity index 71%
rename from src/http/modules/ngx_http_rewrite_handler.c
rename to src/http/modules/ngx_http_rewrite_module.c
index 3080bd6..d0313a0 100644
--- a/src/http/modules/ngx_http_rewrite_handler.c
+++ b/src/http/modules/ngx_http_rewrite_module.c
@@ -21,6 +21,12 @@
 
 
 typedef struct {
+    ngx_str_t                    *name;
+    ngx_http_variable_value_t    *value;
+} ngx_http_rewrite_variable_t;
+
+
+typedef struct {
     ngx_array_t                  *codes;        /* uintptr_t */
     ngx_array_t                  *referers;     /* ngx_http_rewrite_referer_t */
 
@@ -41,6 +47,7 @@
     uintptr_t                     status;
     uintptr_t                     next;
 
+    uintptr_t                     test:1;
     uintptr_t                     uri:1;
 
     /* add the r->args to the new arguments */
@@ -92,13 +99,21 @@
 
 typedef struct {
     ngx_http_rewrite_code_pt      code;
+    uintptr_t                     value;
+    uintptr_t                     text_len;
+    uintptr_t                     text_data;
+} ngx_http_rewrite_value_code_t;
+
+
+typedef struct {
+    ngx_http_rewrite_code_pt      code;
     uintptr_t                     index;
 } ngx_http_rewrite_var_code_t;
 
 
 struct ngx_http_rewrite_engine_s {
     u_char                       *ip;
-    uintptr_t                    *sp;
+    ngx_http_variable_value_t    *sp;
 
     ngx_str_t                     buf;
     ngx_str_t                    *line;
@@ -128,8 +143,14 @@
     void *conf);
 static char *ngx_http_rewrite_if(ngx_conf_t *cf, ngx_command_t *cmd,
     void *conf);
+static char * ngx_http_rewrite_if_condition(ngx_conf_t *cf,
+    ngx_http_rewrite_loc_conf_t *lcf);
+static char *ngx_http_rewrite_variable(ngx_conf_t *cf,
+    ngx_http_rewrite_loc_conf_t *lcf, ngx_str_t *value);
 static char *ngx_http_rewrite_valid_referers(ngx_conf_t *cf,
     ngx_command_t *cmd, void *conf);
+static char * ngx_http_rewrite_set(ngx_conf_t *cf, ngx_command_t *cmd,
+    void *conf);
 static void *ngx_http_rewrite_start_code(ngx_pool_t *pool,
     ngx_array_t **codes, size_t size);
 static void *ngx_http_rewrite_add_code(ngx_array_t *codes, size_t size,
@@ -168,6 +189,14 @@
       0,
       NULL },
 
+    { ngx_string("set"),
+      NGX_HTTP_SRV_CONF|NGX_HTTP_SIF_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
+                       |NGX_CONF_TAKE2,
+      ngx_http_rewrite_set,
+      NGX_HTTP_LOC_CONF_OFFSET,
+      0,
+      NULL },
+
     { ngx_string("rewrite_log"),
       NGX_HTTP_SRV_CONF|NGX_HTTP_SIF_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
                        |NGX_CONF_TAKE1,
@@ -208,6 +237,9 @@
 
 uintptr_t ngx_http_rewrite_exit_code = (uintptr_t) NULL;
 
+static ngx_http_variable_value_t  ngx_http_rewrite_null_value =
+                                                        { 0, ngx_string("") };
+
 
 static ngx_int_t
 ngx_http_rewrite_handler(ngx_http_request_t *r)
@@ -222,11 +254,13 @@
         return NGX_DECLINED;
     }
 
-    if (!(e = ngx_palloc(r->pool, sizeof(ngx_http_rewrite_engine_t)))) {
+    e = ngx_palloc(r->pool, sizeof(ngx_http_rewrite_engine_t));
+    if (e == NULL) {
         return NGX_HTTP_INTERNAL_SERVER_ERROR;
     }
 
-    e->sp = ngx_palloc(r->pool, cf->stack_size * sizeof(ngx_int_t));
+    e->sp = ngx_palloc(r->pool,
+                       cf->stack_size * sizeof(ngx_http_variable_value_t));
     if (e->sp == NULL) {
         return NGX_HTTP_INTERNAL_SERVER_ERROR;
     }
@@ -274,12 +308,13 @@
     r = e->request;
 
     ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
-                   "http rewrite start: \"%V\"", &code->name);
+                   "http rewrite regex: \"%V\"", &code->name);
 
     if (code->uri) {
         e->line = &r->uri;
     } else {
-        e->line = *(ngx_str_t **) e->sp--;
+        e->sp--;
+        e->line = &e->sp->text;
     }
 
     rc = ngx_regex_exec(code->regex, e->line, e->captures, code->ncaptures);
@@ -290,6 +325,16 @@
                           "\"%V\" does not match \"%V\"", &code->name, e->line);
         }
 
+        if (code->test) {
+            e->sp->value = 0;
+            e->sp->text.len = 0;
+            e->sp->text.data = (u_char *) "";
+            e->sp++;
+
+            e->ip += sizeof(ngx_http_rewrite_regex_code_t);
+            return;
+        }
+
         e->ip += code->next;
         return;
     }
@@ -309,6 +354,16 @@
                       "\"%V\" matches \"%V\"", &code->name, e->line);
     }
 
+    if (code->test) {
+        e->sp->value = 1;
+        e->sp->text.len = 1;
+        e->sp->text.data = (u_char *) "1";
+        e->sp++;
+
+        e->ip += sizeof(ngx_http_rewrite_regex_code_t);
+        return;
+    }
+
     if (code->status) {
         e->status = code->status;
 
@@ -339,7 +394,8 @@
         e->buf.len += r->args.len + 1;
     }
 
-    if (!(e->buf.data = ngx_palloc(r->pool, e->buf.len))) {
+    e->buf.data = ngx_palloc(r->pool, e->buf.len);
+    if (e->buf.data == NULL) {
         e->ip = ngx_http_rewrite_exit;
         e->status = NGX_HTTP_INTERNAL_SERVER_ERROR;
         return;
@@ -366,7 +422,7 @@
     e->quote = 0;
 
     ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
-                   "http rewrite end");
+                   "http rewrite regex end");
 
     if (e->args) {
         e->buf.len = e->args - e->buf.data;
@@ -414,7 +470,8 @@
     ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0,
                   "rewritten redirect: \"%V\"", &e->buf);
 
-    if (!(r->headers_out.location = ngx_list_push(&r->headers_out.headers))) {
+    r->headers_out.location = ngx_list_push(&r->headers_out.headers);
+    if (r->headers_out.location == NULL) {
         e->ip = ngx_http_rewrite_exit;
         e->status = NGX_HTTP_INTERNAL_SERVER_ERROR;
         return;
@@ -468,7 +525,7 @@
                         code->len);
 
     e->ip += sizeof(ngx_http_rewrite_copy_code_t)
-             + ((code->len + sizeof(uintptr_t) - 1) & ~(sizeof(uintptr_t) - 1));
+          + ((code->len + sizeof(uintptr_t) - 1) & ~(sizeof(uintptr_t) - 1));
 
     ngx_log_debug1(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
                    "http rewrite copy: \"%V\"", &e->buf);
@@ -509,7 +566,9 @@
     ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
                    "http rewrite if");
 
-    if (*e->sp--) {
+    e->sp--;
+
+    if (e->sp->value) {
         if (code->loc_conf) {
             e->request->loc_conf = code->loc_conf;
         }
@@ -526,6 +585,69 @@
 
 
 static void
+ngx_http_rewrite_value_code(ngx_http_rewrite_engine_t *e)
+{
+    ngx_http_rewrite_value_code_t  *code;
+
+    code = (ngx_http_rewrite_value_code_t *) e->ip;
+
+    e->ip += sizeof(ngx_http_rewrite_value_code_t);
+
+    ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
+                   "http rewrite value");
+
+    e->sp->value = (ngx_uint_t) code->value;
+    e->sp->text.len = (size_t) code->text_len;
+    e->sp->text.data = (u_char *) code->text_data;
+    e->sp++;
+}
+
+
+static void
+ngx_http_rewrite_set_var_code(ngx_http_rewrite_engine_t *e)
+{
+    ngx_http_request_t           *r;
+    ngx_http_variable_value_t    *value;
+    ngx_http_core_main_conf_t    *cmcf;
+    ngx_http_rewrite_var_code_t  *code;
+
+    ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
+                   "http rewrite set var");
+
+    code = (ngx_http_rewrite_var_code_t *) e->ip;
+
+    e->ip += sizeof(ngx_http_rewrite_var_code_t);
+
+    r = e->request;
+
+    if (r->variables == NULL) {
+        cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
+
+        r->variables = ngx_pcalloc(r->pool, cmcf->variables.nelts
+                                        * sizeof(ngx_http_variable_value_t *));
+        if (r->variables == NULL) {
+            e->ip = ngx_http_rewrite_exit;
+            e->status = NGX_HTTP_INTERNAL_SERVER_ERROR;
+            return;
+        }
+    }
+
+    value = ngx_palloc(r->pool, sizeof(ngx_http_variable_value_t));
+    if (value == NULL) {
+        e->ip = ngx_http_rewrite_exit;
+        e->status = NGX_HTTP_INTERNAL_SERVER_ERROR;
+        return;
+    }
+
+    e->sp--;
+
+    *value = *e->sp;
+
+    r->variables[code->index] = value;
+}
+
+
+static void
 ngx_http_rewrite_var_code(ngx_http_rewrite_engine_t *e)
 {
     ngx_http_variable_value_t    *value;
@@ -536,19 +658,24 @@
 
     code = (ngx_http_rewrite_var_code_t *) e->ip;
 
-    e->sp++;
-
     e->ip += sizeof(ngx_http_rewrite_var_code_t);
 
-    if (!(value = ngx_http_get_indexed_variable(e->request, code->index))) {
-        *e->sp = (uintptr_t) 0;
+    value = ngx_http_get_indexed_variable(e->request, code->index);
+
+    if (value == NULL || value == NGX_HTTP_VARIABLE_NOT_FOUND) {
+        e->sp->value = 0;
+        e->sp->text.len = 0;
+        e->sp->text.data = (u_char *) "";
+        e->sp++;
+
         return;
     }
 
-    ngx_log_debug1(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
-                   "http rewrite var: %p", value->value);
+    ngx_log_debug2(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
+                   "http rewrite var: %ui, \"%V\"", value->value, &value->text);
 
-    *e->sp = value->value;
+    *e->sp = *value;
+    e->sp++;
 }
 
 
@@ -569,20 +696,31 @@
 
     cf = ngx_http_get_module_loc_conf(r, ngx_http_rewrite_module);
 
-    e->sp++;
     e->ip += sizeof(uintptr_t);
 
     if (cf->referers == NULL) {
-        *e->sp = (uintptr_t) 0;
+        e->sp->value = 0;
+        e->sp->text.len = 0;
+        e->sp->text.data = (u_char *) "";
+        e->sp++;
+
         return;
     }
 
     if (r->headers_in.referer == NULL) {
         if (cf->no_referer) {
-            *e->sp = (uintptr_t) 0;
+            e->sp->value = 0;
+            e->sp->text.len = 0;
+            e->sp->text.data = (u_char *) "";
+            e->sp++;
+
             return;
         } else {
-            *e->sp = (uintptr_t) 1;
+            e->sp->value = 1;
+            e->sp->text.len = 1;
+            e->sp->text.data = (u_char *) "1";
+            e->sp++;
+
             return;
         }
     }
@@ -593,7 +731,11 @@
     if (len < sizeof("http://i.ru") - 1
         || (ngx_strncasecmp(ref, "http://", 7) != 0))
     {
-        *e->sp = (uintptr_t) 1;
+        e->sp->value = 1;
+        e->sp->text.len = 1;
+        e->sp->text.data = (u_char *) "1";
+        e->sp++;
+
         return;
     }
 
@@ -620,7 +762,11 @@
                 if (ngx_strncmp(&ref[n], refs[i].name.data,
                                 refs[i].name.len) == 0)
                 {
-                    *e->sp = (uintptr_t) 0;
+                    e->sp->value = 0;
+                    e->sp->text.len = 0;
+                    e->sp->text.data = (u_char *) "";
+                    e->sp++;
+
                     return;
                 }
             }
@@ -628,13 +774,20 @@
         } else {
             if (ngx_strncasecmp(refs[i].name.data, ref, refs[i].name.len) == 0)
             {
-                *e->sp = (uintptr_t) 0;
+                e->sp->value = 0;
+                e->sp->text.len = 0;
+                e->sp->text.data = (u_char *) "";
+                e->sp++;
+
                 return;
             }
         }
     }
 
-    *e->sp = (uintptr_t) 1;
+    e->sp->value = 1;
+    e->sp->text.len = 1;
+    e->sp->text.data = (u_char *) "1";
+    e->sp++;
 }
 
 
@@ -645,6 +798,29 @@
 }
 
 
+static ngx_http_variable_value_t *
+ngx_http_rewrite_var(ngx_http_request_t *r, uintptr_t data)
+{
+    ngx_http_variable_t        *var;
+    ngx_http_core_main_conf_t  *cmcf;
+
+    cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
+
+    var = cmcf->variables.elts;
+
+    /*
+     * the ngx_http_rewrite_module sets variables directly in r->variables,
+     * and they should be handle by ngx_http_get_indexed_variable(),
+     * so the handler is called only if the variable is not initialized
+     */
+
+    ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
+                  "using uninitialized \"%V\" variable", &var[data].name);
+
+    return &ngx_http_rewrite_null_value;
+}
+
+
 static ngx_int_t
 ngx_http_rewrite_init(ngx_cycle_t *cycle)
 {   
@@ -653,7 +829,7 @@
     
     cmcf = ngx_http_cycle_get_module_main_conf(cycle, ngx_http_core_module);
 
-    h = ngx_push_array(&cmcf->phases[NGX_HTTP_REWRITE_PHASE].handlers);
+    h = ngx_array_push(&cmcf->phases[NGX_HTTP_REWRITE_PHASE].handlers);
     if (h == NULL) {
         return NGX_ERROR;
     }
@@ -669,7 +845,8 @@
 {
     ngx_http_rewrite_loc_conf_t  *conf;
 
-    if (!(conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_rewrite_loc_conf_t)))) {
+    conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_rewrite_loc_conf_t));
+    if (conf == NULL) {
         return NGX_CONF_ERROR;
     }
 
@@ -724,30 +901,53 @@
                 conf->max_captures = regex->ncaptures;
             }
             code = (uintptr_t *) ((u_char *) code + regex->next);
+            continue;
         }
 
         if (*code == (uintptr_t) &ngx_http_rewrite_if_code) {
             code += sizeof(ngx_http_rewrite_if_code_t) / sizeof(uintptr_t);
+            continue;
         }
 
         if (*code == (uintptr_t) &ngx_http_rewrite_return_code) {
             code += sizeof(ngx_http_rewrite_return_code_t) / sizeof(uintptr_t);
+            continue;
+        }
+
+        if (*code == (uintptr_t) &ngx_http_rewrite_set_var_code) {
+            code += sizeof(ngx_http_rewrite_var_code_t) / sizeof(uintptr_t);
+            continue;
         }
 
         if (*code == (uintptr_t) &ngx_http_rewrite_var_code) {
             code += sizeof(ngx_http_rewrite_var_code_t) / sizeof(uintptr_t);
+            continue;
+        }
+
+        if (*code == (uintptr_t) &ngx_http_rewrite_value_code) {
+            code += sizeof(ngx_http_rewrite_value_code_t) / sizeof(uintptr_t);
+            continue;
         }
 
         if (*code == (uintptr_t) &ngx_http_rewrite_invalid_referer_code) {
             code++;
+            continue;
         }
 
         if (*code == (uintptr_t) &ngx_http_rewrite_nop_code) {
             code++;
+            continue;
         }
+
+#if (NGX_DEBUG)
+        ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
+                      "unknown rewrite code: %p", *code);
+        return NGX_CONF_ERROR;
+#endif
     }
 
-    if (!(code = ngx_array_push_n(conf->codes, sizeof(uintptr_t)))) {
+    code = ngx_array_push_n(conf->codes, sizeof(uintptr_t));
+    if (code == NULL) {
         return NGX_CONF_ERROR;
     }
 
@@ -765,7 +965,8 @@
     u_char                                *data;
     size_t                                 len, size;
     ngx_str_t                             *value, err;
-    ngx_uint_t                             i, n, last;
+    ngx_int_t                              n;
+    ngx_uint_t                             i, last;
     ngx_http_rewrite_code_pt              *code;
     ngx_http_rewrite_copy_code_t          *copy;
     ngx_http_rewrite_regex_code_t         *regex;
@@ -797,6 +998,7 @@
     regex->size = 0;
     regex->ncaptures = 0;
     regex->status = 0;
+    regex->test = 0;
     regex->uri = 1;
     regex->args = 1;
     regex->redirect = 0;
@@ -946,7 +1148,14 @@
 
     n = ngx_regex_capture_count(regex->regex);
 
-    if (regex->ncaptures > n) {
+    if (n < 0) {
+        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+                           ngx_regex_capture_count_n " failed for "
+                           "pattern \"%V\"", &value[1]);
+        return NGX_CONF_ERROR;
+    }
+
+    if (regex->ncaptures > (ngx_uint_t) n) {
         ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
                            "pattern \"%V\" has less captures "
                            "than referrenced in substitution \"%V\"",
@@ -954,8 +1163,8 @@
         return NGX_CONF_ERROR;
     }
 
-    if (regex->ncaptures < n) {
-        regex->ncaptures = n;
+    if (regex->ncaptures < (ngx_uint_t) n) {
+        regex->ncaptures = (ngx_uint_t) n;
     }
 
     if (regex->ncaptures) {
@@ -1028,20 +1237,16 @@
     void                         *mconf;
     char                         *rv;
     u_char                       *elts;
-    ngx_str_t                    *value;
-    ngx_int_t                     index;
     ngx_uint_t                    i;
     ngx_conf_t                    save;
-    ngx_http_rewrite_code_pt     *code;
     ngx_http_module_t            *module;
     ngx_http_conf_ctx_t          *ctx, *pctx;
     ngx_http_core_loc_conf_t     *clcf, *pclcf, **clcfp;
-    ngx_http_core_main_conf_t    *cmcf;
     ngx_http_rewrite_if_code_t   *if_code;
-    ngx_http_rewrite_var_code_t  *var_code;
     ngx_http_rewrite_loc_conf_t  *nlcf;
 
-    if (!(ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)))) {
+    ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
+    if (ctx == NULL) {
         return NGX_CONF_ERROR;
     }
 
@@ -1063,7 +1268,8 @@
     
         if (module->create_loc_conf) {
 
-            if (!(mconf = module->create_loc_conf(cf))) {
+            mconf = module->create_loc_conf(cf);
+            if (mconf == NULL) {
                  return NGX_CONF_ERROR;
             }
 
@@ -1086,63 +1292,18 @@
         }
     }
 
-    if (!(clcfp = ngx_push_array(&pclcf->locations))) {
+    clcfp = ngx_array_push(&pclcf->locations);
+    if (clcfp == NULL) {
         return NGX_CONF_ERROR;
     }
 
     *clcfp = clcf;
 
 
-    /* STUB: "if ($var)" */
-
-    value = cf->args->elts;
-
-    if (value[1].len < 2
-        || value[1].data[0] != '('
-        || value[1].data[1] != '$'
-        || value[1].data[value[1].len - 1] != ')')
-    {
-        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
-                           "invalid condition \"%V\"", &value[1]);
+    if (ngx_http_rewrite_if_condition(cf, lcf) != NGX_CONF_OK) {
         return NGX_CONF_ERROR;
     }
 
-    value[1].len -= 3;
-    value[1].data += 2;
-
-    if (value[1].len == sizeof("invalid_referer") - 1
-        && ngx_strncmp(value[1].data, "invalid_referer",
-                       sizeof("invalid_referer") - 1) == 0)
-    {
-        code = ngx_http_rewrite_start_code(cf->pool, &lcf->codes,
-                                           sizeof(ngx_http_rewrite_code_pt));
-        if (code == NULL) {
-            return NGX_CONF_ERROR;
-        }
-
-        *code = ngx_http_rewrite_invalid_referer_code;
-
-    } else {
-        cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
-
-        index = ngx_http_get_variable_index(cmcf, &value[1]);
-
-        if (index == -1) {
-            ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
-                               "unknown variable name \"%V\"", &value[1]);
-            return NGX_CONF_ERROR;
-        }
-
-        var_code = ngx_http_rewrite_start_code(cf->pool, &lcf->codes,
-                                           sizeof(ngx_http_rewrite_var_code_t));
-        if (var_code == NULL) {
-            return NGX_CONF_ERROR;
-        }
-
-        var_code->code = ngx_http_rewrite_var_code;
-        var_code->index = index;
-    }
-
     if_code = ngx_array_push_n(lcf->codes, sizeof(ngx_http_rewrite_if_code_t));
     if (if_code == NULL) {
         return NULL;
@@ -1193,6 +1354,156 @@
 
 
 static char *
+ngx_http_rewrite_if_condition(ngx_conf_t *cf, ngx_http_rewrite_loc_conf_t *lcf)
+{
+    ngx_str_t                      *value, err;
+    ngx_uint_t                      cur, last;
+    ngx_http_rewrite_regex_code_t  *regex;
+    u_char                          errstr[NGX_MAX_CONF_ERRSTR];
+
+    value = cf->args->elts;
+    last = cf->args->nelts - 1;
+
+    if (value[1].len < 1 || value[1].data[0] != '(') {
+        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+                           "invalid condition \"%V\"", &value[1]);
+        return NGX_CONF_ERROR;
+    }
+
+    if (value[1].len == 1) {
+        cur = 2;
+
+    } else {
+        cur = 1;
+        value[1].len--;
+        value[1].data++;
+    }
+
+    if (value[last].len < 1 || value[last].data[value[last].len - 1] != ')') {
+        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+                           "invalid condition \"%V\"", &value[last]);
+        return NGX_CONF_ERROR;
+    }
+
+    if (value[last].len == 1) {
+        last--;
+
+    } else {
+        value[last].len--;
+        value[last].data[value[last].len] = '\0';
+    }
+
+    if (value[cur].len > 1 && value[cur].data[0] == '$') {
+
+        if (cur != last && cur + 2 != last) {
+            ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+                       "invalid condition \"%V\"", &value[cur]);
+            return NGX_CONF_ERROR;
+        }
+
+        if (ngx_http_rewrite_variable(cf, lcf, &value[cur])!= NGX_CONF_OK) {
+            return NGX_CONF_ERROR;
+        }
+
+        if (cur == last) {
+            return NGX_CONF_OK;
+        }
+
+        cur++;
+
+        if ((value[cur].len == 1 && value[cur].data[0] != '~')
+            || (value[cur].len == 2
+                && value[cur].data[0] != '~' && value[cur].data[1] != '*'))
+        {
+            ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+                               "unexpected \"%V\" in condition", &value[cur]);
+            return NGX_CONF_ERROR;
+        }
+
+        regex = ngx_http_rewrite_start_code(cf->pool, &lcf->codes,
+                                        sizeof(ngx_http_rewrite_regex_code_t));
+        if (regex == NULL) {
+            return NGX_CONF_ERROR;
+        }
+
+        err.len = NGX_MAX_CONF_ERRSTR;
+        err.data = errstr;
+
+        regex->regex = ngx_regex_compile(&value[last],
+                                (value[cur].len == 2) ? NGX_REGEX_CASELESS : 0,
+                                cf->pool, &err);
+
+        if (regex->regex == NULL) {
+            ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", err.data);
+            return NGX_CONF_ERROR;
+        }
+
+        regex->code = ngx_http_rewrite_regex_start_code;
+        regex->size = 0;
+        regex->ncaptures = 0;
+        regex->status = 0;
+        regex->next = sizeof(ngx_http_rewrite_regex_code_t);
+        regex->test = 1;
+        regex->uri = 0;
+        regex->args = 0;
+        regex->redirect = 0;
+        regex->name = value[last];
+
+        return NGX_CONF_OK;
+    }
+
+    ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+                       "invalid condition \"%V\"", &value[cur]);
+
+    return NGX_CONF_ERROR;
+}
+
+
+static char *
+ngx_http_rewrite_variable(ngx_conf_t *cf, ngx_http_rewrite_loc_conf_t *lcf,
+    ngx_str_t *value)
+{
+    ngx_http_variable_t          *var;
+    ngx_http_rewrite_code_pt     *code;
+    ngx_http_rewrite_var_code_t  *var_code;
+
+    value->len--;
+    value->data++;
+
+    if (value->len == sizeof("invalid_referer") - 1
+        && ngx_strncmp(value->data, "invalid_referer",
+                       sizeof("invalid_referer") - 1) == 0)
+    {
+        code = ngx_http_rewrite_start_code(cf->pool, &lcf->codes,
+                                           sizeof(ngx_http_rewrite_code_pt));
+        if (code == NULL) {
+            return NGX_CONF_ERROR;
+        }
+
+        *code = ngx_http_rewrite_invalid_referer_code;
+
+    } else {
+        var = ngx_http_add_variable(cf, value, 0);
+
+        if (var == NULL) {
+            return NGX_CONF_ERROR;
+        }
+
+        var_code = ngx_http_rewrite_start_code(cf->pool, &lcf->codes,
+                                           sizeof(ngx_http_rewrite_var_code_t));
+        if (var_code == NULL) {
+            return NGX_CONF_ERROR;
+        }
+
+        var_code->code = ngx_http_rewrite_var_code;
+        var_code->index = var->index;
+    }
+
+    return NGX_CONF_OK;
+}
+
+
+static char *
 ngx_http_rewrite_valid_referers(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
 {
     ngx_http_rewrite_loc_conf_t *lcf = conf;
@@ -1234,7 +1545,8 @@
             continue;
         }
 
-        if (!(ref = ngx_array_push(lcf->referers))) {
+        ref = ngx_array_push(lcf->referers);
+        if (ref == NULL) {
             return NGX_CONF_ERROR;
         }
 
@@ -1261,12 +1573,14 @@
 
     sn = cscf->server_names.elts;
     for (i = 0; i < cscf->server_names.nelts; i++) {
-        if (!(ref = ngx_array_push(lcf->referers))) {
+        ref = ngx_array_push(lcf->referers);
+        if (ref == NULL) {
             return NGX_CONF_ERROR;
         }
 
         ref->name.len = sn[i].name.len + 1;
-        if (!(ref->name.data = ngx_palloc(cf->pool, ref->name.len))) {
+        ref->name.data = ngx_palloc(cf->pool, ref->name.len);
+        if (ref->name.data == NULL) {
             return NGX_CONF_ERROR;
         }
 
@@ -1279,11 +1593,72 @@
 }
 
 
+static char *
+ngx_http_rewrite_set(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
+{
+    ngx_http_rewrite_loc_conf_t *lcf = conf;
+
+    ngx_int_t                       n;
+    ngx_str_t                      *value;
+    ngx_http_variable_t            *v;
+    ngx_http_rewrite_var_code_t    *var;
+    ngx_http_rewrite_value_code_t  *val;
+
+    value = cf->args->elts;
+
+    if (value[1].data[0] != '$') {
+        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+                           "invalid variable name \"%V\"", &value[1]);
+        return NGX_CONF_ERROR;
+    }
+
+    value[1].len--;
+    value[1].data++;
+
+    v = ngx_http_add_variable(cf, &value[1], 1);
+    if (v == NULL) {
+        return NGX_CONF_ERROR;
+    }
+
+    v->handler = ngx_http_rewrite_var;
+    v->data = v->index;
+
+    val = ngx_http_rewrite_start_code(cf->pool, &lcf->codes,
+                                      sizeof(ngx_http_rewrite_value_code_t));
+    if (val == NULL) {
+        return NGX_CONF_ERROR;
+    }
+
+    n = ngx_atoi(value[2].data, value[2].len);
+
+    if (n == NGX_ERROR) {
+        n = 0;
+    }
+
+    val->code = ngx_http_rewrite_value_code;
+    val->value = (uintptr_t) n;
+    val->text_len = (uintptr_t) value[2].len;
+    val->text_data = (uintptr_t) value[2].data;
+
+    var = ngx_http_rewrite_start_code(cf->pool, &lcf->codes,
+                                      sizeof(ngx_http_rewrite_var_code_t));
+    if (var == NULL) {
+        return NGX_CONF_ERROR;
+    }
+
+    var->code = ngx_http_rewrite_set_var_code;
+    var->index = (uintptr_t) v->index;
+
+    return NGX_CONF_OK;
+}
+
+
 static void *
 ngx_http_rewrite_start_code(ngx_pool_t *pool, ngx_array_t **codes, size_t size)
 {
     if (*codes == NULL) {
-        if (!(*codes = ngx_array_create(pool, 256, 1))) {
+        *codes = ngx_array_create(pool, 256, 1);
+        if (*codes == NULL) {
             return NULL;
         }
     }
@@ -1300,7 +1675,8 @@
 
     elts = codes->elts;
 
-    if (!(new = ngx_array_push_n(codes, size))) {
+    new = ngx_array_push_n(codes, size);
+    if (new == NULL) {
         return NGX_CONF_ERROR;
     }
 
diff --git a/src/http/modules/ngx_http_ssi_filter.c b/src/http/modules/ngx_http_ssi_filter_module.c
similarity index 98%
rename from src/http/modules/ngx_http_ssi_filter.c
rename to src/http/modules/ngx_http_ssi_filter_module.c
index ca877ac..a351747 100644
--- a/src/http/modules/ngx_http_ssi_filter.c
+++ b/src/http/modules/ngx_http_ssi_filter_module.c
@@ -98,8 +98,6 @@
 } ngx_http_ssi_state_e;
 
 
-static ngx_int_t ngx_http_ssi_error(ngx_http_request_t *r,
-    ngx_http_ssi_ctx_t *ctx);
 static ngx_int_t ngx_http_ssi_parse(ngx_http_request_t *r,
     ngx_http_ssi_ctx_t *ctx);
 
@@ -1147,21 +1145,25 @@
 ngx_http_ssi_echo(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx,
     ngx_str_t **params)
 {
+    ngx_uint_t                  i;
     ngx_buf_t                  *b;
     ngx_str_t                  *var, *value;
     ngx_chain_t                *cl;
-    ngx_http_variable_value_t  *v;
+    ngx_http_variable_value_t  *vv;
 
     var = params[NGX_HTTP_SSI_ECHO_VAR];
-    value = NULL;
 
-    v = ngx_http_get_variable(r, var);
+    for (i = 0; i < var->len; i++) {
+        var->data[i] = ngx_toupper(var->data[i]);
+    }
 
-    if (v == NULL) {
+    vv = ngx_http_get_variable(r, var);
+
+    if (vv == NULL) {
         return NGX_HTTP_SSI_ERROR;
     }
 
-    if (v == NGX_HTTP_VARIABLE_NOT_FOUND) {
+    if (vv == NGX_HTTP_VARIABLE_NOT_FOUND) {
         value = params[NGX_HTTP_SSI_ECHO_DEFAULT];
 
         if (value == NULL) {
@@ -1172,7 +1174,7 @@
         }
 
     } else {
-        value = &v->text;
+        value = &vv->text;
 
         if (value->len == 0) {
             return NGX_OK;
diff --git a/src/http/modules/ngx_http_ssl_module.c b/src/http/modules/ngx_http_ssl_module.c
index 883e44f..1c4128c 100644
--- a/src/http/modules/ngx_http_ssl_module.c
+++ b/src/http/modules/ngx_http_ssl_module.c
@@ -19,7 +19,7 @@
 static char *ngx_http_ssl_init_main_conf(ngx_conf_t *cf, void *conf);
 static void *ngx_http_ssl_create_srv_conf(ngx_conf_t *cf);
 static char *ngx_http_ssl_merge_srv_conf(ngx_conf_t *cf,
-                                         void *parent, void *child);
+    void *parent, void *child);
 
 
 static ngx_command_t  ngx_http_ssl_commands[] = {
@@ -87,11 +87,13 @@
 };
 
 
-static void *ngx_http_ssl_create_main_conf(ngx_conf_t *cf)
+static void *
+ngx_http_ssl_create_main_conf(ngx_conf_t *cf)
 {
     ngx_http_ssl_main_conf_t  *mcf;
 
-    if (!(mcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_ssl_main_conf_t)))) {
+    mcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_ssl_main_conf_t));
+    if (mcf == NULL) {
         return NGX_CONF_ERROR;
     }
 
@@ -106,7 +108,8 @@
 }
 
 
-static char *ngx_http_ssl_init_main_conf(ngx_conf_t *cf, void *conf)
+static char *
+ngx_http_ssl_init_main_conf(ngx_conf_t *cf, void *conf)
 {
     ngx_http_ssl_main_conf_t *mcf = conf;
 
@@ -137,11 +140,13 @@
 }
 
 
-static void *ngx_http_ssl_create_srv_conf(ngx_conf_t *cf)
+static void *
+ngx_http_ssl_create_srv_conf(ngx_conf_t *cf)
 {
     ngx_http_ssl_srv_conf_t  *scf;
 
-    if (!(scf = ngx_pcalloc(cf->pool, sizeof(ngx_http_ssl_srv_conf_t)))) {
+    scf = ngx_pcalloc(cf->pool, sizeof(ngx_http_ssl_srv_conf_t));
+    if (scf == NULL) {
         return NGX_CONF_ERROR;
     }
 
@@ -162,8 +167,8 @@
 }
 
 
-static char *ngx_http_ssl_merge_srv_conf(ngx_conf_t *cf,
-                                         void *parent, void *child)
+static char *
+ngx_http_ssl_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
 {
     ngx_http_ssl_srv_conf_t *prev = parent;
     ngx_http_ssl_srv_conf_t *conf = child;
@@ -226,7 +231,8 @@
 
 #if 0
 
-static ngx_int_t ngx_http_ssl_init_process(ngx_cycle_t *cycle)
+static ngx_int_t
+ngx_http_ssl_init_process(ngx_cycle_t *cycle)
 {
     ngx_uint_t                   i;
     ngx_http_ssl_srv_conf_t     *sscf;
diff --git a/src/http/modules/ngx_http_ssl_module.h b/src/http/modules/ngx_http_ssl_module.h
index 8716687..bf60366 100644
--- a/src/http/modules/ngx_http_ssl_module.h
+++ b/src/http/modules/ngx_http_ssl_module.h
@@ -32,7 +32,7 @@
 ngx_int_t ngx_http_ssl_read(ngx_http_request_t *r, u_char *buf, size_t size);
 ngx_int_t ngx_http_ssl_shutdown(ngx_http_request_t *r);
 ngx_chain_t *ngx_http_ssl_write(ngx_connection_t *c, ngx_chain_t *in,
-                                off_t limit);
+    off_t limit);
 
 void ngx_http_ssl_close_connection(SSL *ssl, ngx_log_t *log);
 
diff --git a/src/http/modules/ngx_http_static_handler.c b/src/http/modules/ngx_http_static_module.c
similarity index 93%
rename from src/http/modules/ngx_http_static_handler.c
rename to src/http/modules/ngx_http_static_module.c
index 4f0f96d..c2c4582 100644
--- a/src/http/modules/ngx_http_static_handler.c
+++ b/src/http/modules/ngx_http_static_module.c
@@ -75,10 +75,13 @@
     ngx_buf_t                   *b;
     ngx_chain_t                  out;
     ngx_file_info_t              fi;
-    ngx_http_cleanup_t          *file_cleanup, *redirect_cleanup;
-    ngx_http_core_loc_conf_t    *clcf;
-    ngx_http_static_loc_conf_t  *slcf;
+    ngx_http_cleanup_t          *file_cleanup;
 #if (NGX_HTTP_CACHE)
+    ngx_http_cleanup_t          *redirect_cleanup;
+#endif
+    ngx_http_core_loc_conf_t    *clcf;
+#if (NGX_HTTP_CACHE)
+    ngx_http_static_loc_conf_t  *slcf;
     uint32_t                     file_crc, redirect_crc;
     ngx_http_cache_t            *file, *redirect;
 #endif
@@ -176,14 +179,18 @@
 
     /* allocate cleanups */
 
-    if (!(file_cleanup = ngx_push_array(&r->cleanup))) {
+    file_cleanup = ngx_array_push(&r->cleanup);
+    if (file_cleanup == NULL) {
         return NGX_HTTP_INTERNAL_SERVER_ERROR;
     }
     file_cleanup->valid = 0;
 
+#if (NGX_HTTP_CACHE)
+
     slcf = ngx_http_get_module_loc_conf(r, ngx_http_static_module);
     if (slcf->redirect_cache) {
-        if (!(redirect_cleanup = ngx_push_array(&r->cleanup))) {
+        redirect_cleanup = ngx_array_push(&r->cleanup);
+        if (redirect_cleanup == NULL) {
             return NGX_HTTP_INTERNAL_SERVER_ERROR;
         }
         redirect_cleanup->valid = 0;
@@ -192,8 +199,6 @@
         redirect_cleanup = NULL;
     }
 
-#if (NGX_HTTP_CACHE)
-
     /* look up an open files cache */
 
     if (clcf->open_files) {
@@ -232,9 +237,9 @@
              * should keep more popular redirects in cache.
              */
 
-            if (!(r->headers_out.location =
-                   ngx_http_add_header(&r->headers_out, ngx_http_headers_out)))
-            {
+            r->headers_out.location = ngx_http_add_header(&r->headers_out,
+                                                          ngx_http_headers_out);
+            if (r->headers_out.location == NULL) {
                 return NGX_HTTP_INTERNAL_SERVER_ERROR;
             }
 
@@ -283,9 +288,9 @@
             ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0,
                            "HTTP DIR: \"%s\"", name.data);
 
-            if (!(r->headers_out.location =
-                   ngx_http_add_header(&r->headers_out, ngx_http_headers_out)))
-            {
+            r->headers_out.location = ngx_http_add_header(&r->headers_out,
+                                                          ngx_http_headers_out);
+            if (r->headers_out.location == NULL) {
                 return NGX_HTTP_INTERNAL_SERVER_ERROR;
             }
 
@@ -506,11 +511,13 @@
     if (!r->header_only) {
         /* we need to allocate all before the header would be sent */
 
-        if (!(b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t)))) {
+        b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t));
+        if (b == NULL) {
             return NGX_HTTP_INTERNAL_SERVER_ERROR;
         }
 
-        if (!(b->file = ngx_pcalloc(r->pool, sizeof(ngx_file_t)))) {
+        b->file = ngx_pcalloc(r->pool, sizeof(ngx_file_t));
+        if (b->file == NULL) {
             return NGX_HTTP_INTERNAL_SERVER_ERROR;
         }
 
@@ -547,7 +554,8 @@
 {
     ngx_http_static_loc_conf_t  *conf;
 
-    if (!(conf = ngx_palloc(cf->pool, sizeof(ngx_http_static_loc_conf_t)))) {
+    conf = ngx_palloc(cf->pool, sizeof(ngx_http_static_loc_conf_t));
+    if (conf == NULL) {
         return NGX_CONF_ERROR;
     }
 
@@ -578,7 +586,7 @@
 
     cmcf = ngx_http_cycle_get_module_main_conf(cycle, ngx_http_core_module);
     
-    h = ngx_push_array(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers);
+    h = ngx_array_push(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers);
     if (h == NULL) {
         return NGX_ERROR;
     }
diff --git a/src/http/modules/ngx_http_status_handler.c b/src/http/modules/ngx_http_status_module.c
similarity index 100%
rename from src/http/modules/ngx_http_status_handler.c
rename to src/http/modules/ngx_http_status_module.c
diff --git a/src/http/modules/ngx_http_stub_status_module.c b/src/http/modules/ngx_http_stub_status_module.c
index 7eeef59..1a01bce 100644
--- a/src/http/modules/ngx_http_stub_status_module.c
+++ b/src/http/modules/ngx_http_stub_status_module.c
@@ -88,7 +88,8 @@
            + 6 + 3 * NGX_ATOMIC_T_LEN
            + sizeof("Reading:  Writing:  Waiting:  \n") + 3 * NGX_ATOMIC_T_LEN;
 
-    if (!(b = ngx_create_temp_buf(r->pool, size))) {
+    b = ngx_create_temp_buf(r->pool, size);
+    if (b == NULL) {
         return NGX_HTTP_INTERNAL_SERVER_ERROR;
     }
 
diff --git a/src/http/modules/ngx_http_userid_filter.c b/src/http/modules/ngx_http_userid_filter_module.c
similarity index 99%
rename from src/http/modules/ngx_http_userid_filter.c
rename to src/http/modules/ngx_http_userid_filter_module.c
index ea49f92..62d40ac 100644
--- a/src/http/modules/ngx_http_userid_filter.c
+++ b/src/http/modules/ngx_http_userid_filter_module.c
@@ -618,7 +618,7 @@
     }
 
     p = ngx_cpymem(new, "; domain=", sizeof("; domain=") - 1);
-    p = ngx_cpymem(p, domain->data, domain->len);
+    ngx_memcpy(p, domain->data, domain->len);
 
     domain->len += sizeof("; domain=") - 1;
     domain->data = new;
@@ -640,7 +640,7 @@
     }
 
     p = ngx_cpymem(new, "; path=", sizeof("; path=") - 1);
-    p = ngx_cpymem(p, path->data, path->len);
+    ngx_memcpy(p, path->data, path->len);
 
     path->len += sizeof("; path=") - 1;
     path->data = new;
diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.c b/src/http/modules/proxy/ngx_http_proxy_handler.c
index d213d69..edad22c 100644
--- a/src/http/modules/proxy/ngx_http_proxy_handler.c
+++ b/src/http/modules/proxy/ngx_http_proxy_handler.c
@@ -11,7 +11,9 @@
 
 
 static ngx_int_t ngx_http_proxy_handler(ngx_http_request_t *r);
+#if 0
 static ngx_int_t ngx_http_proxy_cache_get(ngx_http_proxy_ctx_t *p);
+#endif
 
 static size_t ngx_http_proxy_log_proxy_state_getlen(ngx_http_request_t *r,
                                                     uintptr_t data);
@@ -33,8 +35,6 @@
 
 static char *ngx_http_proxy_set_pass(ngx_conf_t *cf, ngx_command_t *cmd,
                                      void *conf);
-static char *ngx_http_proxy_parse_upstream(ngx_str_t *url,
-                                           ngx_http_proxy_upstream_conf_t *u);
 
 static char *ngx_http_proxy_set_x_var(ngx_conf_t *cf, ngx_command_t *cmd,
                                       void *conf);
@@ -362,13 +362,20 @@
 };
 
 
+static ngx_str_t ngx_http_proxy_uri = ngx_string("/");
+
+
 static ngx_int_t ngx_http_proxy_handler(ngx_http_request_t *r)
 {
     ngx_http_proxy_ctx_t  *p;
 
-    ngx_http_create_ctx(r, p, ngx_http_proxy_module,
-                        sizeof(ngx_http_proxy_ctx_t),
-                        NGX_HTTP_INTERNAL_SERVER_ERROR);
+    p = ngx_pcalloc(r->pool, sizeof(ngx_http_proxy_ctx_t));
+    if (p == NULL) {
+        return NGX_HTTP_INTERNAL_SERVER_ERROR;
+    }
+
+    ngx_http_set_ctx(r, p, ngx_http_proxy_module);
+
 
     p->lcf = ngx_http_get_module_loc_conf(r, ngx_http_proxy_module);
     p->request = r;
@@ -382,7 +389,8 @@
         return NGX_HTTP_INTERNAL_SERVER_ERROR;
     }
 
-    if (!(p->state = ngx_array_push(&p->states))) {
+    p->state = ngx_array_push(&p->states);
+    if (p->state == NULL) {
         return NGX_HTTP_INTERNAL_SERVER_ERROR;
     }
 
@@ -439,7 +447,8 @@
     u = p->lcf->upstream;
 
     ctx.key.len = u->url.len + r->uri.len - u->location->len + r->args.len;
-    if (!(ctx.key.data = ngx_palloc(r->pool, ctx.key.len))) {
+    ctx.key.data = ngx_palloc(r->pool, ctx.key.len);
+    if (ctx.key.data == NULL) {
         return NGX_HTTP_INTERNAL_SERVER_ERROR;
     }
 
@@ -1072,7 +1081,8 @@
 {
     ngx_http_proxy_loc_conf_t  *conf;
 
-    if (!(conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_proxy_loc_conf_t)))) {
+    conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_proxy_loc_conf_t));
+    if (conf == NULL) {
         return NGX_CONF_ERROR;
     }
 
@@ -1332,7 +1342,8 @@
         unix_upstream.url.data = url->data + 7;
         unix_upstream.uri_part = 1;
 
-        if (!(lcf->peers = ngx_unix_upstream_parse(cf, &unix_upstream))) {
+        lcf->peers = ngx_unix_upstream_parse(cf, &unix_upstream);
+        if (lcf->peers == NULL) {
             return NGX_CONF_ERROR;
         }
 
@@ -1359,7 +1370,8 @@
         inet_upstream.default_port_value = 80;
         inet_upstream.uri_part = 1;
 
-        if (!(lcf->peers = ngx_inet_upstream_parse(cf, &inet_upstream))) {
+        lcf->peers = ngx_inet_upstream_parse(cf, &inet_upstream);
+        if (lcf->peers == NULL) {
             return NGX_CONF_ERROR;
         }
 
@@ -1372,9 +1384,14 @@
 
     clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
 
-    lcf->upstream->location = &clcf->name;
     clcf->handler = ngx_http_proxy_handler;
 
+#if (NGX_PCRE)
+    lcf->upstream->location = clcf->regex ? &ngx_http_proxy_uri : &clcf->name;
+#else
+    lcf->upstream->location = &clcf->name;
+#endif
+
     if (clcf->name.data[clcf->name.len - 1] == '/') {
         clcf->auto_redirect = 1;
     }
@@ -1409,7 +1426,8 @@
     for (i = 0; i < cmcf->variables.nelts; i++) {
         if (ngx_strcasecmp(var[i].name.data, value[1].data) == 0) {
 
-            if (!(index = ngx_array_push(lcf->x_vars))) {
+            index = ngx_array_push(lcf->x_vars);
+            if (index == NULL) {
                 return NGX_CONF_ERROR;
             }
 
diff --git a/src/http/modules/proxy/ngx_http_proxy_header.c b/src/http/modules/proxy/ngx_http_proxy_header.c
index 78ae653..a46ff9e 100644
--- a/src/http/modules/proxy/ngx_http_proxy_header.c
+++ b/src/http/modules/proxy/ngx_http_proxy_header.c
@@ -87,7 +87,8 @@
 
         /* copy some header pointers and set up r->headers_out */
 
-        if (!(ho = ngx_list_push(&r->headers_out.headers))) {
+        ho = ngx_list_push(&r->headers_out.headers);
+        if (ho == NULL) {
             return NGX_ERROR;
         }
 
@@ -162,7 +163,8 @@
     r = p->request;
     uc = p->lcf->upstream;
 
-    if (!(location = ngx_list_push(&r->headers_out.headers))) {
+    location = ngx_list_push(&r->headers_out.headers);
+    if (location == NULL) {
         return NGX_ERROR;
     }
 
@@ -189,7 +191,8 @@
 
     location->value.len = uc->location->len
                                           + (loc->value.len - uc->url.len) + 1;
-    if (!(location->value.data = ngx_palloc(r->pool, location->value.len))) {
+    location->value.data = ngx_palloc(r->pool, location->value.len);
+    if (location->value.data == NULL) {
         return NGX_ERROR;
     }
 
diff --git a/src/http/modules/proxy/ngx_http_proxy_upstream.c b/src/http/modules/proxy/ngx_http_proxy_upstream.c
index 061ab9f..45dc04d 100644
--- a/src/http/modules/proxy/ngx_http_proxy_upstream.c
+++ b/src/http/modules/proxy/ngx_http_proxy_upstream.c
@@ -58,7 +58,8 @@
 
     r = p->request;
 
-    if (!(u = ngx_pcalloc(r->pool, sizeof(ngx_http_proxy_upstream_t)))) {
+    u = ngx_pcalloc(r->pool, sizeof(ngx_http_proxy_upstream_t));
+    if (u == NULL) {
         return NGX_HTTP_INTERNAL_SERVER_ERROR;
     }
 
@@ -85,7 +86,7 @@
 
 static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p)
 {
-    size_t                           len;
+    size_t                           len, loc_len;
     ngx_uint_t                       i, escape, *index;
     ngx_buf_t                       *b;
     ngx_chain_t                     *chain;
@@ -94,6 +95,7 @@
     ngx_http_request_t              *r;
     ngx_http_variable_t             *var;
     ngx_http_variable_value_t       *value;
+    ngx_http_core_loc_conf_t        *clcf;
     ngx_http_core_main_conf_t       *cmcf;
     ngx_http_proxy_upstream_conf_t  *uc;
 
@@ -112,16 +114,23 @@
         len = r->method_name.len;
     }
 
+    clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
+
+#if (NGX_PCRE)
+    loc_len = (clcf->regex) ? 1 : clcf->name.len;
+#else
+    loc_len = clcf->name.len;
+#endif
+
     if (r->quoted_uri) {
-        escape = 2 * ngx_escape_uri(NULL, r->uri.data + uc->location->len,
-                                    r->uri.len - uc->location->len,
-                                    NGX_ESCAPE_URI);
+        escape = 2 * ngx_escape_uri(NULL, r->uri.data + loc_len,
+                                    r->uri.len - loc_len, NGX_ESCAPE_URI);
     } else {
         escape = 0;
     }
 
     len += uc->uri.len
-        + r->uri.len - uc->location->len + escape
+        + r->uri.len - loc_len + escape
         + sizeof("?") - 1 + r->args.len
         + sizeof(http_version) - 1
         + sizeof(connection_close_header) - 1
@@ -190,7 +199,8 @@
 
         for (i = 0; i < p->lcf->x_vars->nelts; i++) {
 
-            if (!(value = ngx_http_get_indexed_variable(r, index[i]))) {
+            value = ngx_http_get_indexed_variable(r, index[i]);
+            if (value == NULL) {
                 continue;
             }
 
@@ -233,11 +243,13 @@
     len++;
 #endif
 
-    if (!(b = ngx_create_temp_buf(r->pool, len))) {
+    b = ngx_create_temp_buf(r->pool, len);
+    if (b == NULL) {
         return NULL;
     }
 
-    if (!(chain = ngx_alloc_chain_link(r->pool))) {
+    chain = ngx_alloc_chain_link(r->pool);
+    if (chain == NULL) {
         return NULL;
     }
 
@@ -258,14 +270,13 @@
     b->last = ngx_cpymem(b->last, uc->uri.data, uc->uri.len);
 
     if (escape) {
-        ngx_escape_uri(b->last, r->uri.data + uc->location->len,
-                       r->uri.len - uc->location->len, NGX_ESCAPE_URI);
-        b->last += r->uri.len - uc->location->len + escape;
+        ngx_escape_uri(b->last, r->uri.data + loc_len,
+                       r->uri.len - loc_len, NGX_ESCAPE_URI);
+        b->last += r->uri.len - loc_len + escape;
 
     } else {
-        b->last = ngx_cpymem(b->last,
-                             r->uri.data + uc->location->len,
-                             r->uri.len - uc->location->len);
+        b->last = ngx_cpymem(b->last, r->uri.data + loc_len,
+                             r->uri.len - loc_len);
     }
 
     if (r->args.len > 0) {
@@ -379,7 +390,8 @@
     if (p->lcf->x_vars) {
         for (i = 0; i < p->lcf->x_vars->nelts; i++) {
 
-            if (!(value = ngx_http_get_indexed_variable(r, index[i]))) {
+            value = ngx_http_get_indexed_variable(r, index[i]);
+            if (value == NULL) {
                 continue;
             }
 
@@ -506,7 +518,8 @@
     }
 
 
-    if (!(cl = ngx_http_proxy_create_request(p))) {
+    cl = ngx_http_proxy_create_request(p);
+    if (cl == NULL) {
         ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
         return;
     }
@@ -517,7 +530,8 @@
 
     r->request_body->bufs = cl;
 
-    if (!(ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_proxy_log_ctx_t)))) {
+    ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_proxy_log_ctx_t));
+    if (ctx == NULL) {
         ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR);
         return;
     }
@@ -531,7 +545,8 @@
     r->connection->log->handler = ngx_http_proxy_log_error;
     p->action = "connecting to upstream";
 
-    if (!(output = ngx_pcalloc(r->pool, sizeof(ngx_output_chain_ctx_t)))) {
+    output = ngx_pcalloc(r->pool, sizeof(ngx_output_chain_ctx_t));
+    if (output == NULL) {
         ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR);
         return;
     }
@@ -544,7 +559,8 @@
     output->tag = (ngx_buf_tag_t) &ngx_http_proxy_module;
     output->output_filter = ngx_chain_writer;
 
-    if (!(writer = ngx_palloc(r->pool, sizeof(ngx_chain_writer_ctx_t)))) {
+    writer = ngx_palloc(r->pool, sizeof(ngx_chain_writer_ctx_t));
+    if (writer == NULL) {
         ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR);
         return;
     }
@@ -603,7 +619,8 @@
 
     state = p->state->cache_state;
 
-    if (!(p->state = ngx_push_array(&p->states))) {
+    p->state = ngx_array_push(&p->states);
+    if (p->state == NULL) {
         ngx_http_proxy_finalize_request(p, NGX_HTTP_INTERNAL_SERVER_ERROR);
         return;
     }
@@ -775,7 +792,8 @@
     if (r->request_body->buf) {
         if (r->request_body->temp_file) {
 
-            if (!(output->free = ngx_alloc_chain_link(r->pool))) {
+            output->free = ngx_alloc_chain_link(r->pool);
+            if (output->free == NULL) {
                 ngx_http_proxy_finalize_request(p,
                                                 NGX_HTTP_INTERNAL_SERVER_ERROR);
                 return;
@@ -1005,7 +1023,7 @@
     rc = ngx_http_proxy_parse_status_line(p);
 
     if (rc == NGX_AGAIN) {
-        if (p->header_in->pos == p->header_in->last) {
+        if (p->header_in->pos == p->header_in->end) {
             ngx_log_error(NGX_LOG_ERR, rev->log, 0,
                           "upstream sent too long status line");
             ngx_http_proxy_next_upstream(p, NGX_HTTP_PROXY_FT_INVALID_HEADER);
@@ -1158,7 +1176,8 @@
 
             /* a header line has been parsed successfully */
 
-            if (!(h = ngx_list_push(&p->upstream->headers_in.headers))) {
+            h = ngx_list_push(&p->upstream->headers_in.headers);
+            if (h == NULL) {
                 ngx_http_proxy_finalize_request(p,
                                                 NGX_HTTP_INTERNAL_SERVER_ERROR);
                 return;
@@ -1315,6 +1334,11 @@
 
     rc = ngx_http_send_header(r);
 
+    if (rc == NGX_ERROR || rc > NGX_OK) {
+        ngx_http_proxy_finalize_request(p, rc);
+        return;
+    }
+
     p->header_sent = 1;
 
     if (p->cache && p->cache->ctx.file.fd != NGX_INVALID_FILE) {
@@ -1361,7 +1385,8 @@
 
     ep->cachable = p->cachable;
 
-    if (!(ep->temp_file = ngx_pcalloc(r->pool, sizeof(ngx_temp_file_t)))) {
+    ep->temp_file = ngx_pcalloc(r->pool, sizeof(ngx_temp_file_t));
+    if (ep->temp_file == NULL) {
         ngx_http_proxy_finalize_request(p, 0);
         return;
     }
@@ -1381,7 +1406,8 @@
     ep->max_temp_file_size = p->lcf->max_temp_file_size;
     ep->temp_file_write_size = p->lcf->temp_file_write_size;
 
-    if (!(ep->preread_bufs = ngx_alloc_chain_link(r->pool))) {
+    ep->preread_bufs = ngx_alloc_chain_link(r->pool);
+    if (ep->preread_bufs == NULL) {
         ngx_http_proxy_finalize_request(p, 0);
         return;
     }
@@ -1467,7 +1493,6 @@
         ngx_log_debug0(NGX_LOG_DEBUG_HTTP, ev->log, 0,
                        "http proxy process upstream");
         p = c->data;
-        r = p->request;
         p->action = "reading upstream body";
     }