nginx-0.3.53-RELEASE import

    *) Change: the "add_header" directive adds the string to 204, 301, and
       302 responses.

    *) Feature: the "server" directive in the "upstream" context supports
       the "weight" parameter.

    *) Feature: the "server_name" directive supports the "*" wildcard.

    *) Feature: nginx supports the request body size more than 2G.

    *) Bugfix: if a client was successfully authorized using "satisfy_any
       on", then anyway the message "access forbidden by rule" was written
       in the log.

    *) Bugfix: the "PUT" method may erroneously not create a file and
       return the 409 code.

    *) Bugfix: if the IMAP/POP3 backend returned an error, then nginx
       continued proxying anyway.
diff --git a/src/http/modules/ngx_http_access_module.c b/src/http/modules/ngx_http_access_module.c
index 710dd24..b8aa3aa 100644
--- a/src/http/modules/ngx_http_access_module.c
+++ b/src/http/modules/ngx_http_access_module.c
@@ -92,6 +92,7 @@
     ngx_uint_t                   i;
     struct sockaddr_in          *sin;
     ngx_http_access_rule_t      *rule;
+    ngx_http_core_loc_conf_t    *clcf;
     ngx_http_access_loc_conf_t  *alcf;
 
     alcf = ngx_http_get_module_loc_conf(r, ngx_http_access_module);
@@ -113,8 +114,12 @@
 
         if ((sin->sin_addr.s_addr & rule[i].mask) == rule[i].addr) {
             if (rule[i].deny) {
-                ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
-                              "access forbidden by rule");
+                clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
+
+                if (!clcf->satisfy_any) {
+                    ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
+                                  "access forbidden by rule");
+                }
 
                 return NGX_HTTP_FORBIDDEN;
             }
diff --git a/src/http/modules/ngx_http_auth_basic_module.c b/src/http/modules/ngx_http_auth_basic_module.c
index d33e7f6..5dd2876 100644
--- a/src/http/modules/ngx_http_auth_basic_module.c
+++ b/src/http/modules/ngx_http_auth_basic_module.c
@@ -136,7 +136,7 @@
     fd = ngx_open_file(alcf->user_file.data, NGX_FILE_RDONLY, NGX_FILE_OPEN);
 
     if (fd == NGX_INVALID_FILE) {
-        ngx_log_error(NGX_LOG_ERR, r->connection->log, ngx_errno,
+        ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno,
                       ngx_open_file_n " \"%s\" failed", alcf->user_file.data);
         return NGX_HTTP_INTERNAL_SERVER_ERROR;
     }
diff --git a/src/http/modules/ngx_http_charset_filter_module.c b/src/http/modules/ngx_http_charset_filter_module.c
index 41a0e57..0bc31bc 100644
--- a/src/http/modules/ngx_http_charset_filter_module.c
+++ b/src/http/modules/ngx_http_charset_filter_module.c
@@ -188,7 +188,7 @@
 {
     u_char                        *ct;
     ngx_int_t                      charset, source_charset;
-    ngx_str_t                     *mc;
+    ngx_str_t                     *mc, *from, *to;
     ngx_uint_t                     n;
     ngx_http_charset_t            *charsets;
     ngx_http_charset_ctx_t        *ctx;
@@ -288,13 +288,10 @@
             return ngx_http_next_header_filter(r);
         }
 
-        ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
-                      "no \"charset_map\" between the charsets "
-                      "\"%V\" and \"%V\"",
-                      &charsets[lcf->source_charset].name,
-                      &r->main->headers_out.charset);
+        from = &charsets[lcf->source_charset].name;
+        to = &r->main->headers_out.charset;
 
-        return ngx_http_next_header_filter(r);
+        goto no_charset_map;
     }
 
     source_charset = ngx_http_charset_get_charset(charsets, n,
@@ -308,11 +305,12 @@
                               r->headers_out.charset.data)
                 != 0)
         {
-            ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
-                          "no \"charset_map\" between the charsets "
-                          "\"%V\" and \"%V\"",
-                          &r->headers_out.charset,
-                          &r->main->headers_out.charset);
+            from = &r->headers_out.charset;
+            to = (charset == NGX_HTTP_NO_CHARSET) ?
+                                           &r->main->headers_out.charset:
+                                           &charsets[charset].name;
+
+            goto no_charset_map;
         }
 
         return ngx_http_next_header_filter(r);
