summaryrefslogtreecommitdiff
path: root/src/http/modules
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2010-05-17 06:08:59 +0000
committerJonathan Kolb <jon@b0g.us>2010-05-17 06:08:59 +0000
commitbdb559930a37e0f299c1b015175ccbc8af309746 (patch)
tree10173d4a6f98c47c721584e641c3904fc73858c1 /src/http/modules
parent5b1ac2a50033b677b8f240743b6b7720b7f42bf0 (diff)
downloadnginx-bdb559930a37e0f299c1b015175ccbc8af309746.tar.gz
Changes with nginx 0.8.37 17 May 2010v0.8.37
*) Feature: the ngx_http_split_clients_module. *) Feature: the "map" directive supports keys more than 255 characters. *) Bugfix: nginx ignored the "private" and "no-store" values in the "Cache-Control" backend response header line. *) Bugfix: a "stub" parameter of an "include" SSI directive was not used, if empty response has 200 status code. *) Bugfix: if a proxied or FastCGI request was internally redirected to another proxied or FastCGI location, then a segmentation fault might occur in a worker process; the bug had appeared in 0.8.33. Thanks to Yichun Zhang. *) Bugfix: IMAP connections may hang until they timed out while talking to Zimbra server. Thanks to Alan Batie.
Diffstat (limited to 'src/http/modules')
-rw-r--r--src/http/modules/ngx_http_auth_basic_module.c7
-rw-r--r--src/http/modules/ngx_http_autoindex_module.c3
-rw-r--r--src/http/modules/ngx_http_empty_gif_module.c3
-rw-r--r--src/http/modules/ngx_http_fastcgi_module.c16
-rw-r--r--src/http/modules/ngx_http_gzip_filter_module.c7
-rw-r--r--src/http/modules/ngx_http_gzip_static_module.c8
-rw-r--r--src/http/modules/ngx_http_headers_filter_module.c29
-rw-r--r--src/http/modules/ngx_http_image_filter_module.c3
-rw-r--r--src/http/modules/ngx_http_log_module.c8
-rw-r--r--src/http/modules/ngx_http_memcached_module.c4
-rw-r--r--src/http/modules/ngx_http_proxy_module.c36
-rw-r--r--src/http/modules/ngx_http_range_filter_module.c12
-rw-r--r--src/http/modules/ngx_http_referer_module.c6
-rw-r--r--src/http/modules/ngx_http_split_clients_module.c237
-rw-r--r--src/http/modules/ngx_http_ssi_filter_module.c13
-rw-r--r--src/http/modules/ngx_http_ssl_module.c3
-rw-r--r--src/http/modules/ngx_http_stub_status_module.c3
-rw-r--r--src/http/modules/ngx_http_userid_filter_module.c26
-rw-r--r--src/http/modules/ngx_http_xslt_filter_module.c4
-rw-r--r--src/http/modules/perl/nginx.pm2
-rw-r--r--src/http/modules/perl/ngx_http_perl_module.c3
21 files changed, 298 insertions, 135 deletions
diff --git a/src/http/modules/ngx_http_auth_basic_module.c b/src/http/modules/ngx_http_auth_basic_module.c
index c9ce694ef..a6b95fa1d 100644
--- a/src/http/modules/ngx_http_auth_basic_module.c
+++ b/src/http/modules/ngx_http_auth_basic_module.c
@@ -348,8 +348,7 @@ ngx_http_auth_basic_set_realm(ngx_http_request_t *r, ngx_str_t *realm)
}
r->headers_out.www_authenticate->hash = 1;
- r->headers_out.www_authenticate->key.len = sizeof("WWW-Authenticate") - 1;
- r->headers_out.www_authenticate->key.data = (u_char *) "WWW-Authenticate";
+ ngx_str_set(&r->headers_out.www_authenticate->key, "WWW-Authenticate");
r->headers_out.www_authenticate->value = *realm;
return NGX_HTTP_UNAUTHORIZED;
@@ -425,9 +424,7 @@ ngx_http_auth_basic(ngx_conf_t *cf, void *post, void *data)
u_char *basic, *p;
if (ngx_strcmp(realm->data, "off") == 0) {
- realm->len = 0;
- realm->data = (u_char *) "";
-
+ ngx_str_set(realm, "");
return NGX_CONF_OK;
}
diff --git a/src/http/modules/ngx_http_autoindex_module.c b/src/http/modules/ngx_http_autoindex_module.c
index 698b7636c..9dc48702f 100644
--- a/src/http/modules/ngx_http_autoindex_module.c
+++ b/src/http/modules/ngx_http_autoindex_module.c
@@ -235,8 +235,7 @@ ngx_http_autoindex_handler(ngx_http_request_t *r)
r->headers_out.status = NGX_HTTP_OK;
r->headers_out.content_type_len = sizeof("text/html") - 1;
- r->headers_out.content_type.len = sizeof("text/html") - 1;
- r->headers_out.content_type.data = (u_char *) "text/html";
+ ngx_str_set(&r->headers_out.content_type, "text/html");
rc = ngx_http_send_header(r);
diff --git a/src/http/modules/ngx_http_empty_gif_module.c b/src/http/modules/ngx_http_empty_gif_module.c
index e6515df15..35c4415b3 100644
--- a/src/http/modules/ngx_http_empty_gif_module.c
+++ b/src/http/modules/ngx_http_empty_gif_module.c
@@ -123,8 +123,7 @@ ngx_http_empty_gif_handler(ngx_http_request_t *r)
}
r->headers_out.content_type_len = sizeof("image/gif") - 1;
- r->headers_out.content_type.len = sizeof("image/gif") - 1;
- r->headers_out.content_type.data = (u_char *) "image/gif";
+ ngx_str_set(&r->headers_out.content_type, "image/gif");
if (r->method == NGX_HTTP_HEAD) {
r->headers_out.status = NGX_HTTP_OK;
diff --git a/src/http/modules/ngx_http_fastcgi_module.c b/src/http/modules/ngx_http_fastcgi_module.c
index 77b6d9d38..162eca87b 100644
--- a/src/http/modules/ngx_http_fastcgi_module.c
+++ b/src/http/modules/ngx_http_fastcgi_module.c
@@ -589,9 +589,7 @@ ngx_http_fastcgi_handler(ngx_http_request_t *r)
u = r->upstream;
- u->schema.len = sizeof("fastcgi://") - 1;
- u->schema.data = (u_char *) "fastcgi://";
-
+ ngx_str_set(&u->schema, "fastcgi://");
u->output.tag = (ngx_buf_tag_t) &ngx_http_fastcgi_module;
u->conf = &flcf->upstream;
@@ -1449,15 +1447,12 @@ ngx_http_fastcgi_process_header(ngx_http_request_t *r)
} else if (u->headers_in.location) {
u->headers_in.status_n = 302;
- u->headers_in.status_line.len =
- sizeof("302 Moved Temporarily") - 1;
- u->headers_in.status_line.data =
- (u_char *) "302 Moved Temporarily";
+ ngx_str_set(&u->headers_in.status_line,
+ "302 Moved Temporarily");
} else {
u->headers_in.status_n = 200;
- u->headers_in.status_line.len = sizeof("200 OK") - 1;
- u->headers_in.status_line.data = (u_char *) "200 OK";
+ ngx_str_set(&u->headers_in.status_line, "200 OK");
}
if (u->state) {
@@ -1922,8 +1917,7 @@ ngx_http_fastcgi_create_loc_conf(ngx_conf_t *cf)
* conf->upstream.store_lengths = NULL;
* conf->upstream.store_values = NULL;
*
- * conf->index.len = 0;
- * conf->index.data = NULL;
+ * conf->index.len = { 0, NULL };
*/
conf->upstream.store = NGX_CONF_UNSET;
diff --git a/src/http/modules/ngx_http_gzip_filter_module.c b/src/http/modules/ngx_http_gzip_filter_module.c
index 879971ffb..e2b204ba2 100644
--- a/src/http/modules/ngx_http_gzip_filter_module.c
+++ b/src/http/modules/ngx_http_gzip_filter_module.c
@@ -285,11 +285,8 @@ ngx_http_gzip_header_filter(ngx_http_request_t *r)
}
h->hash = 1;
- h->key.len = sizeof("Content-Encoding") - 1;
- h->key.data = (u_char *) "Content-Encoding";
- h->value.len = sizeof("gzip") - 1;
- h->value.data = (u_char *) "gzip";
-
+ ngx_str_set(&h->key, "Content-Encoding");
+ ngx_str_set(&h->value, "gzip");
r->headers_out.content_encoding = h;
r->main_filter_need_in_memory = 1;
diff --git a/src/http/modules/ngx_http_gzip_static_module.c b/src/http/modules/ngx_http_gzip_static_module.c
index 2098d8c43..0c6dbbb4a 100644
--- a/src/http/modules/ngx_http_gzip_static_module.c
+++ b/src/http/modules/ngx_http_gzip_static_module.c
@@ -212,12 +212,10 @@ ngx_http_gzip_static_handler(ngx_http_request_t *r)
}
h->hash = 1;
- h->key.len = sizeof("Content-Encoding") - 1;
- h->key.data = (u_char *) "Content-Encoding";
- h->value.len = sizeof("gzip") - 1;
- h->value.data = (u_char *) "gzip";
-
+ ngx_str_set(&h->key, "Content-Encoding");
+ ngx_str_set(&h->value, "gzip");
r->headers_out.content_encoding = h;
+
r->ignore_content_encoding = 1;
/* we need to allocate all before the header would be sent */
diff --git a/src/http/modules/ngx_http_headers_filter_module.c b/src/http/modules/ngx_http_headers_filter_module.c
index fb6c0050e..1d409582c 100644
--- a/src/http/modules/ngx_http_headers_filter_module.c
+++ b/src/http/modules/ngx_http_headers_filter_module.c
@@ -196,8 +196,7 @@ ngx_http_set_expires(ngx_http_request_t *r, ngx_http_headers_conf_t *conf)
r->headers_out.expires = expires;
expires->hash = 1;
- expires->key.len = sizeof("Expires") - 1;
- expires->key.data = (u_char *) "Expires";
+ ngx_str_set(&expires->key, "Expires");
}
len = sizeof("Mon, 28 Sep 1970 06:00:00 GMT");
@@ -225,9 +224,7 @@ ngx_http_set_expires(ngx_http_request_t *r, ngx_http_headers_conf_t *conf)
}
cc->hash = 1;
- cc->key.len = sizeof("Cache-Control") - 1;
- cc->key.data = (u_char *) "Cache-Control";
-
+ ngx_str_set(&cc->key, "Cache-Control");
*ccp = cc;
} else {
@@ -240,20 +237,14 @@ ngx_http_set_expires(ngx_http_request_t *r, ngx_http_headers_conf_t *conf)
if (conf->expires == NGX_HTTP_EXPIRES_EPOCH) {
expires->value.data = (u_char *) "Thu, 01 Jan 1970 00:00:01 GMT";
-
- cc->value.len = sizeof("no-cache") - 1;
- cc->value.data = (u_char *) "no-cache";
-
+ ngx_str_set(&cc->value, "no-cache");
return NGX_OK;
}
if (conf->expires == NGX_HTTP_EXPIRES_MAX) {
expires->value.data = (u_char *) "Thu, 31 Dec 2037 23:55:55 GMT";
-
/* 10 years */
- cc->value.len = sizeof("max-age=315360000") - 1;
- cc->value.data = (u_char *) "max-age=315360000";
-
+ ngx_str_set(&cc->value, "max-age=315360000");
return NGX_OK;
}
@@ -265,10 +256,7 @@ ngx_http_set_expires(ngx_http_request_t *r, ngx_http_headers_conf_t *conf)
if (conf->expires_time == 0) {
ngx_memcpy(expires->value.data, ngx_cached_http_time.data,
ngx_cached_http_time.len + 1);
-
- cc->value.len = sizeof("max-age=0") - 1;
- cc->value.data = (u_char *) "max-age=0";
-
+ ngx_str_set(&cc->value, "max-age=0");
return NGX_OK;
}
@@ -292,9 +280,7 @@ ngx_http_set_expires(ngx_http_request_t *r, ngx_http_headers_conf_t *conf)
ngx_http_time(expires->value.data, expires_time);
if (conf->expires_time < 0 || max_age < 0) {
- cc->value.len = sizeof("no-cache") - 1;
- cc->value.data = (u_char *) "no-cache";
-
+ ngx_str_set(&cc->value, "no-cache");
return NGX_OK;
}
@@ -361,8 +347,7 @@ ngx_http_add_cache_control(ngx_http_request_t *r, ngx_http_header_val_t *hv,
}
cc->hash = 1;
- cc->key.len = sizeof("Cache-Control") - 1;
- cc->key.data = (u_char *) "Cache-Control";
+ ngx_str_set(&cc->key, "Cache-Control");
cc->value = *value;
*ccp = cc;
diff --git a/src/http/modules/ngx_http_image_filter_module.c b/src/http/modules/ngx_http_image_filter_module.c
index 6511317c6..b5f8425a8 100644
--- a/src/http/modules/ngx_http_image_filter_module.c
+++ b/src/http/modules/ngx_http_image_filter_module.c
@@ -529,8 +529,7 @@ ngx_http_image_json(ngx_http_request_t *r, ngx_http_image_filter_ctx_t *ctx)
ngx_http_clean_header(r);
r->headers_out.status = NGX_HTTP_OK;
- r->headers_out.content_type.len = sizeof("text/plain") - 1;
- r->headers_out.content_type.data = (u_char *) "text/plain";
+ ngx_str_set(&r->headers_out.content_type, "text/plain");
r->headers_out.content_type_lowcase = NULL;
if (ctx == NULL) {
diff --git a/src/http/modules/ngx_http_log_module.c b/src/http/modules/ngx_http_log_module.c
index 0752d0394..5f356c357 100644
--- a/src/http/modules/ngx_http_log_module.c
+++ b/src/http/modules/ngx_http_log_module.c
@@ -533,7 +533,7 @@ ngx_http_log_request_time(ngx_http_request_t *r, u_char *buf,
ms = (ngx_msec_int_t)
((tp->sec - r->start_sec) * 1000 + (tp->msec - r->start_msec));
- ms = (ms >= 0) ? ms : 0;
+ ms = ngx_max(ms, 0);
return ngx_sprintf(buf, "%T.%03M", ms / 1000, ms % 1000);
}
@@ -747,8 +747,7 @@ ngx_http_log_create_main_conf(ngx_conf_t *cf)
return NULL;
}
- fmt->name.len = sizeof("combined") - 1;
- fmt->name.data = (u_char *) "combined";
+ ngx_str_set(&fmt->name, "combined");
fmt->flushes = NULL;
@@ -922,8 +921,7 @@ ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
}
} else {
- name.len = sizeof("combined") - 1;
- name.data = (u_char *) "combined";
+ ngx_str_set(&name, "combined");
lmcf->combined_used = 1;
}
diff --git a/src/http/modules/ngx_http_memcached_module.c b/src/http/modules/ngx_http_memcached_module.c
index 090a285d3..607e319a5 100644
--- a/src/http/modules/ngx_http_memcached_module.c
+++ b/src/http/modules/ngx_http_memcached_module.c
@@ -189,9 +189,7 @@ ngx_http_memcached_handler(ngx_http_request_t *r)
u = r->upstream;
- u->schema.len = sizeof("memcached://") - 1;
- u->schema.data = (u_char *) "memcached://";
-
+ ngx_str_set(&u->schema, "memcached://");
u->output.tag = (ngx_buf_tag_t) &ngx_http_memcached_module;
mlcf = ngx_http_get_module_loc_conf(r, ngx_http_memcached_module);
diff --git a/src/http/modules/ngx_http_proxy_module.c b/src/http/modules/ngx_http_proxy_module.c
index 7b2e077ec..1db26576b 100644
--- a/src/http/modules/ngx_http_proxy_module.c
+++ b/src/http/modules/ngx_http_proxy_module.c
@@ -1568,10 +1568,8 @@ ngx_http_proxy_process_header(ngx_http_request_t *r)
h->hash = ngx_hash(ngx_hash(ngx_hash(ngx_hash(
ngx_hash('s', 'e'), 'r'), 'v'), 'e'), 'r');
- h->key.len = sizeof("Server") - 1;
- h->key.data = (u_char *) "Server";
- h->value.len = 0;
- h->value.data = NULL;
+ ngx_str_set(&h->key, "Server");
+ ngx_str_null(&h->value);
h->lowcase_key = (u_char *) "server";
}
@@ -1583,10 +1581,8 @@ ngx_http_proxy_process_header(ngx_http_request_t *r)
h->hash = ngx_hash(ngx_hash(ngx_hash('d', 'a'), 't'), 'e');
- h->key.len = sizeof("Date") - 1;
- h->key.data = (u_char *) "Date";
- h->value.len = 0;
- h->value.data = NULL;
+ ngx_str_set(&h->key, "Date");
+ ngx_str_null(&h->value);
h->lowcase_key = (u_char *) "date";
}
@@ -2222,8 +2218,7 @@ ngx_http_proxy_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
pr->replacement.text = conf->location;
} else {
- pr->replacement.text.len = 0;
- pr->replacement.text.data = NULL;
+ ngx_str_null(&pr->replacement.text);
}
}
}
@@ -2311,10 +2306,8 @@ ngx_http_proxy_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
return NGX_CONF_ERROR;
}
- s->key.len = sizeof("Content-Length") - 1;
- s->key.data = (u_char *) "Content-Length";
- s->value.len = sizeof("$proxy_internal_body_length") - 1;
- s->value.data = (u_char *) "$proxy_internal_body_length";
+ ngx_str_set(&s->key, "Content-Length");
+ ngx_str_set(&s->value, "$proxy_internal_body_length");
}
if (ngx_http_proxy_merge_headers(cf, conf, prev) != NGX_OK) {
@@ -2777,8 +2770,7 @@ ngx_http_proxy_redirect(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
pr->replacement.text = plcf->location;
} else {
- pr->replacement.text.len = 0;
- pr->replacement.text.data = NULL;
+ ngx_str_null(&pr->replacement.text);
}
return NGX_CONF_OK;
@@ -3038,12 +3030,10 @@ ngx_http_proxy_set_vars(ngx_url_t *u, ngx_http_proxy_vars_t *v)
v->host_header = u->host;
if (u->default_port == 80) {
- v->port.len = sizeof("80") - 1;
- v->port.data = (u_char *) "80";
+ ngx_str_set(&v->port, "80");
} else {
- v->port.len = sizeof("443") - 1;
- v->port.data = (u_char *) "443";
+ ngx_str_set(&v->port, "443");
}
} else {
@@ -3055,10 +3045,8 @@ ngx_http_proxy_set_vars(ngx_url_t *u, ngx_http_proxy_vars_t *v)
v->key_start.len += v->host_header.len;
} else {
- v->host_header.len = sizeof("localhost") - 1;
- v->host_header.data = (u_char *) "localhost";
- v->port.len = 0;
- v->port.data = (u_char *) "";
+ ngx_str_set(&v->host_header, "localhost");
+ ngx_str_null(&v->port);
v->key_start.len += sizeof("unix:") - 1 + u->host.len + 1;
}
diff --git a/src/http/modules/ngx_http_range_filter_module.c b/src/http/modules/ngx_http_range_filter_module.c
index bc2840831..e11240660 100644
--- a/src/http/modules/ngx_http_range_filter_module.c
+++ b/src/http/modules/ngx_http_range_filter_module.c
@@ -224,10 +224,8 @@ next_filter:
}
r->headers_out.accept_ranges->hash = 1;
- r->headers_out.accept_ranges->key.len = sizeof("Accept-Ranges") - 1;
- r->headers_out.accept_ranges->key.data = (u_char *) "Accept-Ranges";
- r->headers_out.accept_ranges->value.len = sizeof("bytes") - 1;
- r->headers_out.accept_ranges->value.data = (u_char *) "bytes";
+ ngx_str_set(&r->headers_out.accept_ranges->key, "Accept-Ranges");
+ ngx_str_set(&r->headers_out.accept_ranges->value, "bytes");
return ngx_http_next_header_filter(r);
}
@@ -355,8 +353,7 @@ ngx_http_range_singlepart_header(ngx_http_request_t *r,
r->headers_out.content_range = content_range;
content_range->hash = 1;
- content_range->key.len = sizeof("Content-Range") - 1;
- content_range->key.data = (u_char *) "Content-Range";
+ ngx_str_set(&content_range->key, "Content-Range");
content_range->value.data = ngx_pnalloc(r->pool,
sizeof("bytes -/") - 1 + 3 * NGX_OFF_T_LEN);
@@ -520,8 +517,7 @@ ngx_http_range_not_satisfiable(ngx_http_request_t *r)
r->headers_out.content_range = content_range;
content_range->hash = 1;
- content_range->key.len = sizeof("Content-Range") - 1;
- content_range->key.data = (u_char *) "Content-Range";
+ ngx_str_set(&content_range->key, "Content-Range");
content_range->value.data = ngx_pnalloc(r->pool,
sizeof("bytes */") - 1 + NGX_OFF_T_LEN);
diff --git a/src/http/modules/ngx_http_referer_module.c b/src/http/modules/ngx_http_referer_module.c
index 78cc7f4dd..8530084d5 100644
--- a/src/http/modules/ngx_http_referer_module.c
+++ b/src/http/modules/ngx_http_referer_module.c
@@ -363,8 +363,7 @@ ngx_http_valid_referers(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
ngx_http_server_name_t *sn;
ngx_http_core_srv_conf_t *cscf;
- name.len = sizeof("invalid_referer") - 1;
- name.data = (u_char *) "invalid_referer";
+ ngx_str_set(&name, "invalid_referer");
var = ngx_http_add_variable(cf, &name,
NGX_HTTP_VAR_CHANGEABLE|NGX_HTTP_VAR_NOHASH);
@@ -407,8 +406,7 @@ ngx_http_valid_referers(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
continue;
}
- uri.len = 0;
- uri.data = NULL;
+ ngx_str_null(&uri);
if (ngx_strcmp(value[i].data, "server_names") == 0) {
diff --git a/src/http/modules/ngx_http_split_clients_module.c b/src/http/modules/ngx_http_split_clients_module.c
new file mode 100644
index 000000000..95286ae18
--- /dev/null
+++ b/src/http/modules/ngx_http_split_clients_module.c
@@ -0,0 +1,237 @@
+
+/*
+ * Copyright (C) Igor Sysoev
+ */
+
+
+#include <ngx_config.h>
+#include <ngx_core.h>
+#include <ngx_http.h>
+
+
+typedef struct {
+ uint32_t percent;
+ ngx_http_variable_value_t value;
+} ngx_http_split_clients_part_t;
+
+
+typedef struct {
+ ngx_http_complex_value_t value;
+ ngx_array_t parts;
+} ngx_http_split_clients_ctx_t;
+
+
+static char *ngx_conf_split_clients_block(ngx_conf_t *cf, ngx_command_t *cmd,
+ void *conf);
+static char *ngx_http_split_clients(ngx_conf_t *cf, ngx_command_t *dummy,
+ void *conf);
+
+static ngx_command_t ngx_http_split_clients_commands[] = {
+
+ { ngx_string("split_clients"),
+ NGX_HTTP_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_TAKE2,
+ ngx_conf_split_clients_block,
+ NGX_HTTP_MAIN_CONF_OFFSET,
+ 0,
+ NULL },
+
+ ngx_null_command
+};
+
+
+static ngx_http_module_t ngx_http_split_clients_module_ctx = {
+ NULL, /* preconfiguration */
+ NULL, /* postconfiguration */
+
+ NULL, /* create main configuration */
+ NULL, /* init main configuration */
+
+ NULL, /* create server configuration */
+ NULL, /* merge server configuration */
+
+ NULL, /* create location configuration */
+ NULL /* merge location configuration */
+};
+
+
+ngx_module_t ngx_http_split_clients_module = {
+ NGX_MODULE_V1,
+ &ngx_http_split_clients_module_ctx, /* module context */
+ ngx_http_split_clients_commands, /* module directives */
+ NGX_HTTP_MODULE, /* module type */
+ NULL, /* init master */
+ NULL, /* init module */
+ NULL, /* init process */
+ NULL, /* init thread */
+ NULL, /* exit thread */
+ NULL, /* exit process */
+ NULL, /* exit master */
+ NGX_MODULE_V1_PADDING
+};
+
+
+static ngx_int_t
+ngx_http_split_clients_variable(ngx_http_request_t *r,
+ ngx_http_variable_value_t *v, uintptr_t data)
+{
+ ngx_http_split_clients_ctx_t *ctx = (ngx_http_split_clients_ctx_t *) data;
+
+ uint32_t hash;
+ ngx_str_t val;
+ ngx_uint_t i;
+ ngx_http_split_clients_part_t *part;
+
+ *v = ngx_http_variable_null_value;
+
+ if (ngx_http_complex_value(r, &ctx->value, &val) != NGX_OK) {
+ return NGX_OK;
+ }
+
+ hash = ngx_crc32_short(val.data, val.len);
+
+ part = ctx->parts.elts;
+
+ for (i = 0; i < ctx->parts.nelts; i++) {
+
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+ "%D %D", hash, part[i].percent);
+
+ if (hash < part[i].percent) {
+ *v = part[i].value;
+ return NGX_OK;
+ }
+ }
+
+ return NGX_OK;
+}
+
+
+static char *
+ngx_conf_split_clients_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
+{
+ char *rv;
+ ngx_str_t *value, name;
+ ngx_uint_t i, sum, last;
+ ngx_conf_t save;
+ ngx_http_variable_t *var;
+ ngx_http_split_clients_ctx_t *ctx;
+ ngx_http_split_clients_part_t *part;
+ ngx_http_compile_complex_value_t ccv;
+
+ ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_split_clients_ctx_t));
+ if (ctx == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
+ value = cf->args->elts;
+
+ ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
+
+ ccv.cf = cf;
+ ccv.value = &value[1];
+ ccv.complex_value = &ctx->value;
+
+ if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
+ return NGX_CONF_ERROR;
+ }
+
+ name = value[2];
+ name.len--;
+ name.data++;
+
+ var = ngx_http_add_variable(cf, &name, NGX_HTTP_VAR_CHANGEABLE);
+ if (var == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
+ var->get_handler = ngx_http_split_clients_variable;
+ var->data = (uintptr_t) ctx;
+
+ if (ngx_array_init(&ctx->parts, cf->pool, 2,
+ sizeof(ngx_http_split_clients_part_t))
+ != NGX_OK)
+ {
+ return NGX_CONF_ERROR;
+ }
+
+ save = *cf;
+ cf->ctx = ctx;
+ cf->handler = ngx_http_split_clients;
+ cf->handler_conf = conf;
+
+ rv = ngx_conf_parse(cf, NULL);
+
+ *cf = save;
+
+ sum = 0;
+ last = 0;
+ part = ctx->parts.elts;
+
+ for (i = 0; i < ctx->parts.nelts; i++) {
+ sum = part[i].percent ? sum + part[i].percent : 10000;
+ if (sum > 10000) {
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+ "percent sum is more than 100%%");
+ return NGX_CONF_ERROR;
+ }
+
+ if (part[i].percent) {
+ part[i].percent = (uint32_t)
+ (last + 0xffffffff / 10000 * part[i].percent);
+ } else {
+ part[i].percent = 0xffffffff;
+ }
+
+ last = part[i].percent;
+ }
+
+ return rv;
+}
+
+
+static char *
+ngx_http_split_clients(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
+{
+ ngx_int_t n;
+ ngx_str_t *value;
+ ngx_http_split_clients_ctx_t *ctx;
+ ngx_http_split_clients_part_t *part;
+
+ ctx = cf->ctx;
+ value = cf->args->elts;
+
+ part = ngx_array_push(&ctx->parts);
+ if (part == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
+ if (value[0].len == 1 && value[0].data[0] == '*') {
+ part->percent = 0;
+
+ } else {
+ if (value[0].data[value[0].len - 1] != '%') {
+ goto invalid;
+ }
+
+ n = ngx_atofp(value[0].data, value[0].len - 1, 2);
+ if (n == NGX_ERROR || n == 0) {
+ goto invalid;
+ }
+
+ part->percent = (uint32_t) n;
+ }
+
+ part->value.len = value[1].len;
+ part->value.valid = 1;
+ part->value.no_cacheable = 0;
+ part->value.not_found = 0;
+ part->value.data = value[1].data;
+
+ return NGX_CONF_OK;
+
+invalid:
+
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+ "invalid percent value \"%V\"", &value[0]);
+ return NGX_CONF_ERROR;
+}
diff --git a/src/http/modules/ngx_http_ssi_filter_module.c b/src/http/modules/ngx_http_ssi_filter_module.c
index 7a2beede1..b994711e7 100644
--- a/src/http/modules/ngx_http_ssi_filter_module.c
+++ b/src/http/modules/ngx_http_ssi_filter_module.c
@@ -346,13 +346,9 @@ ngx_http_ssi_header_filter(ngx_http_request_t *r)
ctx->params.nalloc = NGX_HTTP_SSI_PARAMS_N;
ctx->params.pool = r->pool;
- ctx->timefmt.len = sizeof("%A, %d-%b-%Y %H:%M:%S %Z") - 1;
- ctx->timefmt.data = (u_char *) "%A, %d-%b-%Y %H:%M:%S %Z";
-
- ctx->errmsg.len =
- sizeof("[an error occurred while processing the directive]") - 1;
- ctx->errmsg.data = (u_char *)
- "[an error occurred while processing the directive]";
+ ngx_str_set(&ctx->timefmt, "%A, %d-%b-%Y %H:%M:%S %Z");
+ ngx_str_set(&ctx->errmsg,
+ "[an error occurred while processing the directive]");
r->filter_need_in_memory = 1;
@@ -1904,8 +1900,7 @@ ngx_http_ssi_include(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx,
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"ssi include: \"%V\"", uri);
- args.len = 0;
- args.data = NULL;
+ ngx_str_null(&args);
flags = NGX_HTTP_LOG_UNSAFE;
if (ngx_http_parse_unsafe_uri(r, uri, &args, &flags) != NGX_OK) {
diff --git a/src/http/modules/ngx_http_ssl_module.c b/src/http/modules/ngx_http_ssl_module.c
index 3fe0d4366..ee6cc6f05 100644
--- a/src/http/modules/ngx_http_ssl_module.c
+++ b/src/http/modules/ngx_http_ssl_module.c
@@ -314,8 +314,7 @@ ngx_http_ssl_create_srv_conf(ngx_conf_t *cf)
* sscf->dhparam = { 0, NULL };
* sscf->client_certificate = { 0, NULL };
* sscf->crl = { 0, NULL };
- * sscf->ciphers.len = 0;
- * sscf->ciphers.data = NULL;
+ * sscf->ciphers = { 0, NULL };
* sscf->shm_zone = NULL;
*/
diff --git a/src/http/modules/ngx_http_stub_status_module.c b/src/http/modules/ngx_http_stub_status_module.c
index 9d2d074b2..4b74eb884 100644
--- a/src/http/modules/ngx_http_stub_status_module.c
+++ b/src/http/modules/ngx_http_stub_status_module.c
@@ -75,8 +75,7 @@ static ngx_int_t ngx_http_status_handler(ngx_http_request_t *r)
return rc;
}
- r->headers_out.content_type.len = sizeof("text/plain") - 1;
- r->headers_out.content_type.data = (u_char *) "text/plain";
+ ngx_str_set(&r->headers_out.content_type, "text/plain");
if (r->method == NGX_HTTP_HEAD) {
r->headers_out.status = NGX_HTTP_OK;
diff --git a/src/http/modules/ngx_http_userid_filter_module.c b/src/http/modules/ngx_http_userid_filter_module.c
index 9997274a6..03efd3a8a 100644
--- a/src/http/modules/ngx_http_userid_filter_module.c
+++ b/src/http/modules/ngx_http_userid_filter_module.c
@@ -493,8 +493,7 @@ ngx_http_userid_set_uid(ngx_http_request_t *r, ngx_http_userid_ctx_t *ctx,
}
set_cookie->hash = 1;
- set_cookie->key.len = sizeof("Set-Cookie") - 1;
- set_cookie->key.data = (u_char *) "Set-Cookie";
+ ngx_str_set(&set_cookie->key, "Set-Cookie");
set_cookie->value.len = p - cookie;
set_cookie->value.data = cookie;
@@ -511,8 +510,7 @@ ngx_http_userid_set_uid(ngx_http_request_t *r, ngx_http_userid_ctx_t *ctx,
}
p3p->hash = 1;
- p3p->key.len = sizeof("P3P") - 1;
- p3p->key.data = (u_char *) "P3P";
+ ngx_str_set(&p3p->key, "P3P");
p3p->value = conf->p3p;
return NGX_OK;
@@ -576,14 +574,10 @@ ngx_http_userid_create_conf(ngx_conf_t *cf)
/*
* set by ngx_pcalloc():
*
- * conf->name.len = 0;
- * conf->name.date = NULL;
- * conf->domain.len = 0;
- * conf->domain.date = NULL;
- * conf->path.len = 0;
- * conf->path.date = NULL;
- * conf->p3p.len = 0;
- * conf->p3p.date = NULL;
+ * conf->name = { 0, NULL };
+ * conf->domain = { 0, NULL };
+ * conf->path = { 0, NULL };
+ * conf->p3p = { 0, NULL };
*/
conf->enable = NGX_CONF_UNSET_UINT;
@@ -642,9 +636,7 @@ ngx_http_userid_domain(ngx_conf_t *cf, void *post, void *data)
u_char *p, *new;
if (ngx_strcmp(domain->data, "none") == 0) {
- domain->len = 0;
- domain->data = (u_char *) "";
-
+ ngx_str_set(domain, "");
return NGX_CONF_OK;
}
@@ -727,8 +719,7 @@ ngx_http_userid_p3p(ngx_conf_t *cf, void *post, void *data)
ngx_str_t *p3p = data;
if (ngx_strcmp(p3p->data, "none") == 0) {
- p3p->len = 0;
- p3p->data = (u_char *) "";
+ ngx_str_set(p3p, "");
}
return NGX_CONF_OK;
@@ -780,4 +771,3 @@ ngx_http_userid_init_worker(ngx_cycle_t *cycle)
return NGX_OK;
}
-
diff --git a/src/http/modules/ngx_http_xslt_filter_module.c b/src/http/modules/ngx_http_xslt_filter_module.c
index 528a187a1..a06b26c28 100644
--- a/src/http/modules/ngx_http_xslt_filter_module.c
+++ b/src/http/modules/ngx_http_xslt_filter_module.c
@@ -837,8 +837,7 @@ ngx_http_xslt_apply_stylesheet(ngx_http_request_t *r,
} else if (doc_type == XML_HTML_DOCUMENT_NODE) {
r->headers_out.content_type_len = sizeof("text/html") - 1;
- r->headers_out.content_type.len = sizeof("text/html") - 1;
- r->headers_out.content_type.data = (u_char *) "text/html";
+ ngx_str_set(&r->headers_out.content_type, "text/html");
}
r->headers_out.content_type_lowcase = NULL;
@@ -1144,7 +1143,6 @@ found:
if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
return NGX_CONF_ERROR;
}
-
}
return NGX_CONF_OK;
diff --git a/src/http/modules/perl/nginx.pm b/src/http/modules/perl/nginx.pm
index b2e895c99..c05474445 100644
--- a/src/http/modules/perl/nginx.pm
+++ b/src/http/modules/perl/nginx.pm
@@ -47,7 +47,7 @@ our @EXPORT = qw(
HTTP_INSUFFICIENT_STORAGE
);
-our $VERSION = '0.8.36';
+our $VERSION = '0.8.37';
require XSLoader;
XSLoader::load('nginx', $VERSION);
diff --git a/src/http/modules/perl/ngx_http_perl_module.c b/src/http/modules/perl/ngx_http_perl_module.c
index e1388f1c1..5096b506d 100644
--- a/src/http/modules/perl/ngx_http_perl_module.c
+++ b/src/http/modules/perl/ngx_http_perl_module.c
@@ -481,8 +481,7 @@ ngx_http_perl_init_interpreter(ngx_conf_t *cf, ngx_http_perl_main_conf_t *pmcf)
return NGX_CONF_ERROR;
}
- m->len = sizeof(NGX_PERL_MODULES) - 1;
- m->data = NGX_PERL_MODULES;
+ ngx_str_set(m, NGX_PERL_MODULES);
}
#endif