aboutsummaryrefslogtreecommitdiff
path: root/src/http/modules
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2005-02-09 14:31:07 +0000
committerIgor Sysoev <igor@sysoev.ru>2005-02-09 14:31:07 +0000
commitaa8286101a57f11f2c1f9b5bf2d7ec121e74beea (patch)
treed87e4d87bf388c7a3c630170d9ba43a8591007ed /src/http/modules
parent9ef28fa32a4713d365aa8d4cfc1f8732d6de47f6 (diff)
downloadnginx-aa8286101a57f11f2c1f9b5bf2d7ec121e74beea.tar.gz
nginx-aa8286101a57f11f2c1f9b5bf2d7ec121e74beea.zip
nginx-0.1.18-RELEASE importrelease-0.1.18
*) Workaround: the default values of the devpoll_events and the devpoll_changes directives changed from 512 to 32 to be compatible with Solaris 10. *) Bugfix: the proxy_set_x_var and fastcgi_set_var directives were not inherited. *) Bugfix: in the redirect rewrite directive the arguments were concatenated with URI by the "&" rather than the "?". *) Bugfix: the lines without trailing ";" in the file being included by the ngx_http_geo_module were silently ignored. *) Feature: the ngx_http_stub_status_module. *) Bugfix: the unknown log format in the access_log directive caused the segmentation fault. *) Feature: the new "document_root" parameter of the fastcgi_params directive. *) Feature: the fastcgi_redirect_errors directive. *) Feature: the new "break" modifier of the "rewrite" directive allows to stop the rewrite/location cycle and sets the current configuration to the request.
Diffstat (limited to 'src/http/modules')
-rw-r--r--src/http/modules/ngx_http_fastcgi_handler.c205
-rw-r--r--src/http/modules/ngx_http_geo_module.c2
-rw-r--r--src/http/modules/ngx_http_rewrite_handler.c106
-rw-r--r--src/http/modules/ngx_http_stub_status_module.c138
-rw-r--r--src/http/modules/proxy/ngx_http_proxy_handler.c14
-rw-r--r--src/http/modules/proxy/ngx_http_proxy_handler.h2
-rw-r--r--src/http/modules/proxy/ngx_http_proxy_upstream.c55
7 files changed, 378 insertions, 144 deletions
diff --git a/src/http/modules/ngx_http_fastcgi_handler.c b/src/http/modules/ngx_http_fastcgi_handler.c
index 828f7accc..43f99ca41 100644
--- a/src/http/modules/ngx_http_fastcgi_handler.c
+++ b/src/http/modules/ngx_http_fastcgi_handler.c
@@ -20,7 +20,7 @@ typedef struct {
ngx_str_t root;
ngx_str_t index;
- ngx_array_t vars;
+ ngx_array_t *vars;
ngx_str_t *location;
} ngx_http_fastcgi_loc_conf_t;
@@ -84,6 +84,7 @@ typedef struct {
#define NGX_HTTP_FASTCGI_GATEWAY_INTERFACE 0x0400
#define NGX_HTTP_FASTCGI_REQUEST_URI 0x0800
#define NGX_HTTP_FASTCGI_REDIRECT_STATUS 0x1000
+#define NGX_HTTP_FASTCGI_DOCUMENT_ROOT 0x2000
#define NGX_HTTP_FASTCGI_RESPONDER 1
@@ -123,22 +124,22 @@ static ngx_int_t ngx_http_fastcgi_reinit_request(ngx_http_request_t *r);
static ngx_int_t ngx_http_fastcgi_process_header(ngx_http_request_t *r);
static ngx_int_t ngx_http_fastcgi_send_header(ngx_http_request_t *r);
static ngx_int_t ngx_http_fastcgi_input_filter(ngx_event_pipe_t *p,
- ngx_buf_t *buf);
+ ngx_buf_t *buf);
static ngx_int_t ngx_http_fastcgi_process_record(ngx_http_request_t *r,
- ngx_http_fastcgi_ctx_t *f);
+ ngx_http_fastcgi_ctx_t *f);
static void ngx_http_fastcgi_abort_request(ngx_http_request_t *r);
static void ngx_http_fastcgi_finalize_request(ngx_http_request_t *r,
- ngx_int_t rc);
+ ngx_int_t rc);
static char *ngx_http_fastcgi_pass(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf);
+ void *conf);
static char *ngx_http_fastcgi_set_var(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf);
+ void *conf);
static char *ngx_http_fastcgi_lowat_check(ngx_conf_t *cf, void *post,
- void *data);
+ void *data);
static void *ngx_http_fastcgi_create_loc_conf(ngx_conf_t *cf);
static char *ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf,
- void *parent, void *child);
+ void *parent, void *child);
static ngx_str_t ngx_http_fastcgi_methods[] = {
@@ -155,17 +156,17 @@ static ngx_http_header_t ngx_http_fastcgi_headers_in[] = {
{ ngx_string("Status"), offsetof(ngx_http_fastcgi_headers_in_t, status) },
{ ngx_string("Content-Type"),
- offsetof(ngx_http_fastcgi_headers_in_t, content_type) },
+ offsetof(ngx_http_fastcgi_headers_in_t, content_type) },
{ ngx_string("Content-Length"),
- offsetof(ngx_http_fastcgi_headers_in_t, content_length) },
+ offsetof(ngx_http_fastcgi_headers_in_t, content_length) },
{ ngx_string("X-Powered-By"),
- offsetof(ngx_http_fastcgi_headers_in_t, x_powered_by) },
+ offsetof(ngx_http_fastcgi_headers_in_t, x_powered_by) },
#if (NGX_HTTP_GZIP)
{ ngx_string("Content-Encoding"),
- offsetof(ngx_http_fastcgi_headers_in_t, content_encoding) },
+ offsetof(ngx_http_fastcgi_headers_in_t, content_encoding) },
#endif
{ ngx_null_string, 0 }
@@ -173,7 +174,7 @@ static ngx_http_header_t ngx_http_fastcgi_headers_in[] = {
static ngx_conf_post_t ngx_http_fastcgi_lowat_post =
- { ngx_http_fastcgi_lowat_check } ;
+ { ngx_http_fastcgi_lowat_check };
static ngx_conf_bitmask_t ngx_http_fastcgi_next_upstream_masks[] = {
{ ngx_string("error"), NGX_HTTP_UPSTREAM_FT_ERROR },
@@ -198,6 +199,7 @@ static ngx_conf_bitmask_t ngx_http_fastcgi_params_masks[] = {
{ ngx_string("redirect_status"), NGX_HTTP_FASTCGI_REDIRECT_STATUS },
{ ngx_string("request_uri"), NGX_HTTP_FASTCGI_REQUEST_URI },
+ { ngx_string("document_root"), NGX_HTTP_FASTCGI_DOCUMENT_ROOT },
{ ngx_null_string, 0 }
};
@@ -254,6 +256,13 @@ static ngx_command_t ngx_http_fastcgi_commands[] = {
offsetof(ngx_http_fastcgi_loc_conf_t, upstream.header_buffer_size),
NULL },
+ { ngx_string("fastcgi_redirect_errors"),
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
+ ngx_conf_set_flag_slot,
+ NGX_HTTP_LOC_CONF_OFFSET,
+ offsetof(ngx_http_fastcgi_loc_conf_t, upstream.redirect_errors),
+ NULL },
+
{ ngx_string("fastcgi_x_powered_by"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
ngx_conf_set_flag_slot,
@@ -352,7 +361,8 @@ ngx_module_t ngx_http_fastcgi_module = {
};
-static ngx_int_t ngx_http_fastcgi_handler(ngx_http_request_t *r)
+static ngx_int_t
+ngx_http_fastcgi_handler(ngx_http_request_t *r)
{
ngx_int_t rc;
ngx_http_upstream_t *u;
@@ -408,7 +418,8 @@ static ngx_int_t ngx_http_fastcgi_handler(ngx_http_request_t *r)
}
-static ngx_int_t ngx_http_fastcgi_create_request(ngx_http_request_t *r)
+static ngx_int_t
+ngx_http_fastcgi_create_request(ngx_http_request_t *r)
{
u_char ch, *pos, addr_text[INET_ADDRSTRLEN];
size_t size, len, index, padding, addr_len;
@@ -422,6 +433,7 @@ static ngx_int_t ngx_http_fastcgi_create_request(ngx_http_request_t *r)
struct sockaddr_in sin;
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_fastcgi_header_t *h;
ngx_http_fastcgi_loc_conf_t *flcf;
@@ -450,6 +462,12 @@ static ngx_int_t ngx_http_fastcgi_create_request(ngx_http_request_t *r)
return NGX_ERROR;
}
+#if (NGX_SUPPRESS_WARN)
+ clcf = NULL;
+ var = NULL;
+ vindex = NULL;
+#endif
+
if (r->upstream->method) {
len = 1 + 1 + sizeof("REQUEST_METHOD") - 1
@@ -496,6 +514,12 @@ static ngx_int_t ngx_http_fastcgi_create_request(ngx_http_request_t *r)
+ 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;
+ }
+
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 ;
@@ -533,19 +557,21 @@ static ngx_int_t ngx_http_fastcgi_create_request(ngx_http_request_t *r)
}
- cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
+ if (flcf->vars) {
+ cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
- var = cmcf->variables.elts;
- vindex = flcf->vars.elts;
+ var = cmcf->variables.elts;
+ vindex = flcf->vars->elts;
- for (i = 0; i < flcf->vars.nelts; i++) {
+ for (i = 0; i < flcf->vars->nelts; i++) {
- if (!(value = ngx_http_get_variable(r, vindex[i]))) {
- continue;
- }
+ if (!(value = ngx_http_get_variable(r, vindex[i]))) {
+ continue;
+ }
- if (value->text.len) {
- len += 1 + 1 + var[vindex[i]].name.len + value->text.len;
+ if (value->text.len) {
+ len += 1 + 1 + var[vindex[i]].name.len + value->text.len;
+ }
}
}
@@ -785,6 +811,26 @@ static ngx_int_t ngx_http_fastcgi_create_request(ngx_http_request_t *r)
}
+ if (flcf->params & NGX_HTTP_FASTCGI_DOCUMENT_ROOT) {
+ *b->last++ = sizeof("DOCUMENT_ROOT") - 1;
+
+ len = clcf->root.len;
+ if (len > 127) {
+ *b->last++ = (u_char) (((len >> 24) & 0x7f) | 0x80);
+ *b->last++ = (u_char) ((len >> 16) & 0xff);
+ *b->last++ = (u_char) ((len >> 8) & 0xff);
+ *b->last++ = (u_char) (len & 0xff);
+
+ } else {
+ *b->last++ = (u_char) len;
+ }
+
+ b->last = ngx_cpymem(b->last, "DOCUMENT_ROOT",
+ sizeof("DOCUMENT_ROOT") - 1);
+ b->last = ngx_cpymem(b->last, clcf->root.data, len);
+ }
+
+
if (flcf->params & NGX_HTTP_FASTCGI_SCRIPT_NAME) {
*b->last++ = sizeof("SCRIPT_NAME") - 1;
@@ -882,23 +928,25 @@ static ngx_int_t ngx_http_fastcgi_create_request(ngx_http_request_t *r)
}
- for (i = 0; i < flcf->vars.nelts; i++) {
+ if (flcf->vars) {
+ for (i = 0; i < flcf->vars->nelts; i++) {
- if (!(value = ngx_http_get_variable(r, vindex[i]))) {
- continue;
- }
+ if (!(value = ngx_http_get_variable(r, vindex[i]))) {
+ continue;
+ }
- if (value->text.len == 0) {
- continue;
- }
+ if (value->text.len == 0) {
+ continue;
+ }
- *b->last++ = (u_char) var[vindex[i]].name.len;
- *b->last++ = (u_char) value->text.len;
+ *b->last++ = (u_char) var[vindex[i]].name.len;
+ *b->last++ = (u_char) value->text.len;
- b->last = ngx_cpymem(b->last, var[vindex[i]].name.data,
- var[vindex[i]].name.len);
+ b->last = ngx_cpymem(b->last, var[vindex[i]].name.data,
+ var[vindex[i]].name.len);
- b->last = ngx_cpymem(b->last, value->text.data, value->text.len);
+ b->last = ngx_cpymem(b->last, value->text.data, value->text.len);
+ }
}
@@ -1091,7 +1139,8 @@ static ngx_int_t ngx_http_fastcgi_create_request(ngx_http_request_t *r)
}
-static ngx_int_t ngx_http_fastcgi_reinit_request(ngx_http_request_t *r)
+static ngx_int_t
+ngx_http_fastcgi_reinit_request(ngx_http_request_t *r)
{
ngx_http_fastcgi_ctx_t *f;
@@ -1357,7 +1406,8 @@ static ngx_int_t ngx_http_fastcgi_process_header(ngx_http_request_t *r)
}
-static ngx_int_t ngx_http_fastcgi_send_header(ngx_http_request_t *r)
+static ngx_int_t
+ngx_http_fastcgi_send_header(ngx_http_request_t *r)
{
ngx_uint_t i;
ngx_list_part_t *part;
@@ -1433,8 +1483,8 @@ static ngx_int_t ngx_http_fastcgi_send_header(ngx_http_request_t *r)
}
-static ngx_int_t ngx_http_fastcgi_input_filter(ngx_event_pipe_t *p,
- ngx_buf_t *buf)
+static ngx_int_t
+ngx_http_fastcgi_input_filter(ngx_event_pipe_t *p, ngx_buf_t *buf)
{
ngx_int_t rc;
ngx_buf_t *b, **prev;
@@ -1637,8 +1687,9 @@ static ngx_int_t ngx_http_fastcgi_input_filter(ngx_event_pipe_t *p,
}
-static ngx_int_t ngx_http_fastcgi_process_record(ngx_http_request_t *r,
- ngx_http_fastcgi_ctx_t *f)
+static ngx_int_t
+ngx_http_fastcgi_process_record(ngx_http_request_t *r,
+ ngx_http_fastcgi_ctx_t *f)
{
u_char ch, *p;
ngx_http_upstream_t *u;
@@ -1746,7 +1797,8 @@ static ngx_int_t ngx_http_fastcgi_process_record(ngx_http_request_t *r,
}
-static void ngx_http_fastcgi_abort_request(ngx_http_request_t *r)
+static void
+ngx_http_fastcgi_abort_request(ngx_http_request_t *r)
{
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"abort http fastcgi request");
@@ -1755,8 +1807,8 @@ static void ngx_http_fastcgi_abort_request(ngx_http_request_t *r)
}
-static void ngx_http_fastcgi_finalize_request(ngx_http_request_t *r,
- ngx_int_t rc)
+static void
+ngx_http_fastcgi_finalize_request(ngx_http_request_t *r, ngx_int_t rc)
{
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"finalize http fastcgi request");
@@ -1765,8 +1817,8 @@ static void ngx_http_fastcgi_finalize_request(ngx_http_request_t *r,
}
-static char *ngx_http_fastcgi_pass(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf)
+static char *
+ngx_http_fastcgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_http_fastcgi_loc_conf_t *lcf = conf;
@@ -1829,8 +1881,8 @@ static char *ngx_http_fastcgi_pass(ngx_conf_t *cf, ngx_command_t *cmd,
}
-static char *ngx_http_fastcgi_set_var(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf)
+static char *
+ngx_http_fastcgi_set_var(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_http_fastcgi_loc_conf_t *lcf = conf;
@@ -1839,10 +1891,10 @@ static char *ngx_http_fastcgi_set_var(ngx_conf_t *cf, ngx_command_t *cmd,
ngx_http_variable_t *var;
ngx_http_core_main_conf_t *cmcf;
- if (lcf->vars.elts == NULL) {
- if (ngx_array_init(&lcf->vars, cf->pool, 4,
- sizeof(ngx_http_variable_t *)) == NGX_ERROR)
- {
+ if (lcf->vars == NULL) {
+ lcf->vars = ngx_array_create(cf->pool, 4,
+ sizeof(ngx_http_variable_t *));
+ if (lcf->vars == NULL) {
return NGX_CONF_ERROR;
}
}
@@ -1855,7 +1907,7 @@ static char *ngx_http_fastcgi_set_var(ngx_conf_t *cf, ngx_command_t *cmd,
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))) {
+ if (!(index = ngx_array_push(lcf->vars))) {
return NGX_CONF_ERROR;
}
@@ -1870,8 +1922,8 @@ static char *ngx_http_fastcgi_set_var(ngx_conf_t *cf, ngx_command_t *cmd,
}
-static char *ngx_http_fastcgi_lowat_check(ngx_conf_t *cf, void *post,
- void *data)
+static char *
+ngx_http_fastcgi_lowat_check(ngx_conf_t *cf, void *post, void *data)
{
#if (NGX_FREEBSD)
ssize_t *np = data;
@@ -1899,7 +1951,8 @@ static char *ngx_http_fastcgi_lowat_check(ngx_conf_t *cf, void *post,
}
-static void *ngx_http_fastcgi_create_loc_conf(ngx_conf_t *cf)
+static void *
+ngx_http_fastcgi_create_loc_conf(ngx_conf_t *cf)
{
ngx_http_fastcgi_loc_conf_t *conf;
@@ -1933,6 +1986,7 @@ static void *ngx_http_fastcgi_create_loc_conf(ngx_conf_t *cf)
conf->upstream.max_temp_file_size = NGX_CONF_UNSET_SIZE;
conf->upstream.temp_file_write_size = NGX_CONF_UNSET_SIZE;
+ conf->upstream.redirect_errors = NGX_CONF_UNSET;
conf->upstream.x_powered_by = NGX_CONF_UNSET;
/* "fastcgi_cyclic_temp_file" is disabled */
@@ -1942,8 +1996,8 @@ static void *ngx_http_fastcgi_create_loc_conf(ngx_conf_t *cf)
}
-static char *ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf,
- void *parent, void *child)
+static char *
+ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
{
ngx_http_fastcgi_loc_conf_t *prev = parent;
ngx_http_fastcgi_loc_conf_t *conf = child;
@@ -1960,6 +2014,9 @@ static char *ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf,
ngx_conf_merge_msec_value(conf->upstream.read_timeout,
prev->upstream.read_timeout, 60000);
+ ngx_conf_merge_msec_value(conf->upstream.redirect_errors,
+ prev->upstream.redirect_errors, 0);
+
ngx_conf_merge_msec_value(conf->upstream.x_powered_by,
prev->upstream.x_powered_by, 1);
@@ -2049,10 +2106,10 @@ static char *ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf,
ngx_conf_merge_bitmask_value(conf->upstream.next_upstream,
- prev->upstream.next_upstream,
- (NGX_CONF_BITMASK_SET
- |NGX_HTTP_UPSTREAM_FT_ERROR
- |NGX_HTTP_UPSTREAM_FT_TIMEOUT));
+ prev->upstream.next_upstream,
+ (NGX_CONF_BITMASK_SET
+ |NGX_HTTP_UPSTREAM_FT_ERROR
+ |NGX_HTTP_UPSTREAM_FT_TIMEOUT));
ngx_conf_merge_path_value(conf->upstream.temp_path,
prev->upstream.temp_path,
@@ -2061,15 +2118,15 @@ static char *ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf,
ngx_conf_merge_bitmask_value(conf->params, prev->params,
- (NGX_CONF_BITMASK_SET
- |NGX_HTTP_FASTCGI_REMOTE_ADDR
- |NGX_HTTP_FASTCGI_REMOTE_USER
- |NGX_HTTP_FASTCGI_SERVER_NAME
- |NGX_HTTP_FASTCGI_SERVER_PORT
- |NGX_HTTP_FASTCGI_SCRIPT_NAME
- |NGX_HTTP_FASTCGI_AUTH_TYPE
- |NGX_HTTP_FASTCGI_REQUEST_URI
- |NGX_HTTP_FASTCGI_REDIRECT_STATUS));
+ (NGX_CONF_BITMASK_SET
+ |NGX_HTTP_FASTCGI_REMOTE_ADDR
+ |NGX_HTTP_FASTCGI_REMOTE_USER
+ |NGX_HTTP_FASTCGI_SERVER_NAME
+ |NGX_HTTP_FASTCGI_SERVER_PORT
+ |NGX_HTTP_FASTCGI_SCRIPT_NAME
+ |NGX_HTTP_FASTCGI_AUTH_TYPE
+ |NGX_HTTP_FASTCGI_REQUEST_URI
+ |NGX_HTTP_FASTCGI_REDIRECT_STATUS));
ngx_conf_merge_str_value(conf->root, prev->root, "");
@@ -2079,5 +2136,9 @@ static char *ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf,
ngx_conf_merge_str_value(conf->index, prev->index, "");
+ if (conf->vars == NULL) {
+ conf->vars = prev->vars;
+ }
+
return NGX_CONF_OK;
}
diff --git a/src/http/modules/ngx_http_geo_module.c b/src/http/modules/ngx_http_geo_module.c
index cd774894c..7d17f03ca 100644
--- a/src/http/modules/ngx_http_geo_module.c
+++ b/src/http/modules/ngx_http_geo_module.c
@@ -91,7 +91,7 @@ static char *ngx_http_geo_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
return NGX_CONF_ERROR;
}
- if (!(tree = ngx_radix_tree_create(cf->pool))) {
+ if (!(tree = ngx_radix_tree_create(cf->pool, 8))) {
return NGX_CONF_ERROR;
}
diff --git a/src/http/modules/ngx_http_rewrite_handler.c b/src/http/modules/ngx_http_rewrite_handler.c
index b1f591c97..d3c721fda 100644
--- a/src/http/modules/ngx_http_rewrite_handler.c
+++ b/src/http/modules/ngx_http_rewrite_handler.c
@@ -47,6 +47,7 @@ typedef struct {
uintptr_t args:1;
uintptr_t redirect:1;
+ uintptr_t break_cycle:1;
ngx_str_t name;
} ngx_http_rewrite_regex_code_t;
@@ -121,18 +122,18 @@ struct ngx_http_rewrite_engine_s {
static ngx_int_t ngx_http_rewrite_init(ngx_cycle_t *cycle);
static void *ngx_http_rewrite_create_loc_conf(ngx_conf_t *cf);
static char *ngx_http_rewrite_merge_loc_conf(ngx_conf_t *cf,
- void *parent, void *child);
+ void *parent, void *child);
static char *ngx_http_rewrite(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
static char *ngx_http_rewrite_return(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf);
+ void *conf);
static char *ngx_http_rewrite_if(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf);
-static char *ngx_http_rewrite_valid_referers(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf);
+ void *conf);
+static char *ngx_http_rewrite_valid_referers(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);
+ ngx_array_t **codes, size_t size);
static void *ngx_http_rewrite_add_code(ngx_array_t *codes, size_t size,
- u_char **main);
+ void *code);
static ngx_command_t ngx_http_rewrite_commands[] = {
@@ -208,7 +209,8 @@ ngx_module_t ngx_http_rewrite_module = {
uintptr_t ngx_http_rewrite_exit_code = (uintptr_t) NULL;
-static ngx_int_t ngx_http_rewrite_handler(ngx_http_request_t *r)
+static ngx_int_t
+ngx_http_rewrite_handler(ngx_http_request_t *r)
{
ngx_http_rewrite_code_pt code;
ngx_http_rewrite_engine_t *e;
@@ -259,7 +261,8 @@ static ngx_int_t ngx_http_rewrite_handler(ngx_http_request_t *r)
}
-static void ngx_http_rewrite_regex_start_code(ngx_http_rewrite_engine_t *e)
+static void
+ngx_http_rewrite_regex_start_code(ngx_http_rewrite_engine_t *e)
{
ngx_int_t rc;
ngx_uint_t n;
@@ -318,7 +321,9 @@ static void ngx_http_rewrite_regex_start_code(ngx_http_rewrite_engine_t *e)
e->buf.len = code->size;
if (code->uri) {
- r->uri_changed = 1;
+ if (!code->break_cycle) {
+ r->uri_changed = 1;
+ }
if (rc && (r->quoted_uri || r->plus_in_uri)) {
e->buf.len += 2 * ngx_escape_uri(NULL, r->uri.data, r->uri.len,
@@ -348,7 +353,8 @@ static void ngx_http_rewrite_regex_start_code(ngx_http_rewrite_engine_t *e)
}
-static void ngx_http_rewrite_regex_end_code(ngx_http_rewrite_engine_t *e)
+static void
+ngx_http_rewrite_regex_end_code(ngx_http_rewrite_engine_t *e)
{
ngx_http_request_t *r;
ngx_http_rewrite_regex_end_code_t *code;
@@ -377,7 +383,7 @@ static void ngx_http_rewrite_regex_end_code(ngx_http_rewrite_engine_t *e)
} else {
if (code->args && r->args.len) {
- *e->pos++ = '&';
+ *e->pos++ = '?';
e->pos = ngx_cpymem(e->pos, r->args.data, r->args.len);
}
@@ -425,7 +431,8 @@ static void ngx_http_rewrite_regex_end_code(ngx_http_rewrite_engine_t *e)
}
-static void ngx_http_rewrite_copy_capture_code(ngx_http_rewrite_engine_t *e)
+static void
+ngx_http_rewrite_copy_capture_code(ngx_http_rewrite_engine_t *e)
{
ngx_http_rewrite_copy_capture_code_t *code;
@@ -450,7 +457,8 @@ static void ngx_http_rewrite_copy_capture_code(ngx_http_rewrite_engine_t *e)
}
-static void ngx_http_rewrite_copy_code(ngx_http_rewrite_engine_t *e)
+static void
+ngx_http_rewrite_copy_code(ngx_http_rewrite_engine_t *e)
{
ngx_http_rewrite_copy_code_t *code;
@@ -467,7 +475,8 @@ static void ngx_http_rewrite_copy_code(ngx_http_rewrite_engine_t *e)
}
-static void ngx_http_rewrite_start_args_code(ngx_http_rewrite_engine_t *e)
+static void
+ngx_http_rewrite_start_args_code(ngx_http_rewrite_engine_t *e)
{
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
"http rewrite args");
@@ -477,7 +486,8 @@ static void ngx_http_rewrite_start_args_code(ngx_http_rewrite_engine_t *e)
}
-static void ngx_http_rewrite_return_code(ngx_http_rewrite_engine_t *e)
+static void
+ngx_http_rewrite_return_code(ngx_http_rewrite_engine_t *e)
{
ngx_http_rewrite_return_code_t *code;
@@ -489,7 +499,8 @@ static void ngx_http_rewrite_return_code(ngx_http_rewrite_engine_t *e)
}
-static void ngx_http_rewrite_if_code(ngx_http_rewrite_engine_t *e)
+static void
+ngx_http_rewrite_if_code(ngx_http_rewrite_engine_t *e)
{
ngx_http_rewrite_if_code_t *code;
@@ -514,7 +525,8 @@ static void ngx_http_rewrite_if_code(ngx_http_rewrite_engine_t *e)
}
-static void ngx_http_rewrite_var_code(ngx_http_rewrite_engine_t *e)
+static void
+ngx_http_rewrite_var_code(ngx_http_rewrite_engine_t *e)
{
ngx_http_variable_value_t *value;
ngx_http_rewrite_var_code_t *code;
@@ -540,7 +552,8 @@ static void ngx_http_rewrite_var_code(ngx_http_rewrite_engine_t *e)
}
-static void ngx_http_rewrite_invalid_referer_code(ngx_http_rewrite_engine_t *e)
+static void
+ngx_http_rewrite_invalid_referer_code(ngx_http_rewrite_engine_t *e)
{
u_char *ref;
size_t len;
@@ -625,13 +638,15 @@ static void ngx_http_rewrite_invalid_referer_code(ngx_http_rewrite_engine_t *e)
}
-static void ngx_http_rewrite_nop_code(ngx_http_rewrite_engine_t *e)
+static void
+ngx_http_rewrite_nop_code(ngx_http_rewrite_engine_t *e)
{
e->ip += sizeof(uintptr_t);
}
-static ngx_int_t ngx_http_rewrite_init(ngx_cycle_t *cycle)
+static ngx_int_t
+ngx_http_rewrite_init(ngx_cycle_t *cycle)
{
ngx_http_handler_pt *h;
ngx_http_core_main_conf_t *cmcf;
@@ -649,7 +664,8 @@ static ngx_int_t ngx_http_rewrite_init(ngx_cycle_t *cycle)
}
-static void *ngx_http_rewrite_create_loc_conf(ngx_conf_t *cf)
+static void *
+ngx_http_rewrite_create_loc_conf(ngx_conf_t *cf)
{
ngx_http_rewrite_loc_conf_t *conf;
@@ -665,8 +681,8 @@ static void *ngx_http_rewrite_create_loc_conf(ngx_conf_t *cf)
}
-static char *ngx_http_rewrite_merge_loc_conf(ngx_conf_t *cf,
- void *parent, void *child)
+static char *
+ngx_http_rewrite_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
{
ngx_http_rewrite_loc_conf_t *prev = parent;
ngx_http_rewrite_loc_conf_t *conf = child;
@@ -737,7 +753,8 @@ static char *ngx_http_rewrite_merge_loc_conf(ngx_conf_t *cf,
}
-static char *ngx_http_rewrite(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
+static char *
+ngx_http_rewrite(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_http_rewrite_loc_conf_t *lcf = conf;
@@ -793,6 +810,10 @@ static char *ngx_http_rewrite(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
if (ngx_strcmp(value[3].data, "last") == 0) {
last = 1;
+ } else if (ngx_strcmp(value[3].data, "break") == 0) {
+ regex->break_cycle = 1;
+ last = 1;
+
} else if (ngx_strcmp(value[3].data, "redirect") == 0) {
regex->status = NGX_HTTP_MOVED_TEMPORARILY;
regex->redirect = 1;
@@ -824,7 +845,7 @@ static char *ngx_http_rewrite(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
copy_capture = ngx_http_rewrite_add_code(lcf->codes,
sizeof(ngx_http_rewrite_copy_capture_code_t),
- (u_char **) &regex);
+ &regex);
if (copy_capture == NULL) {
return NGX_CONF_ERROR;
}
@@ -857,7 +878,7 @@ static char *ngx_http_rewrite(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
if (!regex->redirect) {
code = ngx_http_rewrite_add_code(lcf->codes, sizeof(uintptr_t),
- (u_char **) &regex);
+ &regex);
if (code == NULL) {
return NGX_CONF_ERROR;
}
@@ -907,7 +928,7 @@ static char *ngx_http_rewrite(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
copy = ngx_http_rewrite_add_code(lcf->codes,
sizeof(ngx_http_rewrite_copy_code_t) + size,
- (u_char **) &regex);
+ &regex);
if (copy == NULL) {
return NGX_CONF_ERROR;
}
@@ -939,7 +960,7 @@ static char *ngx_http_rewrite(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
regex_end = ngx_http_rewrite_add_code(lcf->codes,
sizeof(ngx_http_rewrite_regex_end_code_t),
- (u_char **) &regex);
+ &regex);
if (regex_end == NULL) {
return NGX_CONF_ERROR;
}
@@ -951,7 +972,7 @@ static char *ngx_http_rewrite(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
if (last) {
code = ngx_http_rewrite_add_code(lcf->codes, sizeof(uintptr_t),
- (u_char **) &regex);
+ &regex);
if (code == NULL) {
return NGX_CONF_ERROR;
}
@@ -966,9 +987,8 @@ static char *ngx_http_rewrite(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
}
-
-static char *ngx_http_rewrite_return(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf)
+static char *
+ngx_http_rewrite_return(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_http_rewrite_loc_conf_t *lcf = conf;
@@ -996,7 +1016,8 @@ static char *ngx_http_rewrite_return(ngx_conf_t *cf, ngx_command_t *cmd,
}
-static char *ngx_http_rewrite_if(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
+static char *
+ngx_http_rewrite_if(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_http_rewrite_loc_conf_t *lcf = conf;
@@ -1179,8 +1200,8 @@ static char *ngx_http_rewrite_if(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
}
-static char *ngx_http_rewrite_valid_referers(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf)
+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;
@@ -1266,8 +1287,8 @@ static char *ngx_http_rewrite_valid_referers(ngx_conf_t *cf, ngx_command_t *cmd,
}
-static void *ngx_http_rewrite_start_code(ngx_pool_t *pool,
- ngx_array_t **codes, size_t size)
+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))) {
@@ -1279,10 +1300,10 @@ static void *ngx_http_rewrite_start_code(ngx_pool_t *pool,
}
-static void *ngx_http_rewrite_add_code(ngx_array_t *codes, size_t size,
- u_char **main)
+static void *
+ngx_http_rewrite_add_code(ngx_array_t *codes, size_t size, void *code)
{
- u_char *elts;
+ u_char *elts, **p;
void *new;
elts = codes->elts;
@@ -1292,7 +1313,8 @@ static void *ngx_http_rewrite_add_code(ngx_array_t *codes, size_t size,
}
if (elts != codes->elts) {
- *main += (u_char *) codes->elts - elts;
+ p = code;
+ *p += (u_char *) codes->elts - elts;
}
return new;
diff --git a/src/http/modules/ngx_http_stub_status_module.c b/src/http/modules/ngx_http_stub_status_module.c
new file mode 100644
index 000000000..3a35fe910
--- /dev/null
+++ b/src/http/modules/ngx_http_stub_status_module.c
@@ -0,0 +1,138 @@
+
+#include <ngx_config.h>
+#include <ngx_core.h>
+#include <ngx_http.h>
+
+
+static char *ngx_http_set_status(ngx_conf_t *cf, ngx_command_t *cmd,
+ void *conf);
+
+static ngx_command_t ngx_http_status_commands[] = {
+
+ { ngx_string("stub_status"),
+ NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
+ ngx_http_set_status,
+ 0,
+ 0,
+ NULL },
+
+ ngx_null_command
+};
+
+
+
+ngx_http_module_t ngx_http_stub_status_module_ctx = {
+ NULL, /* pre conf */
+
+ 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_stub_status_module = {
+ NGX_MODULE,
+ &ngx_http_stub_status_module_ctx, /* module context */
+ ngx_http_status_commands, /* module directives */
+ NGX_HTTP_MODULE, /* module type */
+ NULL, /* init module */
+ NULL /* init process */
+};
+
+
+static ngx_int_t ngx_http_status_handler(ngx_http_request_t *r)
+{
+ size_t size;
+ ngx_int_t rc;
+ uint32_t ap, hn, ac, rq, rd, wr;
+ ngx_buf_t *b;
+ ngx_chain_t out;
+
+ if (r->method != NGX_HTTP_GET && r->method != NGX_HTTP_HEAD) {
+ return NGX_HTTP_NOT_ALLOWED;
+ }
+
+ rc = ngx_http_discard_body(r);
+
+ if (rc != NGX_OK && rc != NGX_AGAIN) {
+ return rc;
+ }
+
+ r->headers_out.content_type = ngx_list_push(&r->headers_out.headers);
+ if (r->headers_out.content_type == NULL) {
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;
+ }
+
+ r->headers_out.content_type->key.len = 0;
+ r->headers_out.content_type->key.data = NULL;
+ r->headers_out.content_type->value.len = sizeof("text/plain") - 1;
+ r->headers_out.content_type->value.data = (u_char *) "text/plain";
+
+ if (r->method == NGX_HTTP_HEAD) {
+ r->headers_out.status = NGX_HTTP_OK;
+
+ rc = ngx_http_send_header(r);
+
+ if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {
+ return rc;
+ }
+ }
+
+ size = sizeof("Active connections: \n") + NGX_INT32_LEN
+ + sizeof("server accepts handled requests\n") - 1
+ + 6 + 3 * NGX_INT32_LEN
+ + sizeof("Reading: Writing: Waiting: \n") + 3 * NGX_INT32_LEN;
+
+ if (!(b = ngx_create_temp_buf(r->pool, size))) {
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;
+ }
+
+ out.buf = b;
+ out.next = NULL;
+
+ ap = *ngx_stat_accepted;
+ hn = *ngx_connection_counter;
+ ac = *ngx_stat_active;
+ rq = *ngx_stat_requests;
+ rd = *ngx_stat_reading;
+ wr = *ngx_stat_writing;
+
+ b->last = ngx_sprintf(b->last, "Active connections: %d \n", ac);
+
+ b->last = ngx_cpymem(b->last, "server accepts handled requests\n",
+ sizeof("server accepts handled requests\n") - 1);
+
+ b->last = ngx_sprintf(b->last, " %d %d %d \n", ap, hn, rq);
+
+ b->last = ngx_sprintf(b->last, "Reading: %d Writing: %d Waiting: %d \n",
+ rd, wr, ac - (rd + wr));
+
+ r->headers_out.status = NGX_HTTP_OK;
+ r->headers_out.content_length_n = b->last - b->pos;
+
+ b->last_buf = 1;
+
+ rc = ngx_http_send_header(r);
+
+ if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {
+ return rc;
+ }
+
+ return ngx_http_output_filter(r, &out);;
+}
+
+
+static char *ngx_http_set_status(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
+{
+ ngx_http_core_loc_conf_t *clcf;
+
+ clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
+ clcf->handler = ngx_http_status_handler;
+
+ return NGX_CONF_OK;
+}
diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.c b/src/http/modules/proxy/ngx_http_proxy_handler.c
index a195b45e4..d213d6929 100644
--- a/src/http/modules/proxy/ngx_http_proxy_handler.c
+++ b/src/http/modules/proxy/ngx_http_proxy_handler.c
@@ -1284,6 +1284,10 @@ static char *ngx_http_proxy_merge_loc_conf(ngx_conf_t *cf,
ngx_conf_merge_value(conf->lm_factor, prev->lm_factor, 0);
ngx_conf_merge_sec_value(conf->default_expires, prev->default_expires, 0);
+ if (conf->x_vars == NULL) {
+ conf->x_vars = prev->x_vars;
+ }
+
return NULL;
}
@@ -1389,10 +1393,10 @@ static char *ngx_http_proxy_set_x_var(ngx_conf_t *cf, ngx_command_t *cmd,
ngx_http_variable_t *var;
ngx_http_core_main_conf_t *cmcf;
- if (lcf->x_vars.elts == NULL) {
- if (ngx_array_init(&lcf->x_vars, cf->pool, 4,
- sizeof(ngx_http_variable_t *)) == NGX_ERROR)
- {
+ if (lcf->x_vars == NULL) {
+ lcf->x_vars = ngx_array_create(cf->pool, 4,
+ sizeof(ngx_http_variable_t *));
+ if (lcf->x_vars == NULL) {
return NGX_CONF_ERROR;
}
}
@@ -1405,7 +1409,7 @@ static char *ngx_http_proxy_set_x_var(ngx_conf_t *cf, ngx_command_t *cmd,
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))) {
+ if (!(index = ngx_array_push(lcf->x_vars))) {
return NGX_CONF_ERROR;
}
diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.h b/src/http/modules/proxy/ngx_http_proxy_handler.h
index 28d7971df..f950258dc 100644
--- a/src/http/modules/proxy/ngx_http_proxy_handler.h
+++ b/src/http/modules/proxy/ngx_http_proxy_handler.h
@@ -87,7 +87,7 @@ typedef struct {
ngx_path_t *cache_path;
ngx_path_t *temp_path;
- ngx_array_t x_vars;
+ ngx_array_t *x_vars;
ngx_http_busy_lock_t *busy_lock;
diff --git a/src/http/modules/proxy/ngx_http_proxy_upstream.c b/src/http/modules/proxy/ngx_http_proxy_upstream.c
index cf5195368..e2fe01554 100644
--- a/src/http/modules/proxy/ngx_http_proxy_upstream.c
+++ b/src/http/modules/proxy/ngx_http_proxy_upstream.c
@@ -100,6 +100,11 @@ static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p)
r = p->request;
uc = p->lcf->upstream;
+#if (NGX_SUPPRESS_WARN)
+ var = NULL;
+ index = NULL;
+#endif
+
if (p->upstream->method) {
len = http_methods[p->upstream->method - 1].len;
@@ -169,20 +174,22 @@ static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p)
}
- cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
+ if (p->lcf->x_vars) {
+ cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
- var = cmcf->variables.elts;
- index = p->lcf->x_vars.elts;
+ var = cmcf->variables.elts;
+ index = p->lcf->x_vars->elts;
- for (i = 0; i < p->lcf->x_vars.nelts; i++) {
+ for (i = 0; i < p->lcf->x_vars->nelts; i++) {
- if (!(value = ngx_http_get_variable(r, index[i]))) {
- continue;
- }
+ if (!(value = ngx_http_get_variable(r, index[i]))) {
+ continue;
+ }
- if (value->text.len) {
- len += sizeof("X-") - 1 + var[index[i]].name.len + sizeof(": ") - 1
- + value->text.len + sizeof(CRLF) - 1;
+ if (value->text.len) {
+ len += sizeof("X-") - 1 + var[index[i]].name.len
+ + sizeof(": ") - 1 + value->text.len + sizeof(CRLF) - 1;
+ }
}
}
@@ -356,26 +363,28 @@ static ngx_chain_t *ngx_http_proxy_create_request(ngx_http_proxy_ctx_t *p)
}
- for (i = 0; i < p->lcf->x_vars.nelts; i++) {
+ if (p->lcf->x_vars) {
+ for (i = 0; i < p->lcf->x_vars->nelts; i++) {
- if (!(value = ngx_http_get_variable(r, index[i]))) {
- continue;
- }
+ if (!(value = ngx_http_get_variable(r, index[i]))) {
+ continue;
+ }
- if (value->text.len == 0) {
- continue;
- }
+ if (value->text.len == 0) {
+ continue;
+ }
- *b->last++ = 'X'; *b->last++ = '-';
+ *b->last++ = 'X'; *b->last++ = '-';
- b->last = ngx_cpymem(b->last, var[index[i]].name.data,
- var[index[i]].name.len);
+ b->last = ngx_cpymem(b->last, var[index[i]].name.data,
+ var[index[i]].name.len);
- *b->last++ = ':'; *b->last++ = ' ';
+ *b->last++ = ':'; *b->last++ = ' ';
- b->last = ngx_cpymem(b->last, value->text.data, value->text.len);
+ b->last = ngx_cpymem(b->last, value->text.data, value->text.len);
- *b->last++ = CR; *b->last++ = LF;
+ *b->last++ = CR; *b->last++ = LF;
+ }
}