@@ -322,18 +320,24 @@
         && (charsets[source_charset].tables == NULL
             || charsets[source_charset].tables[charset] == NULL))
     {
-        ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
-                      "no \"charset_map\" between the charsets "
-                      "\"%V\" and \"%V\"",
-                      &charsets[source_charset].name, &charsets[charset].name);
+        from = &charsets[source_charset].name;
+        to = &charsets[charset].name;
 
-        return ngx_http_next_header_filter(r);
+        goto no_charset_map;
     }
 
     r->headers_out.content_type.len = r->headers_out.content_type_len;
 
     return ngx_http_charset_set_charset(r, mcf->charsets.elts, charset,
                                         source_charset);
+
+no_charset_map:
+
+    ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
+                  "no \"charset_map\" between the charsets "
+                  "\"%V\" and \"%V\"", from, to);
+
+    return ngx_http_next_header_filter(r);
 }
 
 
@@ -392,11 +396,14 @@
     ctx->from_utf8 = charsets[source_charset].utf8;
     ctx->to_utf8 = charsets[charset].utf8;
 
+    r->filter_need_in_memory = 1;
+
     if ((ctx->to_utf8 || ctx->from_utf8) && r == r->main) {
         ngx_http_clear_content_length(r);
-    }
 
-    r->filter_need_in_memory = 1;
+    } else {
+        r->filter_need_temporary = 1;
+    }
 
     return ngx_http_next_header_filter(r);
 }
diff --git a/src/http/modules/ngx_http_dav_module.c b/src/http/modules/ngx_http_dav_module.c
index 7f61774..53ef21c 100644
--- a/src/http/modules/ngx_http_dav_module.c
+++ b/src/http/modules/ngx_http_dav_module.c
@@ -251,17 +251,20 @@
 
     } else {
         status = NGX_HTTP_NO_CONTENT;
-    }
 
-    if (ngx_is_dir(&fi)) {
-        if (ngx_delete_file(temp->data) == NGX_FILE_ERROR) {
-            ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno,
-                          ngx_delete_file_n " \"%s\" failed",
-                          temp->data);
+        if (ngx_is_dir(&fi)) {
+            ngx_log_error(NGX_LOG_ERR, r->connection->log, NGX_EISDIR,
+                          "\"%s\" could not be created", path.data);
+
+            if (ngx_delete_file(temp->data) == NGX_FILE_ERROR) {
+                ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno,
+                              ngx_delete_file_n " \"%s\" failed",
+                              temp->data);
+            }
+
+            ngx_http_finalize_request(r, NGX_HTTP_CONFLICT);
+            return;
         }
-
-        ngx_http_finalize_request(r, NGX_HTTP_CONFLICT);
-        return;
     }
 
     if (ngx_rename_file(temp->data, path.data) != NGX_FILE_ERROR) {
diff --git a/src/http/modules/ngx_http_fastcgi_module.c b/src/http/modules/ngx_http_fastcgi_module.c
index 085fb47..172a1a7 100644
--- a/src/http/modules/ngx_http_fastcgi_module.c
+++ b/src/http/modules/ngx_http_fastcgi_module.c
@@ -1565,6 +1565,7 @@
     uintptr_t                    *code;
     ngx_str_t                    *header;
     ngx_uint_t                    i, j;
+    ngx_peer_t                   *peer;
     ngx_array_t                   hide_headers;
     ngx_keyval_t                 *src;
     ngx_hash_key_t               *hk;
@@ -1693,20 +1694,23 @@
                                |NGX_HTTP_UPSTREAM_FT_ERROR
                                |NGX_HTTP_UPSTREAM_FT_TIMEOUT));
 
-    ngx_conf_merge_unsigned_value(conf->upstream.max_fails,
+    ngx_conf_merge_uint_value(conf->upstream.max_fails,
                               prev->upstream.max_fails, 1);
 
     ngx_conf_merge_sec_value(conf->upstream.fail_timeout,
                               prev->upstream.fail_timeout, 10);
 
-    if (conf->upstream_peers && !conf->upstream_peers->balanced) {
+    if (conf->upstream_peers) {
+        peer = conf->upstream_peers->peers->peer;
         for (i = 0; i < conf->upstream_peers->peers->number; i++) {
-            conf->upstream_peers->peers->peer[i].weight = 1;
-            conf->upstream_peers->peers->peer[i].max_fails =
-                                                   conf->upstream.max_fails;
-            conf->upstream_peers->peers->peer[i].fail_timeout =
-                                                   conf->upstream.fail_timeout;
+            ngx_conf_init_uint_value(peer[i].weight, 1);
+            peer[i].current_weight = peer[i].weight;
+            ngx_conf_init_uint_value(peer[i].max_fails,
+                              conf->upstream.max_fails);
+            ngx_conf_init_value(peer[i].fail_timeout,
+                              conf->upstream.fail_timeout);
         }
+
     }
 
     ngx_conf_merge_path_value(conf->upstream.temp_path,
diff --git a/src/http/modules/ngx_http_gzip_filter_module.c b/src/http/modules/ngx_http_gzip_filter_module.c
index a08f31c..26c1649 100644
--- a/src/http/modules/ngx_http_gzip_filter_module.c
+++ b/src/http/modules/ngx_http_gzip_filter_module.c
@@ -1087,7 +1087,7 @@
 
     ngx_conf_merge_bufs_value(conf->bufs, prev->bufs, 4, ngx_pagesize);
 
-    ngx_conf_merge_unsigned_value(conf->http_version, prev->http_version,
+    ngx_conf_merge_uint_value(conf->http_version, prev->http_version,
                               NGX_HTTP_VERSION_11);
     ngx_conf_merge_bitmask_value(conf->proxied, prev->proxied,
                               (NGX_CONF_BITMASK_SET|NGX_HTTP_GZIP_PROXIED_OFF));
diff --git a/src/http/modules/ngx_http_headers_filter_module.c b/src/http/modules/ngx_http_headers_filter_module.c
index 8ced8e0..8065742 100644
--- a/src/http/modules/ngx_http_headers_filter_module.c
+++ b/src/http/modules/ngx_http_headers_filter_module.c
@@ -103,9 +103,12 @@
     ngx_http_header_val_t    *h;
     ngx_http_headers_conf_t  *conf;
 
-    if ((r->headers_out.status != NGX_HTTP_OK
-         && r->headers_out.status != NGX_HTTP_NOT_MODIFIED)
-        || r != r->main)
+    if (r != r->main
+        || (r->headers_out.status != NGX_HTTP_OK
+            && r->headers_out.status != NGX_HTTP_NO_CONTENT
+            && r->headers_out.status != NGX_HTTP_MOVED_PERMANENTLY
+            && r->headers_out.status != NGX_HTTP_MOVED_TEMPORARILY
+            && r->headers_out.status != NGX_HTTP_NOT_MODIFIED))
     {
         return ngx_http_next_header_filter(r);
     }
diff --git a/src/http/modules/ngx_http_log_module.c b/src/http/modules/ngx_http_log_module.c
index 5e16363..f85a6c8 100644
--- a/src/http/modules/ngx_http_log_module.c
+++ b/src/http/modules/ngx_http_log_module.c
@@ -478,7 +478,7 @@
 ngx_http_log_request_length(ngx_http_request_t *r, u_char *buf,
     ngx_http_log_op_t *op)
 {
-    return ngx_sprintf(buf, "%z", r->request_length);
+    return ngx_sprintf(buf, "%O", r->request_length);
 }
 
 
diff --git a/src/http/modules/ngx_http_memcached_module.c b/src/http/modules/ngx_http_memcached_module.c
index 5b07dbc..000622d 100644
--- a/src/http/modules/ngx_http_memcached_module.c
+++ b/src/http/modules/ngx_http_memcached_module.c
@@ -560,7 +560,7 @@
                                |NGX_HTTP_UPSTREAM_FT_ERROR
                                |NGX_HTTP_UPSTREAM_FT_TIMEOUT));
 
-    ngx_conf_merge_unsigned_value(conf->upstream.max_fails,
+    ngx_conf_merge_uint_value(conf->upstream.max_fails,
                               prev->upstream.max_fails, 1);
 
     ngx_conf_merge_sec_value(conf->upstream.fail_timeout,
diff --git a/src/http/modules/ngx_http_proxy_module.c b/src/http/modules/ngx_http_proxy_module.c
index f14151a..ff5b129 100644
--- a/src/http/modules/ngx_http_proxy_module.c
+++ b/src/http/modules/ngx_http_proxy_module.c
@@ -1520,6 +1520,7 @@
     uintptr_t                    *code;
     ngx_str_t                    *header;
     ngx_uint_t                    i, j;
+    ngx_peer_t                   *peer;
     ngx_array_t                   hide_headers;
     ngx_keyval_t                 *src, *s, *h;
     ngx_hash_key_t               *hk;
@@ -1647,19 +1648,21 @@
                                |NGX_HTTP_UPSTREAM_FT_ERROR
                                |NGX_HTTP_UPSTREAM_FT_TIMEOUT));
 
-    ngx_conf_merge_unsigned_value(conf->upstream.max_fails,
+    ngx_conf_merge_uint_value(conf->upstream.max_fails,
                               prev->upstream.max_fails, 1);
 
     ngx_conf_merge_sec_value(conf->upstream.fail_timeout,
                               prev->upstream.fail_timeout, 10);
 
-    if (conf->upstream_peers && !conf->upstream_peers->balanced) {
+    if (conf->upstream_peers) {
+        peer = conf->upstream_peers->peers->peer;
         for (i = 0; i < conf->upstream_peers->peers->number; i++) {
-            conf->upstream_peers->peers->peer[i].weight = 1;
-            conf->upstream_peers->peers->peer[i].max_fails =
-                                                   conf->upstream.max_fails;
-            conf->upstream_peers->peers->peer[i].fail_timeout =
-                                                   conf->upstream.fail_timeout;
+            ngx_conf_init_uint_value(peer[i].weight, 1);
+            peer[i].current_weight = peer[i].weight;
+            ngx_conf_init_uint_value(peer[i].max_fails,
+                              conf->upstream.max_fails);
+            ngx_conf_init_value(peer[i].fail_timeout,
+                              conf->upstream.fail_timeout);
         }
     }
 
diff --git a/src/http/modules/ngx_http_realip_module.c b/src/http/modules/ngx_http_realip_module.c
index 210bbf6..3940ee4 100644
--- a/src/http/modules/ngx_http_realip_module.c
+++ b/src/http/modules/ngx_http_realip_module.c
@@ -243,7 +243,7 @@
         conf->from = prev->from;
     }
 
-    ngx_conf_merge_unsigned_value(conf->xfwd, prev->xfwd, 0);
+    ngx_conf_merge_uint_value(conf->xfwd, prev->xfwd, 0);
 
     return NGX_CONF_OK;
 }
diff --git a/src/http/modules/ngx_http_rewrite_module.c b/src/http/modules/ngx_http_rewrite_module.c
index c557314..88988bd 100644
--- a/src/http/modules/ngx_http_rewrite_module.c
+++ b/src/http/modules/ngx_http_rewrite_module.c
@@ -245,7 +245,7 @@
     ngx_conf_merge_value(conf->log, prev->log, 0);
     ngx_conf_merge_value(conf->uninitialized_variable_warn,
                          prev->uninitialized_variable_warn, 1);
-    ngx_conf_merge_unsigned_value(conf->stack_size, prev->stack_size, 10);
+    ngx_conf_merge_uint_value(conf->stack_size, prev->stack_size, 10);
 
     if (conf->codes == NULL) {
         return NGX_CONF_OK;
diff --git a/src/http/modules/ngx_http_userid_filter_module.c b/src/http/modules/ngx_http_userid_filter_module.c
index 92c53f8..bdad35d 100644
--- a/src/http/modules/ngx_http_userid_filter_module.c
+++ b/src/http/modules/ngx_http_userid_filter_module.c
@@ -670,8 +670,8 @@
     ngx_http_userid_conf_t *prev = parent;
     ngx_http_userid_conf_t *conf = child;
 
-    ngx_conf_merge_unsigned_value(conf->enable, prev->enable,
-                                  NGX_HTTP_USERID_OFF);
+    ngx_conf_merge_uint_value(conf->enable, prev->enable,
+                              NGX_HTTP_USERID_OFF);
 
     ngx_conf_merge_str_value(conf->name, prev->name, "uid");
     ngx_conf_merge_str_value(conf->domain, prev->domain, "");
diff --git a/src/http/modules/perl/ngx_http_perl_module.c b/src/http/modules/perl/ngx_http_perl_module.c
index 91a9c85..bf976e9 100644
--- a/src/http/modules/perl/ngx_http_perl_module.c
+++ b/src/http/modules/perl/ngx_http_perl_module.c
@@ -833,9 +833,9 @@
     ngx_http_perl_main_conf_t *pmcf = conf;
 
 #if (NGX_HAVE_PERL_CLONE || NGX_HAVE_PERL_MULTIPLICITY)
-    ngx_conf_init_unsigned_value(pmcf->interp_max, 10);
+    ngx_conf_init_uint_value(pmcf->interp_max, 10);
 #else
-    ngx_conf_init_unsigned_value(pmcf->interp_max, 1);
+    ngx_conf_init_uint_value(pmcf->interp_max, 1);
 #endif
 
     pmcf->free_perls = ngx_pcalloc(cf->pool,