summaryrefslogtreecommitdiffhomepage
path: root/src/http
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2005-11-15 13:30:52 +0000
committerIgor Sysoev <igor@sysoev.ru>2005-11-15 13:30:52 +0000
commit0e5dc5cff692f532f0ccb2655ab196995f4233e0 (patch)
treef56f40e788077b9820ebb45f3e0739fabb7be421 /src/http
parent2a7f83eceda87e520f36bbfb16b82b8c2d6606d7 (diff)
downloadnginx-release-0.3.10.tar.gz
nginx-release-0.3.10.tar.bz2
nginx-0.3.10-RELEASE importrelease-0.3.10
*) Change: the "valid_referers" directive and the "$invalid_referer" variable were moved to the new ngx_http_referer_module from the ngx_http_rewrite_module. *) Change: the "$apache_bytes_sent" variable name was changed to "$body_bytes_sent". *) Feature: the "$sent_http_..." variables. *) Feature: the "if" directive supports the "=" and "!=" operations. *) Feature: the "proxy_pass" directive supports the HTTPS protocol. *) Feature: the "proxy_set_body" directive. *) Feature: the "post_action" directive. *) Feature: the ngx_http_empty_gif_module. *) Feature: the "worker_cpu_affinity" directive for Linux. *) Bugfix: the "rewrite" directive did not unescape URI part in redirect, now it is unescaped except the %00-%25 and %7F-%FF characters. *) Bugfix: nginx could not be built by the icc 9.0 compiler. *) Bugfix: if the SSI was enabled for zero size static file, then the chunked response was encoded incorrectly.
Diffstat (limited to 'src/http')
-rw-r--r--src/http/modules/ngx_http_autoindex_module.c10
-rw-r--r--src/http/modules/ngx_http_empty_gif_module.c173
-rw-r--r--src/http/modules/ngx_http_fastcgi_module.c22
-rw-r--r--src/http/modules/ngx_http_geo_module.c7
-rw-r--r--src/http/modules/ngx_http_gzip_filter_module.c15
-rw-r--r--src/http/modules/ngx_http_headers_filter_module.c4
-rw-r--r--src/http/modules/ngx_http_index_module.c2
-rw-r--r--src/http/modules/ngx_http_log_module.c22
-rw-r--r--src/http/modules/ngx_http_not_modified_filter_module.c9
-rw-r--r--src/http/modules/ngx_http_proxy_module.c267
-rw-r--r--src/http/modules/ngx_http_range_filter_module.c8
-rw-r--r--src/http/modules/ngx_http_referer_module.c309
-rw-r--r--src/http/modules/ngx_http_rewrite_module.c493
-rw-r--r--src/http/modules/ngx_http_ssi_filter_module.c26
-rw-r--r--src/http/modules/ngx_http_static_module.c50
-rw-r--r--src/http/modules/ngx_http_status_module.c4
-rw-r--r--src/http/modules/ngx_http_stub_status_module.c17
-rw-r--r--src/http/modules/ngx_http_userid_filter_module.c6
-rw-r--r--src/http/ngx_http.c6
-rw-r--r--src/http/ngx_http_core_module.c47
-rw-r--r--src/http/ngx_http_core_module.h50
-rw-r--r--src/http/ngx_http_parse.c2
-rw-r--r--src/http/ngx_http_request.c43
-rw-r--r--src/http/ngx_http_request.h8
-rw-r--r--src/http/ngx_http_request_body.c1
-rw-r--r--src/http/ngx_http_script.c94
-rw-r--r--src/http/ngx_http_script.h4
-rw-r--r--src/http/ngx_http_special_response.c3
-rw-r--r--src/http/ngx_http_upstream.c184
-rw-r--r--src/http/ngx_http_upstream.h5
-rw-r--r--src/http/ngx_http_variables.c73
-rw-r--r--src/http/ngx_http_variables.h4
32 files changed, 1333 insertions, 635 deletions
diff --git a/src/http/modules/ngx_http_autoindex_module.c b/src/http/modules/ngx_http_autoindex_module.c
index 3623e2a5f..8a048070e 100644
--- a/src/http/modules/ngx_http_autoindex_module.c
+++ b/src/http/modules/ngx_http_autoindex_module.c
@@ -98,7 +98,7 @@ ngx_http_module_t ngx_http_autoindex_module_ctx = {
ngx_module_t ngx_http_autoindex_module = {
NGX_MODULE_V1,
- &ngx_http_autoindex_module_ctx, /* module context */
+ &ngx_http_autoindex_module_ctx, /* module context */
ngx_http_autoindex_commands, /* module directives */
NGX_HTTP_MODULE, /* module type */
NULL, /* init master */
@@ -248,7 +248,7 @@ ngx_http_autoindex_handler(ngx_http_request_t *r)
return ngx_http_autoindex_error(r, &dir, &path);
}
- break;
+ break;
}
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
@@ -302,7 +302,7 @@ ngx_http_autoindex_handler(ngx_http_request_t *r)
return ngx_http_autoindex_error(r, &dir, &path);
}
- entry->name.len = len;
+ entry->name.len = len;
entry->name.data = ngx_palloc(pool, len + 1);
if (entry->name.data == NULL) {
@@ -446,7 +446,7 @@ ngx_http_autoindex_handler(ngx_http_request_t *r)
sizeof(" -") - 1);
} else {
b->last = ngx_sprintf(b->last, "%19O", entry[i].size);
- }
+ }
} else {
if (entry[i].dir) {
@@ -460,7 +460,7 @@ ngx_http_autoindex_handler(ngx_http_request_t *r)
size = (ngx_int_t) (length / (1024 * 1024 * 1024));
if ((length % (1024 * 1024 * 1024))
> (1024 * 1024 * 1024 / 2 - 1))
- {
+ {
size++;
}
scale = 'G';
diff --git a/src/http/modules/ngx_http_empty_gif_module.c b/src/http/modules/ngx_http_empty_gif_module.c
new file mode 100644
index 000000000..5c9a415c7
--- /dev/null
+++ b/src/http/modules/ngx_http_empty_gif_module.c
@@ -0,0 +1,173 @@
+
+/*
+ * Copyright (C) Igor Sysoev
+ */
+
+#include <ngx_config.h>
+#include <ngx_core.h>
+#include <ngx_http.h>
+
+
+static char *ngx_http_empty_gif(ngx_conf_t *cf, ngx_command_t *cmd,
+ void *conf);
+
+static ngx_command_t ngx_http_empty_gif_commands[] = {
+
+ { ngx_string("empty_gif"),
+ NGX_HTTP_LOC_CONF|NGX_CONF_NOARGS,
+ ngx_http_empty_gif,
+ 0,
+ 0,
+ NULL },
+
+ ngx_null_command
+};
+
+
+/* the minimal single pixel transparent GIF, 43 bytes */
+
+static u_char ngx_empty_gif[] = {
+
+ 'G', 'I', 'F', '8', '9', 'a', /* header */
+
+ /* logical screen descriptor */
+ 0x01, 0x00, /* logical screen width */
+ 0x01, 0x00, /* logical screen height */
+ 0x80, /* global 1-bit color table */
+ 0x01, /* background color #1 */
+ 0x00, /* no aspect ratio */
+
+ /* global color table */
+ 0x00, 0x00, 0x00, /* #0: black */
+ 0xff, 0xff, 0xff, /* #1: white */
+
+ /* graphic control extension */
+ 0x21, /* extension introducer */
+ 0xf9, /* graphic control label */
+ 0x04, /* block size */
+ 0x01, /* transparent color is given, */
+ /* no disposal specified, */
+ /* user input is not expected */
+ 0x00, 0x00, /* delay time */
+ 0x01, /* transparent color #1 */
+ 0x00, /* block terminator */
+
+ /* image descriptor */
+ 0x2c, /* image separator */
+ 0x00, 0x00, /* image left position */
+ 0x00, 0x00, /* image top position */
+ 0x01, 0x00, /* image width */
+ 0x01, 0x00, /* image height */
+ 0x00, /* no local color table, no interlaced */
+
+ /* table based image data */
+ 0x02, /* LZW minimum code size, */
+ /* must be at least 2-bit */
+ 0x02, /* block size */
+ 0x4c, 0x01, /* compressed bytes 01_001_100, 0000000_1 */
+ /* 100: clear code */
+ /* 001: 1 */
+ /* 101: end of information code */
+ 0x00, /* block terminator */
+
+ 0x3B /* trailer */
+};
+
+
+ngx_http_module_t ngx_http_empty_gif_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_empty_gif_module = {
+ NGX_MODULE_V1,
+ &ngx_http_empty_gif_module_ctx, /* module context */
+ ngx_http_empty_gif_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_empty_gif_handler(ngx_http_request_t *r)
+{
+ ngx_int_t rc;
+ 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.len = sizeof("image/gif") - 1;
+ r->headers_out.content_type.data = (u_char *) "image/gif";
+
+ 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;
+ }
+ }
+
+ b = ngx_create_temp_buf(r->pool, sizeof(ngx_empty_gif));
+ if (b == NULL) {
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;
+ }
+
+ out.buf = b;
+ out.next = NULL;
+
+ b->pos = ngx_empty_gif;
+ b->last = ngx_empty_gif + sizeof(ngx_empty_gif);
+ b->last_buf = 1;
+
+ r->headers_out.status = NGX_HTTP_OK;
+ r->headers_out.content_length_n = b->last - b->pos;
+ r->headers_out.last_modified_time = 23349600;
+
+ 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_empty_gif(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_empty_gif_handler;
+
+ return NGX_CONF_OK;
+}
diff --git a/src/http/modules/ngx_http_fastcgi_module.c b/src/http/modules/ngx_http_fastcgi_module.c
index 160aacbc3..5d2c153e2 100644
--- a/src/http/modules/ngx_http_fastcgi_module.c
+++ b/src/http/modules/ngx_http_fastcgi_module.c
@@ -556,9 +556,9 @@ ngx_http_fastcgi_create_request(ngx_http_request_t *r)
if (i >= part->nelts) {
if (part->next == NULL) {
- break;
+ break;
}
-
+
part = part->next;
header = part->elts;
i = 0;
@@ -570,7 +570,7 @@ ngx_http_fastcgi_create_request(ngx_http_request_t *r)
*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;
}
@@ -876,7 +876,7 @@ ngx_http_fastcgi_process_header(ngx_http_request_t *r)
f->length = 0;
f->state = ngx_http_fastcgi_st_padding;
- } else {
+ } else {
line.len = u->header_in.last - u->header_in.pos;
f->length -= u->header_in.last - u->header_in.pos;
u->header_in.pos = u->header_in.last;
@@ -1145,7 +1145,7 @@ ngx_http_fastcgi_input_filter(ngx_event_pipe_t *p, ngx_buf_t *buf)
f->length = 0;
f->state = ngx_http_fastcgi_st_padding;
- } else {
+ } else {
line.len = f->last - f->pos;
f->length -= f->last - f->pos;
f->pos = f->last;
@@ -1447,7 +1447,7 @@ ngx_http_fastcgi_create_loc_conf(ngx_conf_t *cf)
conf->upstream.header_buffer_size = NGX_CONF_UNSET_SIZE;
conf->upstream.busy_buffers_size_conf = NGX_CONF_UNSET_SIZE;
- conf->upstream.max_temp_file_size_conf = NGX_CONF_UNSET_SIZE;
+ conf->upstream.max_temp_file_size_conf = NGX_CONF_UNSET_SIZE;
conf->upstream.temp_file_write_size_conf = NGX_CONF_UNSET_SIZE;
conf->upstream.max_fails = NGX_CONF_UNSET_UINT;
@@ -1497,7 +1497,7 @@ ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
ngx_conf_merge_size_value(conf->upstream.send_lowat,
prev->upstream.send_lowat, 0);
- ngx_conf_merge_size_value(conf->upstream.header_buffer_size,
+ ngx_conf_merge_size_value(conf->upstream.header_buffer_size,
prev->upstream.header_buffer_size,
(size_t) ngx_pagesize);
@@ -1693,7 +1693,7 @@ ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
if (copy == NULL) {
return NGX_CONF_ERROR;
}
-
+
copy->code = ngx_http_script_copy_code;
copy->len = src[i].key.len + src[i].value.len;
@@ -1722,7 +1722,7 @@ ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
if (copy == NULL) {
return NGX_CONF_ERROR;
}
-
+
copy->code = ngx_http_script_copy_code;
copy->len = src[i].key.len;
@@ -1777,7 +1777,7 @@ ngx_http_fastcgi_script_name_variable(ngx_http_request_t *r,
u_char *p;
ngx_http_fastcgi_loc_conf_t *flcf;
- v->valid = 1;
+ v->valid = 1;
v->no_cachable = 0;
v->not_found = 0;
@@ -1850,7 +1850,7 @@ ngx_http_fastcgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
inet_upstream.name = value[1];
inet_upstream.url = value[1];
-
+
lcf->peers = ngx_inet_upstream_parse(cf, &inet_upstream);
if (lcf->peers == 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 a3638e4bf..8231de11d 100644
--- a/src/http/modules/ngx_http_geo_module.c
+++ b/src/http/modules/ngx_http_geo_module.c
@@ -64,10 +64,6 @@ ngx_module_t ngx_http_geo_module = {
};
-static ngx_http_variable_value_t ngx_http_geo_null_value =
- ngx_http_variable("");
-
-
/* AF_INET only */
static ngx_int_t
@@ -171,7 +167,8 @@ ngx_http_geo_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
}
if (ngx_radix32tree_insert(tree, 0, 0,
- (uintptr_t) &ngx_http_geo_null_value) == NGX_ERROR)
+ (uintptr_t) &ngx_http_variable_null_value)
+ == NGX_ERROR)
{
return NGX_CONF_ERROR;
}
diff --git a/src/http/modules/ngx_http_gzip_filter_module.c b/src/http/modules/ngx_http_gzip_filter_module.c
index adf7005c2..66d59358a 100644
--- a/src/http/modules/ngx_http_gzip_filter_module.c
+++ b/src/http/modules/ngx_http_gzip_filter_module.c
@@ -301,7 +301,7 @@ ngx_http_gzip_header_filter(ngx_http_request_t *r)
type = conf->types->elts;
for (i = 0; i < conf->types->nelts; i++) {
if (r->headers_out.content_type.len >= type[i].len
- && ngx_strncasecmp(r->headers_out.content_type.data,
+ && ngx_strncasecmp(r->headers_out.content_type.data,
type[i].data, type[i].len) == 0)
{
goto found;
@@ -358,15 +358,12 @@ found:
r->headers_out.content_encoding->value.data = (u_char *) "gzip";
ctx->length = r->headers_out.content_length_n;
- r->headers_out.content_length_n = -1;
-
- if (r->headers_out.content_length) {
- r->headers_out.content_length->hash = 0;
- r->headers_out.content_length = NULL;
- }
r->main_filter_need_in_memory = 1;
+ ngx_http_clear_content_length(r);
+ ngx_http_clear_accept_ranges(r);
+
return ngx_http_next_header_filter(r);
}
@@ -993,7 +990,7 @@ ngx_http_gzip_ratio_variable(ngx_http_request_t *r,
ngx_uint_t zint, zfrac;
ngx_http_gzip_ctx_t *ctx;
- v->valid = 1;
+ v->valid = 1;
v->no_cachable = 0;
v->not_found = 0;
@@ -1096,7 +1093,7 @@ ngx_http_gzip_merge_conf(ngx_conf_t *cf, void *parent, void *child)
ngx_conf_merge_size_value(conf->wbits, prev->wbits, MAX_WBITS);
ngx_conf_merge_size_value(conf->memlevel, prev->memlevel,
MAX_MEM_LEVEL - 1);
- ngx_conf_merge_value(conf->min_length, prev->min_length, 0);
+ ngx_conf_merge_value(conf->min_length, prev->min_length, 20);
ngx_conf_merge_value(conf->no_buffer, prev->no_buffer, 0);
if (conf->types == NULL) {
diff --git a/src/http/modules/ngx_http_headers_filter_module.c b/src/http/modules/ngx_http_headers_filter_module.c
index da9061be8..86c1a8057 100644
--- a/src/http/modules/ngx_http_headers_filter_module.c
+++ b/src/http/modules/ngx_http_headers_filter_module.c
@@ -262,7 +262,7 @@ ngx_http_headers_filter_init(ngx_cycle_t *cycle)
static void *
ngx_http_headers_create_conf(ngx_conf_t *cf)
-{
+{
ngx_http_headers_conf_t *conf;
conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_headers_conf_t));
@@ -350,7 +350,7 @@ ngx_http_headers_expires(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
if (hcf->expires == NGX_ERROR) {
return "invalid value";
}
-
+
if (hcf->expires == NGX_PARSE_LARGE_TIME) {
return "value must be less than 68 years";
}
diff --git a/src/http/modules/ngx_http_index_module.c b/src/http/modules/ngx_http_index_module.c
index 4847cb700..e6e45a17e 100644
--- a/src/http/modules/ngx_http_index_module.c
+++ b/src/http/modules/ngx_http_index_module.c
@@ -356,7 +356,7 @@ ngx_http_index_error(ngx_http_request_t *r, ngx_http_index_ctx_t *ctx,
if (err == NGX_EACCES) {
ngx_log_error(NGX_LOG_ERR, r->connection->log, err,
"\"%s\" is forbidden", ctx->path.data);
-
+
return NGX_HTTP_FORBIDDEN;
}
diff --git a/src/http/modules/ngx_http_log_module.c b/src/http/modules/ngx_http_log_module.c
index e83207042..3bcf73ac9 100644
--- a/src/http/modules/ngx_http_log_module.c
+++ b/src/http/modules/ngx_http_log_module.c
@@ -55,7 +55,7 @@ static u_char *ngx_http_log_status(ngx_http_request_t *r, u_char *buf,
ngx_http_log_op_t *op);
static u_char *ngx_http_log_bytes_sent(ngx_http_request_t *r, u_char *buf,
ngx_http_log_op_t *op);
-static u_char *ngx_http_log_apache_bytes_sent(ngx_http_request_t *r,
+static u_char *ngx_http_log_body_bytes_sent(ngx_http_request_t *r,
u_char *buf, ngx_http_log_op_t *op);
static u_char *ngx_http_log_request_length(ngx_http_request_t *r, u_char *buf,
ngx_http_log_op_t *op);
@@ -173,7 +173,7 @@ static ngx_str_t http_access_log = ngx_string(NGX_HTTP_LOG_PATH);
static ngx_str_t ngx_http_combined_fmt =
ngx_string("$remote_addr - $remote_user [$time_gmt] "
- "\"$request\" $status $apache_bytes_sent "
+ "\"$request\" $status $body_bytes_sent "
"\"$http_referer\" \"$http_user_agent\"");
@@ -186,8 +186,10 @@ static ngx_http_log_var_t ngx_http_log_vars[] = {
{ ngx_string("request_time"), NGX_TIME_T_LEN, ngx_http_log_request_time },
{ ngx_string("status"), 3, ngx_http_log_status },
{ ngx_string("bytes_sent"), NGX_OFF_T_LEN, ngx_http_log_bytes_sent },
+ { ngx_string("body_bytes_sent"), NGX_OFF_T_LEN,
+ ngx_http_log_body_bytes_sent },
{ ngx_string("apache_bytes_sent"), NGX_OFF_T_LEN,
- ngx_http_log_apache_bytes_sent },
+ ngx_http_log_body_bytes_sent },
{ ngx_string("request_length"), NGX_SIZE_T_LEN,
ngx_http_log_request_length },
@@ -209,7 +211,7 @@ ngx_http_log_op_name_t ngx_http_log_fmt_ops[] = {
{ ngx_string("length"), NGX_OFF_T_LEN,
NULL, NULL, ngx_http_log_bytes_sent },
{ ngx_string("apache_length"), NGX_OFF_T_LEN,
- NULL, NULL, ngx_http_log_apache_bytes_sent },
+ NULL, NULL, ngx_http_log_body_bytes_sent },
{ ngx_string("request_length"), NGX_SIZE_T_LEN,
NULL, NULL, ngx_http_log_request_length },
@@ -429,7 +431,7 @@ ngx_http_log_bytes_sent(ngx_http_request_t *r, u_char *buf,
static u_char *
-ngx_http_log_apache_bytes_sent(ngx_http_request_t *r, u_char *buf,
+ngx_http_log_body_bytes_sent(ngx_http_request_t *r, u_char *buf,
ngx_http_log_op_t *op)
{
off_t length;
@@ -811,7 +813,7 @@ ngx_http_log_transfer_encoding_header_out(ngx_http_request_t *r, u_char *buf,
}
-static ngx_int_t
+static ngx_int_t
ngx_http_log_variable_compile(ngx_conf_t *cf, ngx_http_log_op_t *op,
ngx_str_t *value)
{
@@ -1220,7 +1222,7 @@ ngx_http_log_compile_format(ngx_conf_t *cf, ngx_array_t *ops,
if (arg_len == 0) {
fname[fname_len] = '\0';
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "\"%s\" requires argument",
+ "\"%s\" requires argument",
data);
return NGX_CONF_ERROR;
}
@@ -1298,6 +1300,12 @@ ngx_http_log_compile_format(ngx_conf_t *cf, ngx_array_t *ops,
goto invalid;
}
+ if (ngx_strncmp(var.data, "apache_bytes_sent", 17) == 0) {
+ ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
+ "use \"$body_bytes_sent\" instead of "
+ "\"$apache_bytes_sent\"");
+ }
+
for (v = ngx_http_log_vars; v->name.len; v++) {
if (v->name.len == var.len
diff --git a/src/http/modules/ngx_http_not_modified_filter_module.c b/src/http/modules/ngx_http_not_modified_filter_module.c
index 1e2db62cd..4a6bb5cbc 100644
--- a/src/http/modules/ngx_http_not_modified_filter_module.c
+++ b/src/http/modules/ngx_http_not_modified_filter_module.c
@@ -61,7 +61,7 @@ static ngx_int_t ngx_http_not_modified_header_filter(ngx_http_request_t *r)
ims = ngx_http_parse_time(r->headers_in.if_modified_since->value.data,
r->headers_in.if_modified_since->value.len);
-
+
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"http ims:%d lm:%d", ims, r->headers_out.last_modified_time);
@@ -72,11 +72,8 @@ static ngx_int_t ngx_http_not_modified_header_filter(ngx_http_request_t *r)
if (ims != NGX_ERROR && ims == r->headers_out.last_modified_time) {
r->headers_out.status = NGX_HTTP_NOT_MODIFIED;
r->headers_out.content_type.len = 0;
- r->headers_out.content_length_n = -1;
- r->headers_out.content_length = NULL;
-#if 0
- r->headers_out.accept_ranges->hash = 0;
-#endif
+ ngx_http_clear_content_length(r);
+ ngx_http_clear_accept_ranges(r);
}
return ngx_http_next_header_filter(r);
diff --git a/src/http/modules/ngx_http_proxy_module.c b/src/http/modules/ngx_http_proxy_module.c
index 26f08315e..5712ea04b 100644
--- a/src/http/modules/ngx_http_proxy_module.c
+++ b/src/http/modules/ngx_http_proxy_module.c
@@ -1,5 +1,5 @@
-/*
+/*
* Copyright (C) Igor Sysoev
*/
@@ -38,6 +38,8 @@ typedef struct {
ngx_peers_t *peers;
ngx_array_t *flushes;
+ ngx_array_t *body_set_len;
+ ngx_array_t *body_set;
ngx_array_t *headers_set_len;
ngx_array_t *headers_set;
ngx_hash_t *headers_set_hash;
@@ -47,6 +49,8 @@ typedef struct {
ngx_array_t *redirects;
+ ngx_str_t body_source;
+
ngx_str_t method;
ngx_str_t host_header;
ngx_str_t port_text;
@@ -60,6 +64,8 @@ typedef struct {
ngx_uint_t status_count;
u_char *status_start;
u_char *status_end;
+
+ size_t internal_body_length;
} ngx_http_proxy_ctx_t;
@@ -83,6 +89,9 @@ static ngx_int_t ngx_http_proxy_port_variable(ngx_http_request_t *r,
static ngx_int_t
ngx_http_proxy_add_x_forwarded_for_variable(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data);
+static ngx_int_t
+ ngx_http_proxy_internal_body_length_variable(ngx_http_request_t *r,
+ ngx_http_variable_value_t *v, uintptr_t data);
static ngx_int_t ngx_http_proxy_rewrite_redirect(ngx_http_request_t *r,
ngx_table_elt_t *h, size_t prefix);
@@ -164,6 +173,13 @@ static ngx_command_t ngx_http_proxy_commands[] = {
offsetof(ngx_http_proxy_loc_conf_t, headers_source),
NULL },
+ { ngx_string("proxy_set_body"),
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
+ ngx_conf_set_str_slot,
+ NGX_HTTP_LOC_CONF_OFFSET,
+ offsetof(ngx_http_proxy_loc_conf_t, body_source),
+ NULL },
+
{ ngx_string("proxy_method"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
ngx_conf_set_str_slot,
@@ -336,24 +352,27 @@ static ngx_http_variable_t ngx_http_proxy_vars[] = {
{ ngx_string("proxy_add_via"), NULL, 0, 0, 0 },
#endif
+ { ngx_string("proxy_internal_body_length"),
+ ngx_http_proxy_internal_body_length_variable, 0, 0, 0 },
+
{ ngx_null_string, NULL, 0, 0, 0 }
};
static ngx_int_t
ngx_http_proxy_handler(ngx_http_request_t *r)
-{
+{
ngx_int_t rc;
ngx_http_upstream_t *u;
ngx_http_proxy_loc_conf_t *plcf;
-
+
plcf = ngx_http_get_module_loc_conf(r, ngx_http_proxy_module);
-
+
u = ngx_pcalloc(r->pool, sizeof(ngx_http_upstream_t));
if (u == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
-
+
u->peer.log = r->connection->log;
u->peer.log_error = NGX_ERROR_ERR;
u->peer.peers = plcf->peers;
@@ -379,7 +398,7 @@ ngx_http_proxy_handler(ngx_http_request_t *r)
u->pipe.input_filter = ngx_event_pipe_copy_input_filter;
u->accel = 1;
-
+
r->upstream = u;
rc = ngx_http_read_client_request_body(r, ngx_http_upstream_init);
@@ -395,7 +414,7 @@ ngx_http_proxy_handler(ngx_http_request_t *r)
static ngx_int_t
ngx_http_proxy_create_request(ngx_http_request_t *r)
{
- size_t len, loc_len;
+ size_t len, loc_len, body_len;
ngx_uint_t i, key;
uintptr_t escape;
ngx_buf_t *b;
@@ -404,6 +423,7 @@ ngx_http_proxy_create_request(ngx_http_request_t *r)
ngx_list_part_t *part;
ngx_table_elt_t *header;
ngx_http_upstream_t *u;
+ ngx_http_proxy_ctx_t *p;
ngx_http_script_code_pt code;
ngx_http_script_engine_t e, le;
ngx_http_proxy_loc_conf_t *plcf;
@@ -413,6 +433,13 @@ ngx_http_proxy_create_request(ngx_http_request_t *r)
plcf = ngx_http_get_module_loc_conf(r, ngx_http_proxy_module);
+ 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);
+
len = sizeof(ngx_http_proxy_version) - 1 + sizeof(CRLF) - 1;
if (u->method.len) {
@@ -446,10 +473,23 @@ ngx_http_proxy_create_request(ngx_http_request_t *r)
len += r->uri.len - loc_len + escape + sizeof("?") - 1 + r->args.len;
}
- ngx_memzero(&e, sizeof(ngx_http_script_engine_t));
-
ngx_http_script_flush_no_cachable_variables(r, plcf->flushes);
+ if (plcf->body_set_len) {
+ le.ip = plcf->body_set_len->elts;
+ le.request = r;
+ le.flushed = 1;
+ body_len = 0;
+
+ while (*(uintptr_t *) le.ip) {
+ lcode = *(ngx_http_script_len_code_pt *) le.ip;
+ body_len += lcode(&le);
+ }
+
+ p->internal_body_length = body_len;
+ len += body_len;
+ }
+
le.ip = plcf->headers_set_len->elts;
le.request = r;
le.flushed = 1;
@@ -478,7 +518,7 @@ ngx_http_proxy_create_request(ngx_http_request_t *r)
part = part->next;
header = part->elts;
- i = 0;
+ i = 0;
}
key = header[i].hash % plcf->headers_set_hash->hash_size;
@@ -527,7 +567,7 @@ ngx_http_proxy_create_request(ngx_http_request_t *r)
r->uri.len - loc_len, NGX_ESCAPE_URI);
b->last += r->uri.len - loc_len + escape;
- } else {
+ } else {
b->last = ngx_copy(b->last, r->uri.data + loc_len,
r->uri.len - loc_len);
}
@@ -543,6 +583,7 @@ ngx_http_proxy_create_request(ngx_http_request_t *r)
b->last = ngx_cpymem(b->last, ngx_http_proxy_version,
sizeof(ngx_http_proxy_version) - 1);
+ ngx_memzero(&e, sizeof(ngx_http_script_engine_t));
e.ip = plcf->headers_set->elts;
e.pos = b->last;
@@ -574,7 +615,7 @@ ngx_http_proxy_create_request(ngx_http_request_t *r)
while (*(uintptr_t *) e.ip) {
code = *(ngx_http_script_code_pt *) e.ip;
code((ngx_http_script_engine_t *) &e);
- }
+ }
e.ip += sizeof(uintptr_t);
}
@@ -584,7 +625,7 @@ ngx_http_proxy_create_request(ngx_http_request_t *r)
if (plcf->upstream.pass_request_headers) {
part = &r->headers_in.headers.part;
header = part->elts;
-
+
for (i = 0; /* void */; i++) {
if (i >= part->nelts) {
@@ -594,7 +635,7 @@ ngx_http_proxy_create_request(ngx_http_request_t *r)
part = part->next;
header = part->elts;
- i = 0;
+ i = 0;
}
key = header[i].hash % plcf->headers_set_hash->hash_size;
@@ -620,9 +661,22 @@ ngx_http_proxy_create_request(ngx_http_request_t *r)
}
}
+
/* add "\r\n" at the header end */
*b->last++ = CR; *b->last++ = LF;
+ if (plcf->body_set) {
+ e.ip = plcf->body_set->elts;
+ e.pos = b->last;
+
+ while (*(uintptr_t *) e.ip) {
+ code = *(ngx_http_script_code_pt *) e.ip;
+ code((ngx_http_script_engine_t *) &e);
+ }
+ }
+
+ b->last = e.pos;
+
#if (NGX_DEBUG)
{
ngx_str_t s;
@@ -634,7 +688,7 @@ ngx_http_proxy_create_request(ngx_http_request_t *r)
}
#endif
- if (plcf->upstream.pass_request_body) {
+ if (plcf->body_set == NULL && plcf->upstream.pass_request_body) {
body = u->request_bufs;
u->request_bufs = cl;
@@ -700,12 +754,7 @@ ngx_http_proxy_process_status_line(ngx_http_request_t *r)
p = ngx_http_get_module_ctx(r, ngx_http_proxy_module);
if (p == NULL) {
- 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);
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
rc = ngx_http_proxy_parse_status_line(r, p);
@@ -718,7 +767,7 @@ ngx_http_proxy_process_status_line(ngx_http_request_t *r)
if (rc == NGX_HTTP_PROXY_PARSE_NO_HEADER) {
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
- "upstream sent no valid HTTP/1.0 header");
+ "upstream sent no valid HTTP/1.0 header");
if (u->accel) {
return NGX_HTTP_UPSTREAM_INVALID_HEADER;
@@ -726,7 +775,7 @@ ngx_http_proxy_process_status_line(ngx_http_request_t *r)
r->http_version = NGX_HTTP_VERSION_9;
p->status = NGX_HTTP_OK;
-
+
return NGX_OK;
}
@@ -773,7 +822,7 @@ ngx_http_proxy_parse_status_line(ngx_http_request_t *r, ngx_http_proxy_ctx_t *p)
sw_space_after_status,
sw_status_text,
sw_almost_done
- } state;
+ } state;
u = r->upstream;
@@ -787,7 +836,7 @@ ngx_http_proxy_parse_status_line(ngx_http_request_t *r, ngx_http_proxy_ctx_t *p)
/* "HTTP/" */
case sw_start:
switch (ch) {
- case 'H':
+ case 'H':
state = sw_H;
break;
default:
@@ -795,9 +844,9 @@ ngx_http_proxy_parse_status_line(ngx_http_request_t *r, ngx_http_proxy_ctx_t *p)
}
break;
- case sw_H:
+ case sw_H:
switch (ch) {
- case 'T':
+ case 'T':
state = sw_HT;
break;
default:
@@ -807,7 +856,7 @@ ngx_http_proxy_parse_status_line(ngx_http_request_t *r, ngx_http_proxy_ctx_t *p)
case sw_HT:
switch (ch) {
- case 'T':
+ case 'T':
state = sw_HTT;
break;
default:
@@ -817,7 +866,7 @@ ngx_http_proxy_parse_status_line(ngx_http_request_t *r, ngx_http_proxy_ctx_t *p)
case sw_HTT:
switch (ch) {
- case 'P':
+ case 'P':
state = sw_HTTP;
break;
default:
@@ -827,7 +876,7 @@ ngx_http_proxy_parse_status_line(ngx_http_request_t *r, ngx_http_proxy_ctx_t *p)
case sw_HTTP:
switch (ch) {
- case '/':
+ case '/':
state = sw_first_major_digit;
break;
default:
@@ -897,7 +946,7 @@ ngx_http_proxy_parse_status_line(ngx_http_request_t *r, ngx_http_proxy_ctx_t *p)
/* space or end of line */
case sw_space_after_status:
switch (ch) {
- case ' ':
+ case ' ':
state = sw_status_text;
break;
case '.': /* IIS may send 403.1, 403.2, etc */
@@ -1044,14 +1093,14 @@ ngx_http_proxy_abort_request(ngx_http_request_t *r)
{
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"abort http proxy request");
-
+
return;
}
static void
ngx_http_proxy_finalize_request(ngx_http_request_t *r, ngx_int_t rc)
-{
+{
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"finalize http proxy request");
@@ -1068,7 +1117,7 @@ ngx_http_proxy_host_variable(ngx_http_request_t *r,
plcf = ngx_http_get_module_loc_conf(r, ngx_http_proxy_module);
v->len = plcf->host_header.len;
- v->valid = 1;
+ v->valid = 1;
v->no_cachable = 0;
v->not_found = 0;
v->data = plcf->host_header.data;
@@ -1086,7 +1135,7 @@ ngx_http_proxy_port_variable(ngx_http_request_t *r,
plcf = ngx_http_get_module_loc_conf(r, ngx_http_proxy_module);
v->len = plcf->port_text.len;
- v->valid = 1;
+ v->valid = 1;
v->no_cachable = 0;
v->not_found = 0;
v->data = plcf->port_text.data;
@@ -1097,12 +1146,11 @@ ngx_http_proxy_port_variable(ngx_http_request_t *r,
static ngx_int_t
ngx_http_proxy_add_x_forwarded_for_variable(ngx_http_request_t *r,
-
ngx_http_variable_value_t *v, uintptr_t data)
{
u_char *p;
- v->valid = 1;
+ v->valid = 1;
v->no_cachable = 0;
v->not_found = 0;
@@ -1134,6 +1182,35 @@ ngx_http_proxy_add_x_forwarded_for_variable(ngx_http_request_t *r,
static ngx_int_t
+ngx_http_proxy_internal_body_length_variable(ngx_http_request_t *r,
+ ngx_http_variable_value_t *v, uintptr_t data)
+{
+ ngx_http_proxy_ctx_t *p;
+
+ p = ngx_http_get_module_ctx(r, ngx_http_proxy_module);
+
+ if (p == NULL) {
+ v->not_found = 1;
+ return NGX_OK;
+ }
+
+ v->valid = 1;
+ v->no_cachable = 0;
+ v->not_found = 0;
+
+ v->data = ngx_palloc(r->connection->pool, NGX_SIZE_T_LEN);
+
+ if (v->data == NULL) {
+ return NGX_ERROR;
+ }
+
+ v->len = ngx_sprintf(v->data, "%uz", p->internal_body_length) - v->data;
+
+ return NGX_OK;
+}
+
+
+static ngx_int_t
ngx_http_proxy_rewrite_redirect(ngx_http_request_t *r, ngx_table_elt_t *h,
size_t prefix)
{
@@ -1294,9 +1371,12 @@ ngx_http_proxy_create_loc_conf(ngx_conf_t *cf)
* conf->headers_set_len = NULL;
* conf->headers_set = NULL;
* conf->headers_set_hash = NULL;
+ * conf->body_set_len = NULL;
+ * conf->body_set = NULL;
+ * conf->body_source = { 0, NULL };
* conf->rewrite_locations = NULL;
*/
-
+
conf->upstream.connect_timeout = NGX_CONF_UNSET_MSEC;
conf->upstream.send_timeout = NGX_CONF_UNSET_MSEC;
conf->upstream.read_timeout = NGX_CONF_UNSET_MSEC;
@@ -1305,7 +1385,7 @@ ngx_http_proxy_create_loc_conf(ngx_conf_t *cf)
conf->upstream.header_buffer_size = NGX_CONF_UNSET_SIZE;
conf->upstream.busy_buffers_size_conf = NGX_CONF_UNSET_SIZE;
- conf->upstream.max_temp_file_size_conf = NGX_CONF_UNSET_SIZE;
+ conf->upstream.max_temp_file_size_conf = NGX_CONF_UNSET_SIZE;
conf->upstream.temp_file_write_size_conf = NGX_CONF_UNSET_SIZE;
conf->upstream.max_fails = NGX_CONF_UNSET_UINT;
@@ -1366,14 +1446,14 @@ ngx_http_proxy_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
8, ngx_pagesize);
if (conf->upstream.bufs.num < 2) {
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"there must be at least 2 \"proxy_buffers\"");
return NGX_CONF_ERROR;
}
-
+
size = conf->upstream.header_buffer_size;
- if (size < conf->upstream.bufs.size) {
+ if (size < conf->upstream.bufs.size) {
size = conf->upstream.bufs.size;
}
@@ -1388,7 +1468,7 @@ ngx_http_proxy_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
conf->upstream.busy_buffers_size =
conf->upstream.busy_buffers_size_conf;
}
-
+
if (conf->upstream.busy_buffers_size < size) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"\"proxy_busy_buffers_size\" must be equal or bigger than "
@@ -1419,7 +1499,7 @@ ngx_http_proxy_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
conf->upstream.temp_file_write_size =
conf->upstream.temp_file_write_size_conf;
}
-
+
if (conf->upstream.temp_file_write_size < size) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"\"proxy_temp_file_write_size\" must be equal or bigger than "
@@ -1534,6 +1614,50 @@ ngx_http_proxy_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
conf->peers = prev->peers;
}
+
+ if (conf->body_source.data == NULL) {
+ conf->body_source = prev->body_source;
+ conf->body_set_len = prev->body_set_len;
+ conf->body_set = prev->body_set;
+ }
+
+ if (conf->body_set_len == 0) {
+
+ ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
+
+ sc.cf = cf;
+ sc.source = &conf->body_source;
+ sc.flushes = &conf->flushes;
+ sc.lengths = &conf->body_set_len;
+ sc.values = &conf->body_set;
+ sc.complete_lengths = 1;
+ sc.complete_values = 1;
+
+ if (ngx_http_script_compile(&sc) != NGX_OK) {
+ return NGX_CONF_ERROR;
+ }
+
+ if (conf->headers_source == NULL) {
+ conf->headers_source = ngx_array_create(cf->pool, 4,
+ sizeof(ngx_table_elt_t));
+ if (conf->headers_source == NULL) {
+ return NGX_CONF_ERROR;
+ }
+ }
+
+ s = ngx_array_push(conf->headers_source);
+ if (s == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
+ s->hash = 0;
+ 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";
+ }
+
+
if (conf->headers_source == NULL) {
conf->flushes = prev->flushes;
conf->headers_set_len = prev->headers_set_len;
@@ -1595,6 +1719,8 @@ ngx_http_proxy_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
continue;
}
+
+ src = conf->headers_source->elts;
for (i = 0; i < conf->headers_source->nelts; i++) {
name = ngx_array_push(conf->headers_names);
@@ -1766,9 +1892,13 @@ ngx_http_proxy_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_http_proxy_loc_conf_t *plcf = conf;
+ size_t add;
ngx_str_t *value, *url;
ngx_inet_upstream_t inet_upstream;
ngx_http_core_loc_conf_t *clcf;
+#if (NGX_HTTP_SSL)
+ ngx_pool_cleanup_t *cln;
+#endif
#if (NGX_HAVE_UNIX_DOMAIN)
ngx_unix_domain_upstream_t unix_upstream;
#endif
@@ -1781,20 +1911,57 @@ ngx_http_proxy_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
url = &value[1];
- if (ngx_strncasecmp(url->data, "http://", 7) != 0) {
+ if (ngx_strncasecmp(url->data, "http://", 7) == 0) {
+ add = 7;
+
+ } else if (ngx_strncasecmp(url->data, "https://", 8) == 0) {
+
+#if (NGX_HTTP_SSL)
+
+ add = 8;
+
+ plcf->upstream.ssl = ngx_pcalloc(cf->pool, sizeof(ngx_ssl_t));
+ if (plcf->upstream.ssl == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
+ plcf->upstream.ssl->log = cf->log;
+
+ if (ngx_ssl_create(plcf->upstream.ssl,
+ NGX_SSL_SSLv2|NGX_SSL_SSLv3|NGX_SSL_TLSv1)
+ != NGX_OK)
+ {
+ return NGX_CONF_ERROR;
+ }
+
+ cln = ngx_pool_cleanup_add(cf->pool, 0);
+ if (cln == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
+ cln->handler = ngx_ssl_cleanup_ctx;
+ cln->data = plcf->upstream.ssl;
+
+#else
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+ "https protocol requires SSL support");
+ return NGX_CONF_ERROR;
+#endif
+
+ } else {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid URL prefix");
return NGX_CONF_ERROR;
}
- if (ngx_strncasecmp(url->data + 7, "unix:", 5) == 0) {
+ if (ngx_strncasecmp(url->data + add, "unix:", 5) == 0) {
#if (NGX_HAVE_UNIX_DOMAIN)
ngx_memzero(&unix_upstream, sizeof(ngx_unix_domain_upstream_t));
unix_upstream.name = *url;
- unix_upstream.url.len = url->len - 7;
- unix_upstream.url.data = url->data + 7;
+ unix_upstream.url.len = url->len - add;
+ unix_upstream.url.data = url->data + add;
unix_upstream.uri_part = 1;
plcf->peers = ngx_unix_upstream_parse(cf, &unix_upstream);
@@ -1818,8 +1985,8 @@ ngx_http_proxy_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
ngx_memzero(&inet_upstream, sizeof(ngx_inet_upstream_t));
inet_upstream.name = *url;
- inet_upstream.url.len = url->len - 7;
- inet_upstream.url.data = url->data + 7;
+ inet_upstream.url.len = url->len - add;
+ inet_upstream.url.data = url->data + add;
inet_upstream.default_port_value = 80;
inet_upstream.uri_part = 1;
diff --git a/src/http/modules/ngx_http_range_filter_module.c b/src/http/modules/ngx_http_range_filter_module.c
index c8b30b850..05e2c9376 100644
--- a/src/http/modules/ngx_http_range_filter_module.c
+++ b/src/http/modules/ngx_http_range_filter_module.c
@@ -300,11 +300,7 @@ ngx_http_range_header_filter(ngx_http_request_t *r)
r->headers_out.content_length_n)
- content_range->value.data;
- r->headers_out.content_length_n = -1;
- if (r->headers_out.content_length) {
- r->headers_out.content_length->key.len = 0;
- r->headers_out.content_length = NULL;
- }
+ ngx_http_clear_content_length(r);
return rc;
}
@@ -350,7 +346,7 @@ ngx_http_range_header_filter(ngx_http_request_t *r)
if (ctx == NULL) {
return NGX_ERROR;
}
-
+
ngx_http_set_ctx(r, ctx, ngx_http_range_body_filter_module);
diff --git a/src/http/modules/ngx_http_referer_module.c b/src/http/modules/ngx_http_referer_module.c
new file mode 100644
index 000000000..a3d3d4606
--- /dev/null
+++ b/src/http/modules/ngx_http_referer_module.c
@@ -0,0 +1,309 @@
+
+/*
+ * Copyright (C) Igor Sysoev
+ */
+
+
+#include <ngx_config.h>
+#include <ngx_core.h>
+#include <ngx_http.h>
+
+
+typedef struct {
+ ngx_str_t name;
+ ngx_uint_t wildcard;
+} ngx_http_referer_t;
+
+typedef struct {
+ ngx_array_t *referers; /* ngx_http_referer_t */
+
+ ngx_flag_t no_referer;
+ ngx_flag_t blocked_referer;
+} ngx_http_referer_conf_t;
+
+
+static void * ngx_http_referer_create_conf(ngx_conf_t *cf);
+static char * ngx_http_referer_merge_conf(ngx_conf_t *cf, void *parent,
+ void *child);
+static char *ngx_http_valid_referers(ngx_conf_t *cf, ngx_command_t *cmd,
+ void *conf);
+
+
+static ngx_command_t ngx_http_referer_commands[] = {
+
+ { ngx_string("valid_referers"),
+ NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
+ ngx_http_valid_referers,
+ NGX_HTTP_LOC_CONF_OFFSET,
+ 0,
+ NULL },
+
+ ngx_null_command
+};
+
+
+static ngx_http_module_t ngx_http_referer_module_ctx = {
+ NULL, /* preconfiguration */
+ NULL, /* postconfiguration */
+
+ NULL, /* create main configuration */
+ NULL, /* init main configuration */
+
+ NULL, /* create server configuration */
+ NULL, /* merge server configuration */
+
+ ngx_http_referer_create_conf, /* create location configuration */
+ ngx_http_referer_merge_conf /* merge location configuration */
+};
+
+
+ngx_module_t ngx_http_referer_module = {
+ NGX_MODULE_V1,
+ &ngx_http_referer_module_ctx, /* module context */
+ ngx_http_referer_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_referer_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v,
+ uintptr_t data)
+{
+ u_char *ref;
+ size_t len;
+ ngx_uint_t i, n;
+ ngx_http_referer_t *refs;
+ ngx_http_referer_conf_t *cf;
+
+ cf = ngx_http_get_module_loc_conf(r, ngx_http_referer_module);
+
+ if (cf->referers == NULL) {
+ *v = ngx_http_variable_null_value;
+ return NGX_OK;
+ }
+
+ if (r->headers_in.referer == NULL) {
+ if (cf->no_referer) {
+ *v = ngx_http_variable_null_value;
+ return NGX_OK;
+
+ } else {
+ *v = ngx_http_variable_true_value;
+ return NGX_OK;
+ }
+ }
+
+ len = r->headers_in.referer->value.len;
+ ref = r->headers_in.referer->value.data;
+
+ if (len < sizeof("http://i.ru") - 1
+ || (ngx_strncasecmp(ref, "http://", 7) != 0))
+ {
+ if (cf->blocked_referer) {
+ *v = ngx_http_variable_null_value;
+ return NGX_OK;
+
+ } else {
+ *v = ngx_http_variable_true_value;
+ return NGX_OK;
+ }
+ }
+
+ len -= 7;
+ ref += 7;
+
+ refs = cf->referers->elts;
+ for (i = 0; i < cf->referers->nelts; i++ ){
+
+ if (refs[i].name.len > len) {
+ continue;
+ }
+
+ if (refs[i].wildcard) {
+ for (n = 0; n < len; n++) {
+ if (ref[n] == '/' || ref[n] == ':') {
+ break;
+ }
+
+ if (ref[n] != '.') {
+ continue;
+ }
+
+ if (ngx_strncmp(&ref[n], refs[i].name.data,
+ refs[i].name.len) == 0)
+ {
+ *v = ngx_http_variable_null_value;
+ return NGX_OK;
+ }
+ }
+
+ } else {
+ if (ngx_strncasecmp(refs[i].name.data, ref, refs[i].name.len) == 0)
+ {
+ *v = ngx_http_variable_null_value;
+ return NGX_OK;
+ }
+ }
+ }
+
+ *v = ngx_http_variable_true_value;
+
+ return NGX_OK;
+}
+
+
+static void *
+ngx_http_referer_create_conf(ngx_conf_t *cf)
+{
+ ngx_http_referer_conf_t *conf;
+
+ conf = ngx_palloc(cf->pool, sizeof(ngx_http_referer_conf_t));
+ if (conf == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
+ conf->referers = NULL;
+ conf->no_referer = NGX_CONF_UNSET;
+ conf->blocked_referer = NGX_CONF_UNSET;
+
+ return conf;
+}
+
+
+static char *
+ngx_http_referer_merge_conf(ngx_conf_t *cf, void *parent, void *child)
+{
+ ngx_http_referer_conf_t *prev = parent;
+ ngx_http_referer_conf_t *conf = child;
+
+ if (conf->referers == NULL) {
+ conf->referers = prev->referers;
+ ngx_conf_merge_value(conf->no_referer, prev->no_referer, 0);
+ ngx_conf_merge_value(conf->blocked_referer, prev->blocked_referer, 0);
+ }
+
+ if (conf->no_referer == NGX_CONF_UNSET) {
+ conf->no_referer = 0;
+ }
+
+ if (conf->blocked_referer == NGX_CONF_UNSET) {
+ conf->blocked_referer = 0;
+ }
+
+ return NGX_CONF_OK;
+}
+
+
+static char *
+ngx_http_valid_referers(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
+{
+ ngx_http_referer_conf_t *lcf = conf;
+
+ ngx_uint_t i, server_names;
+ ngx_str_t *value, name;
+ ngx_http_referer_t *ref;
+ ngx_http_variable_t *var;
+ 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";
+
+ var = ngx_http_add_variable(cf, &name, NGX_HTTP_VAR_CHANGABLE);
+ if (var == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
+ var->handler = ngx_http_referer_variable;
+
+ cscf = ngx_http_conf_get_module_srv_conf(cf, ngx_http_core_module);
+
+ if (lcf->referers == NULL) {
+ lcf->referers = ngx_array_create(cf->pool,
+ cf->args->nelts + cscf->server_names.nelts,
+ sizeof(ngx_http_referer_t));
+ if (lcf->referers == NULL) {
+ return NGX_CONF_ERROR;
+ }
+ }
+
+ value = cf->args->elts;
+ server_names = 0;
+
+ for (i = 1; i < cf->args->nelts; i++) {
+ if (value[i].len == 0) {
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+ "invalid referer \"%V\"", &value[i]);
+ return NGX_CONF_ERROR;
+ }
+
+ if (ngx_strcmp(value[i].data, "none") == 0) {
+ lcf->no_referer = 1;
+ continue;
+ }
+
+ if (ngx_strcmp(value[i].data, "blocked") == 0) {
+ lcf->blocked_referer = 1;
+ continue;
+ }
+
+ if (ngx_strcmp(value[i].data, "server_names") == 0) {
+ server_names = 1;
+ continue;
+ }
+
+ ref = ngx_array_push(lcf->referers);
+ if (ref == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
+ if (value[i].data[0] != '*') {
+ ref->name = value[i];
+ ref->wildcard = 0;
+ continue;
+ }
+
+
+ if (value[i].data[1] != '.') {
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+ "invalid wildcard referer \"%V\"", &value[i]);
+ return NGX_CONF_ERROR;
+ }
+
+ ref->name.len = value[i].len - 1;
+ ref->name.data = value[i].data + 1;
+ ref->wildcard = 1;
+ }
+
+ if (!server_names) {
+ return NGX_CONF_OK;
+ }
+
+ sn = cscf->server_names.elts;
+ for (i = 0; i < cscf->server_names.nelts; i++) {
+ ref = ngx_array_push(lcf->referers);
+ if (ref == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
+ ref->name.len = sn[i].name.len + 1;
+ ref->name.data = ngx_palloc(cf->pool, ref->name.len);
+ if (ref->name.data == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
+ ngx_memcpy(ref->name.data, sn[i].name.data, sn[i].name.len);
+ ref->name.data[sn[i].name.len] = '/';
+ ref->wildcard = sn[i].wildcard;
+ }
+
+ 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 6e64f6a99..2c895c520 100644
--- a/src/http/modules/ngx_http_rewrite_module.c
+++ b/src/http/modules/ngx_http_rewrite_module.c
@@ -10,22 +10,12 @@
typedef struct {
- ngx_str_t name;
- ngx_uint_t wildcard;
-} ngx_http_rewrite_referer_t;
+ ngx_array_t *codes; /* uintptr_t */
+ ngx_uint_t captures;
+ ngx_uint_t stack_size;
-typedef struct {
- ngx_array_t *codes; /* uintptr_t */
- ngx_array_t *referers; /* ngx_http_rewrite_referer_t */
-
- ngx_uint_t captures;
- ngx_uint_t stack_size;
-
- ngx_flag_t log;
-
- ngx_flag_t no_referer;
- ngx_flag_t blocked_referer;
+ ngx_flag_t log;
} ngx_http_rewrite_loc_conf_t;
@@ -44,10 +34,10 @@ 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 char * ngx_http_rewrite_value(ngx_conf_t *cf,
+ ngx_http_rewrite_loc_conf_t *lcf, ngx_str_t *value);
static ngx_command_t ngx_http_rewrite_commands[] = {
@@ -83,12 +73,14 @@ static ngx_command_t ngx_http_rewrite_commands[] = {
0,
NULL },
+#if 0
{ ngx_string("valid_referers"),
NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
ngx_http_rewrite_valid_referers,
NGX_HTTP_LOC_CONF_OFFSET,
0,
NULL },
+#endif
{ ngx_string("set"),
NGX_HTTP_SRV_CONF|NGX_HTTP_SIF_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
@@ -127,7 +119,7 @@ ngx_http_module_t ngx_http_rewrite_module_ctx = {
ngx_module_t ngx_http_rewrite_module = {
NGX_MODULE_V1,
- &ngx_http_rewrite_module_ctx, /* module context */
+ &ngx_http_rewrite_module_ctx, /* module context */
ngx_http_rewrite_commands, /* module directives */
NGX_HTTP_MODULE, /* module type */
NULL, /* init master */
@@ -141,10 +133,6 @@ ngx_module_t ngx_http_rewrite_module = {
};
-static ngx_http_variable_value_t ngx_http_rewrite_null_value =
- ngx_http_variable("");
-
-
static ngx_int_t
ngx_http_rewrite_handler(ngx_http_request_t *r)
{
@@ -194,121 +182,6 @@ ngx_http_rewrite_handler(ngx_http_request_t *r)
}
-static void
-ngx_http_rewrite_invalid_referer_code(ngx_http_script_engine_t *e)
-{
- u_char *ref;
- size_t len;
- ngx_uint_t i, n;
- ngx_http_request_t *r;
- ngx_http_rewrite_referer_t *refs;
- ngx_http_rewrite_loc_conf_t *cf;
-
- r = e->request;
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "http rewrite invalid referer");
-
- cf = ngx_http_get_module_loc_conf(r, ngx_http_rewrite_module);
-
- e->ip += sizeof(uintptr_t);
-
- if (cf->referers == NULL) {
- e->sp->data = (u_char *) "";
- e->sp->len = 0;
- e->sp++;
-
- return;
- }
-
- if (r->headers_in.referer == NULL) {
- if (cf->no_referer) {
- e->sp->data = (u_char *) "";
- e->sp->len = 0;
- e->sp++;
-
- return;
-
- } else {
- e->sp->data = (u_char *) "1";
- e->sp->len = 1;
- e->sp++;
-
- return;
- }
- }
-
- len = r->headers_in.referer->value.len;
- ref = r->headers_in.referer->value.data;
-
- if (len < sizeof("http://i.ru") - 1
- || (ngx_strncasecmp(ref, "http://", 7) != 0))
- {
- if (cf->blocked_referer) {
- e->sp->data = (u_char *) "";
- e->sp->len = 0;
- e->sp++;
-
- return;
-
- } else {
- e->sp->data = (u_char *) "1";
- e->sp->len = 1;
- e->sp++;
-
- return;
- }
- }
-
- len -= 7;
- ref += 7;
-
- refs = cf->referers->elts;
- for (i = 0; i < cf->referers->nelts; i++ ){
-
- if (refs[i].name.len > len) {
- continue;
- }
-
- if (refs[i].wildcard) {
- for (n = 0; n < len; n++) {
- if (ref[n] == '/' || ref[n] == ':') {
- break;
- }
-
- if (ref[n] != '.') {
- continue;
- }
-
- if (ngx_strncmp(&ref[n], refs[i].name.data,
- refs[i].name.len) == 0)
- {
- e->sp->data = (u_char *) "";
- e->sp->len = 0;
- e->sp++;
-
- return;
- }
- }
-
- } else {
- if (ngx_strncasecmp(refs[i].name.data, ref, refs[i].name.len) == 0)
- {
- e->sp->data = (u_char *) "";
- e->sp->len = 0;
- e->sp++;
-
- return;
- }
- }
- }
-
- e->sp->data = (u_char *) "1";
- e->sp->len = 1;
- e->sp++;
-}
-
-
static ngx_int_t
ngx_http_rewrite_var(ngx_http_request_t *r, ngx_http_variable_value_t *v,
uintptr_t data)
@@ -329,7 +202,7 @@ ngx_http_rewrite_var(ngx_http_request_t *r, ngx_http_variable_value_t *v,
ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
"using uninitialized \"%V\" variable", &var[data].name);
- *v = ngx_http_rewrite_null_value;
+ *v = ngx_http_variable_null_value;
return NGX_OK;
}
@@ -347,8 +220,6 @@ ngx_http_rewrite_create_loc_conf(ngx_conf_t *cf)
conf->stack_size = NGX_CONF_UNSET_UINT;
conf->log = NGX_CONF_UNSET;
- conf->no_referer = NGX_CONF_UNSET;
- conf->blocked_referer = NGX_CONF_UNSET;
return conf;
}
@@ -365,20 +236,6 @@ ngx_http_rewrite_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
ngx_conf_merge_value(conf->log, prev->log, 0);
ngx_conf_merge_unsigned_value(conf->stack_size, prev->stack_size, 10);
- if (conf->referers == NULL) {
- conf->referers = prev->referers;
- ngx_conf_merge_value(conf->no_referer, prev->no_referer, 0);
- ngx_conf_merge_value(conf->blocked_referer, prev->blocked_referer, 0);
- }
-
- if (conf->no_referer == NGX_CONF_UNSET) {
- conf->no_referer = 0;
- }
-
- if (conf->blocked_referer == NGX_CONF_UNSET) {
- conf->blocked_referer = 0;
- }
-
if (conf->codes == NULL) {
return NGX_CONF_OK;
}
@@ -400,7 +257,7 @@ ngx_http_rewrite_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
static ngx_int_t
ngx_http_rewrite_init(ngx_cycle_t *cycle)
-{
+{
ngx_http_handler_pt *h;
ngx_http_core_main_conf_t *cmcf;
@@ -421,14 +278,14 @@ ngx_http_rewrite_init(ngx_cycle_t *cycle)
*h = ngx_http_rewrite_handler;
return NGX_OK;
-}
+}
static char *
ngx_http_rewrite(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
- ngx_http_rewrite_loc_conf_t *lcf = conf;
-
+ ngx_http_rewrite_loc_conf_t *lcf = conf;
+
ngx_str_t *value, err;
ngx_int_t n;
ngx_uint_t last;
@@ -592,7 +449,7 @@ 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)
{
- ngx_http_rewrite_loc_conf_t *lcf = conf;
+ ngx_http_rewrite_loc_conf_t *lcf = conf;
ngx_str_t *value;
ngx_http_script_return_code_t *ret;
@@ -639,7 +496,7 @@ ngx_http_rewrite_break(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;
+ ngx_http_rewrite_loc_conf_t *lcf = conf;
void *mconf;
char *rv;
@@ -659,7 +516,7 @@ ngx_http_rewrite_if(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
pctx = cf->ctx;
ctx->main_conf = pctx->main_conf;
- ctx->srv_conf = pctx->srv_conf;
+ ctx->srv_conf = pctx->srv_conf;
ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
if (ctx->loc_conf == NULL) {
@@ -672,7 +529,7 @@ ngx_http_rewrite_if(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
}
module = ngx_modules[i]->ctx;
-
+
if (module->create_loc_conf) {
mconf = module->create_loc_conf(cf);
@@ -774,6 +631,7 @@ 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, n;
+ ngx_http_script_code_pt *code;
ngx_http_script_regex_code_t *regex;
u_char errstr[NGX_MAX_CONF_ERRSTR];
@@ -817,7 +675,7 @@ ngx_http_rewrite_if_condition(ngx_conf_t *cf, ngx_http_rewrite_loc_conf_t *lcf)
return NGX_CONF_ERROR;
}
- if (ngx_http_rewrite_variable(cf, lcf, &value[cur])!= NGX_CONF_OK) {
+ if (ngx_http_rewrite_variable(cf, lcf, &value[cur]) != NGX_CONF_OK) {
return NGX_CONF_ERROR;
}
@@ -827,51 +685,85 @@ ngx_http_rewrite_if_condition(ngx_conf_t *cf, ngx_http_rewrite_loc_conf_t *lcf)
cur++;
- if ((value[cur].len == 1 && value[cur].data[0] != '~')
- || (value[cur].len == 2
- && value[cur].data[0] != '~' && value[cur].data[1] != '*'))
+ if (value[cur].len == 1 && value[cur].data[0] == '=') {
+
+ if (ngx_http_rewrite_value(cf, lcf, &value[last]) != NGX_CONF_OK) {
+ return NGX_CONF_ERROR;
+ }
+
+ code = ngx_http_script_start_code(cf->pool, &lcf->codes,
+ sizeof(uintptr_t));
+ if (code == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
+ *code = ngx_http_script_equal_code;
+
+ return NGX_CONF_OK;
+ }
+
+ if (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;
+ if (ngx_http_rewrite_value(cf, lcf, &value[last]) != NGX_CONF_OK) {
+ return NGX_CONF_ERROR;
+ }
+
+ code = ngx_http_script_start_code(cf->pool, &lcf->codes,
+ sizeof(uintptr_t));
+ if (code == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
+ *code = ngx_http_script_not_equal_code;
+ return NGX_CONF_OK;
}
- regex = ngx_http_script_start_code(cf->pool, &lcf->codes,
+ if ((value[cur].len == 1 && value[cur].data[0] == '~')
+ || (value[cur].len == 2
+ && value[cur].data[0] == '~' && value[cur].data[1] == '*'))
+ {
+ regex = ngx_http_script_start_code(cf->pool, &lcf->codes,
sizeof(ngx_http_script_regex_code_t));
- if (regex == NULL) {
- return NGX_CONF_ERROR;
- }
+ if (regex == NULL) {
+ return NGX_CONF_ERROR;
+ }
- ngx_memzero(regex, sizeof(ngx_http_script_regex_code_t));
+ ngx_memzero(regex, sizeof(ngx_http_script_regex_code_t));
- err.len = NGX_MAX_CONF_ERRSTR;
- err.data = errstr;
+ 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);
+ 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;
- }
+ if (regex->regex == NULL) {
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", err.data);
+ return NGX_CONF_ERROR;
+ }
- regex->code = ngx_http_script_regex_start_code;
- regex->next = sizeof(ngx_http_script_regex_code_t);
- regex->test = 1;
- regex->name = value[last];
+ regex->code = ngx_http_script_regex_start_code;
+ regex->next = sizeof(ngx_http_script_regex_code_t);
+ regex->test = 1;
+ regex->name = value[last];
- n = ngx_regex_capture_count(regex->regex);
+ n = ngx_regex_capture_count(regex->regex);
- if (n) {
- regex->ncaptures = (n + 1) * 3;
+ if (n) {
+ regex->ncaptures = (n + 1) * 3;
- if (lcf->captures < regex->ncaptures) {
- lcf->captures = regex->ncaptures;
+ if (lcf->captures < regex->ncaptures) {
+ lcf->captures = regex->ncaptures;
+ }
}
+
+ return NGX_CONF_OK;
}
- return NGX_CONF_OK;
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+ "unexpected \"%V\" in condition", &value[cur]);
+ return NGX_CONF_ERROR;
}
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
@@ -886,135 +778,25 @@ ngx_http_rewrite_variable(ngx_conf_t *cf, ngx_http_rewrite_loc_conf_t *lcf,
ngx_str_t *value)
{
ngx_int_t index;
- ngx_http_script_code_pt *code;
ngx_http_script_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_script_start_code(cf->pool, &lcf->codes,
- sizeof(ngx_http_script_code_pt));
- if (code == NULL) {
- return NGX_CONF_ERROR;
- }
-
- *code = ngx_http_rewrite_invalid_referer_code;
-
- } else {
- index = ngx_http_get_variable_index(cf, value);
+ index = ngx_http_get_variable_index(cf, value);
- if (index == NGX_ERROR) {
- return NGX_CONF_ERROR;
- }
-
- var_code = ngx_http_script_start_code(cf->pool, &lcf->codes,
- sizeof(ngx_http_script_var_code_t));
- if (var_code == NULL) {
- return NGX_CONF_ERROR;
- }
-
- var_code->code = ngx_http_script_var_code;
- var_code->index = 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;
-
- ngx_uint_t i, server_names;
- ngx_str_t *value;
- ngx_http_server_name_t *sn;
- ngx_http_core_srv_conf_t *cscf;
- ngx_http_rewrite_referer_t *ref;
-
- cscf = ngx_http_conf_get_module_srv_conf(cf, ngx_http_core_module);
-
- if (lcf->referers == NULL) {
- lcf->referers = ngx_array_create(cf->pool,
- cf->args->nelts + cscf->server_names.nelts,
- sizeof(ngx_http_rewrite_referer_t));
- if (lcf->referers == NULL) {
- return NGX_CONF_ERROR;
- }
- }
-
- value = cf->args->elts;
- server_names = 0;
-
- for (i = 1; i < cf->args->nelts; i++) {
- if (value[i].len == 0) {
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "invalid referer \"%V\"", &value[i]);
- return NGX_CONF_ERROR;
- }
-
- if (ngx_strcmp(value[i].data, "none") == 0) {
- lcf->no_referer = 1;
- continue;
- }
-
- if (ngx_strcmp(value[i].data, "blocked") == 0) {
- lcf->blocked_referer = 1;
- continue;
- }
-
- if (ngx_strcmp(value[i].data, "server_names") == 0) {
- server_names = 1;
- continue;
- }
-
- ref = ngx_array_push(lcf->referers);
- if (ref == NULL) {
- return NGX_CONF_ERROR;
- }
-
- if (value[i].data[0] != '*') {
- ref->name = value[i];
- ref->wildcard = 0;
- continue;
- }
-
- if (value[i].data[1] != '.') {
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "invalid wildcard referer \"%V\"", &value[i]);
- return NGX_CONF_ERROR;
- }
-
- ref->name.len = value[i].len - 1;
- ref->name.data = value[i].data + 1;
- ref->wildcard = 1;
+ if (index == NGX_ERROR) {
+ return NGX_CONF_ERROR;
}
- if (!server_names) {
- return NGX_CONF_OK;
+ var_code = ngx_http_script_start_code(cf->pool, &lcf->codes,
+ sizeof(ngx_http_script_var_code_t));
+ if (var_code == NULL) {
+ return NGX_CONF_ERROR;
}
- sn = cscf->server_names.elts;
- for (i = 0; i < cscf->server_names.nelts; i++) {
- ref = ngx_array_push(lcf->referers);
- if (ref == NULL) {
- return NGX_CONF_ERROR;
- }
-
- ref->name.len = sn[i].name.len + 1;
- ref->name.data = ngx_palloc(cf->pool, ref->name.len);
- if (ref->name.data == NULL) {
- return NGX_CONF_ERROR;
- }
-
- ngx_memcpy(ref->name.data, sn[i].name.data, sn[i].name.len);
- ref->name.data[sn[i].name.len] = '/';
- ref->wildcard = sn[i].wildcard;
- }
+ var_code->code = ngx_http_script_var_code;
+ var_code->index = index;
return NGX_CONF_OK;
}
@@ -1023,15 +805,12 @@ 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)
{
- ngx_http_rewrite_loc_conf_t *lcf = conf;
+ ngx_http_rewrite_loc_conf_t *lcf = conf;
- ngx_int_t n, index;
- ngx_str_t *value;
- ngx_http_variable_t *v;
- ngx_http_script_compile_t sc;
- ngx_http_script_var_code_t *var;
- ngx_http_script_value_code_t *val;
- ngx_http_script_complex_value_code_t *complex;
+ ngx_int_t index;
+ ngx_str_t *value;
+ ngx_http_variable_t *v;
+ ngx_http_script_var_code_t *var;
value = cf->args->elts;
@@ -1059,7 +838,33 @@ ngx_http_rewrite_set(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
v->data = index;
}
- n = ngx_http_script_variables_count(&value[2]);
+ if (ngx_http_rewrite_value(cf, lcf, &value[2]) != NGX_CONF_OK) {
+ return NGX_CONF_ERROR;
+ }
+
+ var = ngx_http_script_start_code(cf->pool, &lcf->codes,
+ sizeof(ngx_http_script_var_code_t));
+ if (var == NULL) {
+ return NGX_CONF_ERROR;
+ }
+
+ var->code = ngx_http_script_set_var_code;
+ var->index = (uintptr_t) index;
+
+ return NGX_CONF_OK;
+}
+
+
+static char *
+ngx_http_rewrite_value(ngx_conf_t *cf, ngx_http_rewrite_loc_conf_t *lcf,
+ ngx_str_t *value)
+{
+ ngx_int_t n;
+ ngx_http_script_compile_t sc;
+ ngx_http_script_value_code_t *val;
+ ngx_http_script_complex_value_code_t *complex;
+
+ n = ngx_http_script_variables_count(value);
if (n == 0) {
val = ngx_http_script_start_code(cf->pool, &lcf->codes,
@@ -1068,7 +873,7 @@ ngx_http_rewrite_set(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
return NGX_CONF_ERROR;
}
- n = ngx_atoi(value[2].data, value[2].len);
+ n = ngx_atoi(value->data, value->len);
if (n == NGX_ERROR) {
n = 0;
@@ -1076,41 +881,33 @@ ngx_http_rewrite_set(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
val->code = ngx_http_script_value_code;
val->value = (uintptr_t) n;
- val->text_len = (uintptr_t) value[2].len;
- val->text_data = (uintptr_t) value[2].data;
+ val->text_len = (uintptr_t) value->len;
+ val->text_data = (uintptr_t) value->data;
- } else {
- complex = ngx_http_script_start_code(cf->pool, &lcf->codes,
- sizeof(ngx_http_script_complex_value_code_t));
- if (complex == NULL) {
- return NGX_CONF_ERROR;
- }
+ return NGX_CONF_OK;
+ }
- complex->code = ngx_http_script_complex_value_code;
- complex->lengths = NULL;
+ complex = ngx_http_script_start_code(cf->pool, &lcf->codes,
+ sizeof(ngx_http_script_complex_value_code_t));
+ if (complex == NULL) {
+ return NGX_CONF_ERROR;
+ }
- ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
+ complex->code = ngx_http_script_complex_value_code;
+ complex->lengths = NULL;
- sc.cf = cf;
- sc.source = &value[2];
- sc.lengths = &complex->lengths;
- sc.values = &lcf->codes;
- sc.variables = n;
- sc.complete_lengths = 1;
+ ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
- if (ngx_http_script_compile(&sc) != NGX_OK) {
- return NGX_CONF_ERROR;
- }
- }
+ sc.cf = cf;
+ sc.source = value;
+ sc.lengths = &complex->lengths;
+ sc.values = &lcf->codes;
+ sc.variables = n;
+ sc.complete_lengths = 1;
- var = ngx_http_script_start_code(cf->pool, &lcf->codes,
- sizeof(ngx_http_script_var_code_t));
- if (var == NULL) {
+ if (ngx_http_script_compile(&sc) != NGX_OK) {
return NGX_CONF_ERROR;
}
- var->code = ngx_http_script_set_var_code;
- var->index = (uintptr_t) index;
-
return NGX_CONF_OK;
}
diff --git a/src/http/modules/ngx_http_ssi_filter_module.c b/src/http/modules/ngx_http_ssi_filter_module.c
index 86700ecf3..6f4ac4555 100644
--- a/src/http/modules/ngx_http_ssi_filter_module.c
+++ b/src/http/modules/ngx_http_ssi_filter_module.c
@@ -197,7 +197,7 @@ static ngx_command_t ngx_http_ssi_filter_commands[] = {
};
-
+
static ngx_http_module_t ngx_http_ssi_filter_module_ctx = {
ngx_http_ssi_add_variables, /* preconfiguration */
NULL, /* postconfiguration */
@@ -210,7 +210,7 @@ static ngx_http_module_t ngx_http_ssi_filter_module_ctx = {
ngx_http_ssi_create_conf, /* create location configuration */
ngx_http_ssi_merge_conf /* merge location configuration */
-};
+};
ngx_module_t ngx_http_ssi_filter_module = {
@@ -331,7 +331,8 @@ ngx_http_ssi_header_filter(ngx_http_request_t *r)
conf = ngx_http_get_module_loc_conf(r, ngx_http_ssi_filter_module);
if (!conf->enable
- || r->headers_out.content_type.len == 0)
+ || r->headers_out.content_type.len == 0
+ || r->headers_out.content_length_n == 0)
{
return ngx_http_next_header_filter(r);
}
@@ -381,17 +382,8 @@ found:
r->filter_need_in_memory = 1;
if (r->main == r) {
- r->headers_out.content_length_n = -1;
- if (r->headers_out.content_length) {
- r->headers_out.content_length->hash = 0;
- r->headers_out.content_length = NULL;
- }
-
- r->headers_out.last_modified_time = -1;
- if (r->headers_out.last_modified) {
- r->headers_out.last_modified->hash = 0;
- r->headers_out.last_modified = NULL;
- }
+ ngx_http_clear_content_length(r);
+ ngx_http_clear_last_modified(r);
}
return ngx_http_next_header_filter(r);
@@ -1485,7 +1477,7 @@ ngx_http_ssi_evaluate_string(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx,
return NGX_ERROR;
}
- if (var.len == 0) {
+ if (var.len == 0) {
goto invalid_variable;
}
@@ -1983,7 +1975,7 @@ ngx_http_ssi_date_gmt_local_variable(ngx_http_request_t *r,
struct tm tm;
char buf[NGX_HTTP_SSI_DATE_LEN];
- v->valid = 1;
+ v->valid = 1;
v->no_cachable = 0;
v->not_found = 0;
@@ -2092,7 +2084,7 @@ ngx_http_ssi_add_variables(ngx_conf_t *cf)
var->data = v->data;
}
- return NGX_OK;
+ return NGX_OK;
}
diff --git a/src/http/modules/ngx_http_static_module.c b/src/http/modules/ngx_http_static_module.c
index ab7ac9c6f..74cd010a0 100644
--- a/src/http/modules/ngx_http_static_module.c
+++ b/src/http/modules/ngx_http_static_module.c
@@ -44,13 +44,13 @@ ngx_http_module_t ngx_http_static_module_ctx = {
NULL, /* create main configuration */
NULL, /* init main configuration */
-
+
NULL, /* create server configuration */
NULL, /* merge server configuration */
-
+
ngx_http_static_create_loc_conf, /* create location configuration */
ngx_http_static_merge_loc_conf /* merge location configuration */
-};
+};
ngx_module_t ngx_http_static_module = {
@@ -240,51 +240,37 @@ ngx_http_static_handler(ngx_http_request_t *r)
r->headers_out.content_length_n = ngx_file_size(&fi);
r->headers_out.last_modified_time = ngx_file_mtime(&fi);
- if (r->headers_out.content_length_n == 0) {
- r->header_only = 1;
- }
-
if (ngx_http_set_content_type(r) != NGX_OK) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
-#if (NGX_SUPPRESS_WARN)
- b = NULL;
-#endif
-
- if (!r->header_only) {
- /* we need to allocate all before the header would be sent */
-
- b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t));
- if (b == NULL) {
- return NGX_HTTP_INTERNAL_SERVER_ERROR;
- }
+ /* we need to allocate all before the header would be sent */
- b->file = ngx_pcalloc(r->pool, sizeof(ngx_file_t));
- if (b->file == NULL) {
- return NGX_HTTP_INTERNAL_SERVER_ERROR;
- }
+ b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t));
+ if (b == NULL) {
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;
+ }
- r->filter_allow_ranges = 1;
+ b->file = ngx_pcalloc(r->pool, sizeof(ngx_file_t));
+ if (b->file == NULL) {
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
+ r->filter_allow_ranges = 1;
+
rc = ngx_http_send_header(r);
if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {
return rc;
}
- b->in_file = 1;
-
- if (r->main == r) {
- b->last_buf = 1;
- }
-
- b->last_in_chain = 1;
-
b->file_pos = 0;
b->file_last = ngx_file_size(&fi);
+ b->in_file = b->file_last ? 1: 0;
+ b->last_buf = (r->main == r) ? 1: 0;
+ b->last_in_chain = 1;
+
b->file->fd = fd;
b->file->name = path;
b->file->log = log;
@@ -333,7 +319,7 @@ ngx_http_static_init(ngx_cycle_t *cycle)
ngx_http_core_main_conf_t *cmcf;
cmcf = ngx_http_cycle_get_module_main_conf(cycle, ngx_http_core_module);
-
+
h = ngx_array_push(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers);
if (h == NULL) {
return NGX_ERROR;
diff --git a/src/http/modules/ngx_http_status_module.c b/src/http/modules/ngx_http_status_module.c
index ce49ae426..cf4f33f84 100644
--- a/src/http/modules/ngx_http_status_module.c
+++ b/src/http/modules/ngx_http_status_module.c
@@ -78,7 +78,7 @@ static ngx_int_t ngx_http_status_handler(ngx_http_request_t *r)
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;
@@ -281,7 +281,7 @@ static ngx_int_t ngx_http_status(ngx_http_status_ctx_t *ctx)
if (ctx->head) {
*ll = cl;
- } else {
+ } else {
ctx->head = cl;
}
diff --git a/src/http/modules/ngx_http_stub_status_module.c b/src/http/modules/ngx_http_stub_status_module.c
index ea55c1b04..7cdb3c1b9 100644
--- a/src/http/modules/ngx_http_stub_status_module.c
+++ b/src/http/modules/ngx_http_stub_status_module.c
@@ -1,4 +1,9 @@
+/*
+ * Copyright (C) Igor Sysoev
+ */
+
+
#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_http.h>
@@ -6,7 +11,7 @@
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"),
@@ -17,20 +22,20 @@ static ngx_command_t ngx_http_status_commands[] = {
NULL },
ngx_null_command
-};
+};
+
-
ngx_http_module_t ngx_http_stub_status_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 */
};
@@ -59,7 +64,7 @@ static ngx_int_t ngx_http_status_handler(ngx_http_request_t *r)
ngx_buf_t *b;
ngx_chain_t out;
ngx_atomic_int_t ap, hn, ac, rq, rd, wr;
-
+
if (r->method != NGX_HTTP_GET && r->method != NGX_HTTP_HEAD) {
return NGX_HTTP_NOT_ALLOWED;
}
diff --git a/src/http/modules/ngx_http_userid_filter_module.c b/src/http/modules/ngx_http_userid_filter_module.c
index 94a709b60..c77dca2da 100644
--- a/src/http/modules/ngx_http_userid_filter_module.c
+++ b/src/http/modules/ngx_http_userid_filter_module.c
@@ -594,7 +594,7 @@ ngx_http_userid_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v,
ngx_http_userid_ctx_t *ctx;
ngx_http_userid_conf_t *conf;
- v->valid = 1;
+ v->valid = 1;
v->no_cachable = 0;
v->not_found = 0;
@@ -634,7 +634,7 @@ ngx_http_userid_init(ngx_cycle_t *cycle)
static void *
ngx_http_userid_create_conf(ngx_conf_t *cf)
-{
+{
ngx_http_userid_conf_t *conf;
conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_userid_conf_t));
@@ -661,7 +661,7 @@ ngx_http_userid_create_conf(ngx_conf_t *cf)
conf->mark = (u_char) '\xFF';
return conf;
-}
+}
static char *
diff --git a/src/http/ngx_http.c b/src/http/ngx_http.c
index 7e4fab7f6..bfb7c6b13 100644
--- a/src/http/ngx_http.c
+++ b/src/http/ngx_http.c
@@ -44,12 +44,12 @@ static ngx_command_t ngx_http_commands[] = {
ngx_null_command
};
-
+
static ngx_core_module_t ngx_http_module_ctx = {
ngx_string("http"),
NULL,
NULL
-};
+};
ngx_module_t ngx_http_module = {
@@ -438,7 +438,7 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
}
/*
- * check the duplicate "default" server
+ * check the duplicate "default" server
* for this address:port
*/
diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
index c230860bb..5fd53179d 100644
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -343,6 +343,14 @@ static ngx_command_t ngx_http_core_commands[] = {
0,
NULL },
+ { ngx_string("post_action"),
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
+ |NGX_CONF_TAKE1,
+ ngx_conf_set_str_slot,
+ NGX_HTTP_LOC_CONF_OFFSET,
+ offsetof(ngx_http_core_loc_conf_t, post_action),
+ NULL },
+
{ ngx_string("error_log"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
ngx_http_core_error_log,
@@ -514,7 +522,7 @@ ngx_http_core_run_phases(ngx_http_request_t *r)
if (rc == NGX_DONE) {
/*
- * we should never use r here because
+ * we should never use r here because
* it may point to already freed data
*/
@@ -1034,9 +1042,9 @@ ngx_http_auth_basic_user(ngx_http_request_t *r)
r->headers_in.user.data = (u_char *) "";
return NGX_DECLINED;
}
-
+
auth.len = ngx_base64_decoded_length(encoded.len);
- auth.data = ngx_palloc(r->pool, auth.len + 1);
+ auth.data = ngx_palloc(r->pool, auth.len + 1);
if (auth.data == NULL) {
return NGX_ERROR;
}
@@ -1045,15 +1053,15 @@ ngx_http_auth_basic_user(ngx_http_request_t *r)
r->headers_in.user.data = (u_char *) "";
return NGX_DECLINED;
}
-
+
auth.data[auth.len] = '\0';
-
- for (len = 0; len < auth.len; len++) {
+
+ for (len = 0; len < auth.len; len++) {
if (auth.data[len] == ':') {
break;
}
}
-
+
if (len == 0 || len == auth.len) {
r->headers_in.user.data = (u_char *) "";
return NGX_DECLINED;
@@ -1105,8 +1113,10 @@ ngx_http_subrequest(ngx_http_request_t *r,
sr->headers_in = r->headers_in;
sr->start_time = ngx_time();
- sr->headers_out.content_length_n = -1;
- sr->headers_out.last_modified_time = -1;
+
+ ngx_http_clear_content_length(sr);
+ ngx_http_clear_accept_ranges(sr);
+ ngx_http_clear_last_modified(sr);
sr->request_body = r->request_body;
@@ -1859,11 +1869,10 @@ ngx_http_core_create_loc_conf(ngx_conf_t *cf)
/*
* set by ngx_pcalloc():
*
- * lcf->root.len = 0;
- * lcf->root.data = NULL;
+ * lcf->root = { 0, NULL };
+ * lcf->post_action = { 0, NULL };
* lcf->types = NULL;
- * lcf->default_type.len = 0;
- * lcf->default_type.data = NULL;
+ * lcf->default_type = { 0, NULL };
* lcf->err_log = NULL;
* lcf->error_pages = NULL;
* lcf->client_body_path = NULL;
@@ -1923,13 +1932,17 @@ ngx_http_core_merge_loc_conf(ngx_conf_t *cf,
return NGX_CONF_ERROR;
}
+ if (conf->post_action.data == NULL) {
+ conf->post_action = prev->post_action;
+ }
+
if (conf->types == NULL) {
if (prev->types) {
conf->types = prev->types;
} else {
conf->types = ngx_palloc(cf->pool, NGX_HTTP_TYPES_HASH_PRIME
- * sizeof(ngx_array_t));
+ * sizeof(ngx_array_t));
if (conf->types == NULL) {
return NGX_CONF_ERROR;
}
@@ -2038,7 +2051,7 @@ ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
*/
value = cf->args->elts;
-
+
ngx_memzero(&inet_upstream, sizeof(ngx_inet_upstream_t));
inet_upstream.url = value[1];
@@ -2050,7 +2063,7 @@ ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"%s in \"%V\" of the \"listen\" directive",
err, &inet_upstream.url);
- return NGX_CONF_ERROR;
+ return NGX_CONF_ERROR;
}
ls = ngx_array_push(&scf->listen);
@@ -2084,7 +2097,7 @@ ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
inet_upstream.host.data);
return NGX_CONF_ERROR;
}
-
+
ls->addr = *(in_addr_t *)(h->h_addr_list[0]);
}
diff --git a/src/http/ngx_http_core_module.h b/src/http/ngx_http_core_module.h
index b2c25cf0b..1be3b38f3 100644
--- a/src/http/ngx_http_core_module.h
+++ b/src/http/ngx_http_core_module.h
@@ -145,9 +145,9 @@ typedef struct {
#define ngx_http_server_names_hash_key(key, name, len, prime) \
{ \
- ngx_uint_t n; \
- for (key = 0, n = 0; n < len; n++) { \
- key += name[n]; \
+ ngx_uint_t n0; \
+ for (key = 0, n0 = 0; n0 < len; n0++) { \
+ key += name[n0]; \
} \
key %= prime; \
}
@@ -202,11 +202,12 @@ struct ngx_http_core_loc_conf_s {
ngx_http_handler_pt handler;
- ngx_str_t root; /* root, alias */
-
ngx_array_t *types;
ngx_str_t default_type;
+ ngx_str_t root; /* root, alias */
+ ngx_str_t post_action;
+
size_t client_max_body_size; /* client_max_body_size */
size_t client_body_buffer_size; /* client_body_buffer_size */
size_t send_lowat; /* send_lowat */
@@ -245,14 +246,6 @@ struct ngx_http_core_loc_conf_s {
};
-
-extern ngx_http_module_t ngx_http_core_module_ctx;
-extern ngx_module_t ngx_http_core_module;
-
-extern ngx_uint_t ngx_http_max_module;
-
-
-
ngx_int_t ngx_http_find_location_config(ngx_http_request_t *r);
ngx_int_t ngx_http_set_content_type(ngx_http_request_t *r);
@@ -278,4 +271,35 @@ ngx_int_t ngx_http_output_filter(ngx_http_request_t *r, ngx_chain_t *chain);
ngx_int_t ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *chain);
+extern ngx_http_module_t ngx_http_core_module_ctx;
+extern ngx_module_t ngx_http_core_module;
+
+extern ngx_uint_t ngx_http_max_module;
+
+
+#define ngx_http_clear_content_length(r) \
+ \
+ r->headers_out.content_length_n = -1; \
+ if (r->headers_out.content_length) { \
+ r->headers_out.content_length->hash = 0; \
+ r->headers_out.content_length = NULL; \
+ }
+ \
+#define ngx_http_clear_accept_ranges(r) \
+ \
+ r->filter_allow_ranges = 0; \
+ if (r->headers_out.accept_ranges) { \
+ r->headers_out.accept_ranges->hash = 0 ; \
+ r->headers_out.accept_ranges = NULL; \
+ }
+
+#define ngx_http_clear_last_modified(r) \
+ \
+ r->headers_out.last_modified_time = -1; \
+ if (r->headers_out.last_modified) { \
+ r->headers_out.last_modified->hash = 0; \
+ r->headers_out.last_modified = NULL; \
+ }
+
+
#endif /* _NGX_HTTP_CORE_H_INCLUDED_ */
diff --git a/src/http/ngx_http_parse.c b/src/http/ngx_http_parse.c
index b2e2f9e3f..ba08e59b3 100644
--- a/src/http/ngx_http_parse.c
+++ b/src/http/ngx_http_parse.c
@@ -1109,7 +1109,7 @@ ngx_http_parse_multi_header_lines(ngx_array_t *headers, ngx_str_t *name,
if (name->len > h[i]->value.len) {
continue;
}
-
+
start = h[i]->value.data;
end = h[i]->value.data + h[i]->value.len;
diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c
index ef5a45f56..a73c788b6 100644
--- a/src/http/ngx_http_request.c
+++ b/src/http/ngx_http_request.c
@@ -51,7 +51,6 @@ static u_char *ngx_http_log_error_handler(ngx_http_request_t *r, u_char *buf,
#if (NGX_HTTP_SSL)
static void ngx_http_ssl_handshake(ngx_event_t *rev);
static void ngx_http_ssl_handshake_handler(ngx_connection_t *c);
-static void ngx_http_ssl_close_handler(ngx_event_t *ev);
#endif
@@ -451,7 +450,7 @@ ngx_http_ssl_handshake(ngx_event_t *rev)
return;
}
- n = recv(c->fd, buf, 1, MSG_PEEK);
+ n = recv(c->fd, buf, 1, MSG_PEEK);
if (n == -1 && ngx_socket_errno == NGX_EAGAIN) {
return;
@@ -1346,7 +1345,7 @@ ngx_http_find_virtual_server(ngx_http_request_t *r)
}
if (rc < 0) {
- /* the server names are lexicographically sorted */
+ /* the server names are lexicographically sorted */
break;
}
}
@@ -1520,6 +1519,13 @@ ngx_http_finalize_request(ngx_http_request_t *r, ngx_int_t rc)
return;
}
+ clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
+
+ if (clcf->post_action.data) {
+ ngx_http_internal_redirect(r, &clcf->post_action, NULL);
+ return;
+ }
+
if (r->connection->read->timer_set) {
ngx_del_timer(r->connection->read);
}
@@ -1539,8 +1545,6 @@ ngx_http_finalize_request(ngx_http_request_t *r, ngx_int_t rc)
return;
}
- clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
-
if (!ngx_terminate
&& !ngx_exiting
&& r->keepalive != 0
@@ -1894,7 +1898,7 @@ ngx_http_set_keepalive(ngx_http_request_t *r)
* If the large header buffers were allocated while the previous
* request processing then we do not use c->buffer for
* the pipelined request (see ngx_http_init_request()).
- *
+ *
* Now we would move the large header buffers to the free list.
*/
@@ -2178,7 +2182,7 @@ ngx_http_keepalive_handler(ngx_event_t *rev)
static void
ngx_http_set_lingering_close(ngx_http_request_t *r)
-{
+{
ngx_event_t *rev, *wev;
ngx_connection_t *c;
ngx_http_core_loc_conf_t *clcf;
@@ -2248,6 +2252,7 @@ ngx_http_lingering_close_handler(ngx_event_t *rev)
"http lingering close handler");
if (rev->timedout) {
+ c->timedout = 1;
ngx_http_close_request(r, 0);
return;
}
@@ -2423,8 +2428,7 @@ ngx_http_close_connection(ngx_connection_t *c)
if (c->ssl) {
if (ngx_ssl_shutdown(c) == NGX_AGAIN) {
- c->read->handler = ngx_http_ssl_close_handler;
- c->write->handler = ngx_http_ssl_close_handler;
+ c->ssl->handler = ngx_http_close_connection;
return;
}
}
@@ -2443,27 +2447,6 @@ ngx_http_close_connection(ngx_connection_t *c)
}
-#if (NGX_HTTP_SSL)
-
-static void
-ngx_http_ssl_close_handler(ngx_event_t *ev)
-{
- ngx_connection_t *c;
-
- c = ev->data;
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, ev->log, 0, "http ssl close handler");
-
- if (ngx_ssl_shutdown(c) == NGX_AGAIN) {
- return;
- }
-
- ngx_http_close_connection(c);
-}
-
-#endif
-
-
static u_char *
ngx_http_log_error(ngx_log_t *log, u_char *buf, size_t len)
{
diff --git a/src/http/ngx_http_request.h b/src/http/ngx_http_request.h
index b0bb5d00f..da12b58d6 100644
--- a/src/http/ngx_http_request.h
+++ b/src/http/ngx_http_request.h
@@ -69,13 +69,13 @@
/*
* We use the special code for the plain HTTP requests that are sent to
- * HTTPS port to distinguish it from 4XX in an error page redirection
+ * HTTPS port to distinguish it from 4XX in an error page redirection
*/
#define NGX_HTTP_TO_HTTPS 497
/*
* We use the special code for the requests with invalid host name
- * to distinguish it from 4XX in an error page redirection
+ * to distinguish it from 4XX in an error page redirection
*/
#define NGX_HTTP_INVALID_HOST 498
@@ -300,7 +300,7 @@ struct ngx_http_request_s {
ngx_uint_t http_version;
ngx_uint_t http_major;
ngx_uint_t http_minor;
-
+
ngx_str_t request_line;
ngx_str_t uri;
ngx_str_t args;
@@ -309,7 +309,7 @@ struct ngx_http_request_s {
ngx_str_t method_name;
ngx_str_t http_protocol;
-
+
ngx_chain_t *out;
ngx_http_request_t *main;
ngx_http_request_t *parent;
diff --git a/src/http/ngx_http_request_body.c b/src/http/ngx_http_request_body.c
index 6f02f0d4b..779edf949 100644
--- a/src/http/ngx_http_request_body.c
+++ b/src/http/ngx_http_request_body.c
@@ -143,6 +143,7 @@ ngx_http_read_client_request_body_handler(ngx_http_request_t *r)
ngx_int_t rc;
if (r->connection->read->timedout) {
+ r->connection->timedout = 1;
ngx_http_finalize_request(r, NGX_HTTP_REQUEST_TIME_OUT);
return;
}
diff --git a/src/http/ngx_http_script.c b/src/http/ngx_http_script.c
index 90620cd59..4986675a9 100644
--- a/src/http/ngx_http_script.c
+++ b/src/http/ngx_http_script.c
@@ -503,7 +503,7 @@ ngx_http_script_start_args_code(ngx_http_script_engine_t *e)
{
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
"http script args");
-
+
e->args = e->pos;
e->ip += sizeof(uintptr_t);
}
@@ -664,6 +664,7 @@ ngx_http_script_regex_start_code(ngx_http_script_engine_t *e)
void
ngx_http_script_regex_end_code(ngx_http_script_engine_t *e)
{
+ u_char *dst, *src;
ngx_http_request_t *r;
ngx_http_script_regex_end_code_t *code;
@@ -678,7 +679,18 @@ ngx_http_script_regex_end_code(ngx_http_script_engine_t *e)
if (code->redirect) {
- if (code->add_args && r->args.len) {
+ dst = e->buf.data;
+ src = e->buf.data;
+
+ ngx_unescape_uri(&dst, &src, e->pos - e->buf.data);
+
+ if (src < e->pos) {
+ dst = ngx_copy(dst, src, e->pos - src);
+ }
+
+ e->pos = dst;
+
+ if (code->add_args && r->args.len) {
*e->pos++ = (u_char) (code->args ? '&' : '?');
e->pos = ngx_copy(e->pos, r->args.data, r->args.len);
}
@@ -697,7 +709,7 @@ ngx_http_script_regex_end_code(ngx_http_script_engine_t *e)
return;
}
- r->headers_out.location->hash = 1;
+ r->headers_out.location->hash = 1;
r->headers_out.location->key.len = sizeof("Location") - 1;
r->headers_out.location->key.data = (u_char *) "Location";
r->headers_out.location->value = e->buf;
@@ -706,7 +718,7 @@ ngx_http_script_regex_end_code(ngx_http_script_engine_t *e)
return;
}
- if (e->args) {
+ if (e->args) {
e->buf.len = e->args - e->buf.data;
if (code->add_args && r->args.len) {
@@ -755,9 +767,9 @@ ngx_http_script_regex_end_code(ngx_http_script_engine_t *e)
void
ngx_http_script_return_code(ngx_http_script_engine_t *e)
-{
+{
ngx_http_script_return_code_t *code;
-
+
code = (ngx_http_script_return_code_t *) e->ip;
e->status = code->status;
@@ -798,13 +810,69 @@ ngx_http_script_if_code(ngx_http_script_engine_t *e)
}
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
- "http script if false");
+ "http script if: false");
e->ip += code->next;
}
void
+ngx_http_script_equal_code(ngx_http_script_engine_t *e)
+{
+ ngx_http_variable_value_t *val, *res;
+
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
+ "http script equal");
+
+ e->sp--;
+ val = e->sp;
+ res = e->sp - 1;
+
+ e->ip += sizeof(uintptr_t);
+
+ if (val->len == res->len && ngx_strncmp(val->data, res->data, res->len)
+ == 0)
+ {
+ *res = ngx_http_variable_true_value;
+ return;
+ }
+
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
+ "http script equal: no");
+
+ *res = ngx_http_variable_null_value;
+}
+
+
+void
+ngx_http_script_not_equal_code(ngx_http_script_engine_t *e)
+{
+ ngx_http_variable_value_t *val, *res;
+
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
+ "http script not equal");
+
+ e->sp--;
+ val = e->sp;
+ res = e->sp - 1;
+
+ e->ip += sizeof(uintptr_t);
+
+ if (val->len == res->len && ngx_strncmp(val->data, res->data, res->len)
+ == 0)
+ {
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
+ "http script not equal: no");
+
+ *res = ngx_http_variable_null_value;
+ return;
+ }
+
+ *res = ngx_http_variable_true_value;
+}
+
+
+void
ngx_http_script_complex_value_code(ngx_http_script_engine_t *e)
{
size_t len;
@@ -840,8 +908,8 @@ ngx_http_script_complex_value_code(ngx_http_script_engine_t *e)
e->pos = e->buf.data;
- e->sp->data = e->buf.data;
e->sp->len = e->buf.len;
+ e->sp->data = e->buf.data;
e->sp++;
}
@@ -855,11 +923,12 @@ ngx_http_script_value_code(ngx_http_script_engine_t *e)
e->ip += sizeof(ngx_http_script_value_code_t);
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
- "http script value");
-
e->sp->len = code->text_len;
e->sp->data = (u_char *) code->text_data;
+
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, e->request->connection->log, 0,
+ "http script value: \"%V\"", e->sp);
+
e->sp++;
}
@@ -914,8 +983,7 @@ ngx_http_script_var_code(ngx_http_script_engine_t *e)
return;
}
- e->sp->data = (u_char *) "";
- e->sp->len = 0;
+ *e->sp = ngx_http_variable_null_value;
e->sp++;
}
diff --git a/src/http/ngx_http_script.h b/src/http/ngx_http_script.h
index f67b5bee8..46e448a99 100644
--- a/src/http/ngx_http_script.h
+++ b/src/http/ngx_http_script.h
@@ -99,7 +99,7 @@ typedef struct {
/* add the r->args to the new arguments */
uintptr_t add_args:1;
-
+
uintptr_t redirect:1;
uintptr_t break_cycle:1;
@@ -173,6 +173,8 @@ void ngx_http_script_regex_end_code(ngx_http_script_engine_t *e);
void ngx_http_script_return_code(ngx_http_script_engine_t *e);
void ngx_http_script_break_code(ngx_http_script_engine_t *e);
void ngx_http_script_if_code(ngx_http_script_engine_t *e);
+void ngx_http_script_equal_code(ngx_http_script_engine_t *e);
+void ngx_http_script_not_equal_code(ngx_http_script_engine_t *e);
void ngx_http_script_complex_value_code(ngx_http_script_engine_t *e);
void ngx_http_script_value_code(ngx_http_script_engine_t *e);
void ngx_http_script_set_var_code(ngx_http_script_engine_t *e);
diff --git a/src/http/ngx_http_special_response.c b/src/http/ngx_http_special_response.c
index 5a1f3c461..d115fddc3 100644
--- a/src/http/ngx_http_special_response.c
+++ b/src/http/ngx_http_special_response.c
@@ -371,6 +371,9 @@ ngx_http_special_response_handler(ngx_http_request_t *r, ngx_int_t error)
r->headers_out.content_length = NULL;
}
+ ngx_http_clear_accept_ranges(r);
+ ngx_http_clear_last_modified(r);
+
rc = ngx_http_send_header(r);
if (rc == NGX_ERROR || r->header_only) {
diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c
index 48af6fe4c..62f5d9eae 100644
--- a/src/http/ngx_http_upstream.c
+++ b/src/http/ngx_http_upstream.c
@@ -84,6 +84,12 @@ static ngx_int_t ngx_http_upstream_response_time_variable(ngx_http_request_t *r,
static void *ngx_http_upstream_create_main_conf(ngx_conf_t *cf);
static char *ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf);
+#if (NGX_HTTP_SSL)
+static void ngx_http_upstream_ssl_handshake(ngx_connection_t *c);
+static void ngx_http_upstream_ssl_shutdown(ngx_connection_t *c,
+ ngx_peer_t *peer);
+#endif
+
ngx_http_upstream_header_t ngx_http_upstream_headers_in[] = {
@@ -147,6 +153,12 @@ ngx_http_upstream_header_t ngx_http_upstream_headers_in[] = {
ngx_http_upstream_copy_header_line,
offsetof(ngx_http_headers_out_t, expires), 1 },
+ { ngx_string("Accept-Ranges"),
+ ngx_http_upstream_process_header_line,
+ offsetof(ngx_http_upstream_headers_in_t, accept_ranges),
+ ngx_http_upstream_copy_header_line,
+ offsetof(ngx_http_headers_out_t, accept_ranges), 1 },
+
{ ngx_string("Connection"),
ngx_http_upstream_ignore_header_line, 0,
ngx_http_upstream_ignore_header_line, 0, 0 },
@@ -199,7 +211,7 @@ ngx_http_module_t ngx_http_upstream_module_ctx = {
NULL, /* create location configuration */
NULL /* merge location configuration */
};
-
+
ngx_module_t ngx_http_upstream_module = {
NGX_MODULE_V1,
@@ -266,7 +278,7 @@ ngx_http_upstream_init(ngx_http_request_t *r)
r->read_event_handler = ngx_http_upstream_rd_check_broken_connection;
r->write_event_handler = ngx_http_upstream_wr_check_broken_connection;
-
+
if (ngx_event_flags & NGX_USE_CLEAR_EVENT) {
if (!c->write->active) {
@@ -359,7 +371,7 @@ ngx_http_upstream_check_broken_connection(ngx_http_request_t *r,
{
int n;
char buf[1];
- ngx_err_t err;
+ ngx_err_t err;
ngx_connection_t *c;
ngx_http_upstream_t *u;
@@ -482,6 +494,7 @@ static void
ngx_http_upstream_connect(ngx_http_request_t *r, ngx_http_upstream_t *u)
{
ngx_int_t rc;
+ ngx_peer_t *peer;
ngx_connection_t *c;
r->connection->log->action = "connecting to upstream";
@@ -499,7 +512,8 @@ ngx_http_upstream_connect(ngx_http_request_t *r, ngx_http_upstream_t *u)
return;
}
- u->state->peer = &u->peer.peers->peer[u->peer.cur_peer].name;
+ peer = &u->peer.peers->peer[u->peer.cur_peer];
+ u->state->peer = &peer->name;
if (rc == NGX_BUSY) {
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "no live upstreams");
@@ -510,6 +524,8 @@ ngx_http_upstream_connect(ngx_http_request_t *r, ngx_http_upstream_t *u)
return;
}
+ /* rc == NGX_OK || rc == NGX_AGAIN */
+
c = u->peer.connection;
c->data = r;
@@ -568,10 +584,75 @@ ngx_http_upstream_connect(ngx_http_request_t *r, ngx_http_upstream_t *u)
/* rc == NGX_OK */
+#if (NGX_HTTP_SSL)
+
+ if (u->conf->ssl) {
+ if (c->ssl == NULL) {
+
+ if (ngx_ssl_create_connection(u->conf->ssl, c,
+ NGX_SSL_BUFFER|NGX_SSL_CLIENT)
+ == NGX_ERROR)
+ {
+ ngx_http_upstream_finalize_request(r, u,
+ NGX_HTTP_INTERNAL_SERVER_ERROR);
+ return;
+ }
+
+ c->sendfile = 0;
+ }
+
+ if (ngx_ssl_set_session(c, peer->ssl_session) != NGX_OK) {
+ ngx_http_upstream_finalize_request(r, u,
+ NGX_HTTP_INTERNAL_SERVER_ERROR);
+ return;
+ }
+
+ rc = ngx_ssl_handshake(c);
+
+ if (rc == NGX_AGAIN) {
+ c->ssl->handler = ngx_http_upstream_ssl_handshake;
+ return;
+ }
+
+ ngx_http_upstream_ssl_handshake(c);
+
+ return;
+ }
+
+#endif
+
ngx_http_upstream_send_request(r, u);
}
+#if (NGX_HTTP_SSL)
+
+static void
+ngx_http_upstream_ssl_handshake(ngx_connection_t *c)
+{
+ ngx_http_request_t *r;
+ ngx_http_upstream_t *u;
+
+ r = c->data;
+ u = r->upstream;
+
+ if (c->ssl->handshaked) {
+
+ c->write->handler = ngx_http_upstream_send_request_handler;
+ c->read->handler = ngx_http_upstream_process_header;
+
+ ngx_http_upstream_send_request(r, u);
+
+ return;
+ }
+
+ ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR);
+
+}
+
+#endif
+
+
static ngx_int_t
ngx_http_upstream_reinit(ngx_http_request_t *r, ngx_http_upstream_t *u)
{
@@ -591,7 +672,7 @@ ngx_http_upstream_reinit(ngx_http_request_t *r, ngx_http_upstream_t *u)
}
/* reinit the request chain */
-
+
for (cl = u->request_bufs; cl; cl = cl->next) {
cl->buf->pos = cl->buf->start;
cl->buf->file_pos = 0;
@@ -617,9 +698,9 @@ ngx_http_upstream_reinit(ngx_http_request_t *r, ngx_http_upstream_t *u)
u->output.buf = NULL;
u->output.in = NULL;
u->output.busy = NULL;
-
+
/* reinit u->header_in buffer */
-
+
#if 0
if (u->cache) {
u->header_in.pos = u->header_in.start + u->cache->ctx.header_size;
@@ -654,7 +735,7 @@ ngx_http_upstream_send_request(ngx_http_request_t *r, ngx_http_upstream_t *u)
{
int rc;
ngx_connection_t *c;
-
+
c = u->peer.connection;
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
@@ -710,17 +791,17 @@ ngx_http_upstream_send_request(ngx_http_request_t *r, ngx_http_upstream_t *u)
ngx_tcp_push_n " failed");
ngx_http_upstream_finalize_request(r, u,
NGX_HTTP_INTERNAL_SERVER_ERROR);
- return;
+ return;
}
c->tcp_nopush = NGX_TCP_NOPUSH_UNSET;
}
-
+
ngx_add_timer(c->read, u->conf->read_timeout);
#if 1
if (c->read->ready) {
-
+
/* post aio operation */
/*
@@ -799,7 +880,7 @@ ngx_http_upstream_process_header(ngx_event_t *rev)
ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_TIMEOUT);
return;
}
-
+
if (u->header_in.start == NULL) {
u->header_in.start = ngx_palloc(r->pool, u->conf->header_buffer_size);
if (u->header_in.start == NULL) {
@@ -831,8 +912,8 @@ ngx_http_upstream_process_header(ngx_event_t *rev)
#endif
}
- n = ngx_recv(u->peer.connection, u->header_in.last,
- u->header_in.end - u->header_in.last);
+ n = u->peer.connection->recv(u->peer.connection, u->header_in.last,
+ u->header_in.end - u->header_in.last);
if (n == NGX_AGAIN) {
#if 0
@@ -958,7 +1039,7 @@ ngx_http_upstream_process_header(ngx_event_t *rev)
return;
}
- *r->headers_out.www_authenticate =
+ *r->headers_out.www_authenticate =
*u->headers_in.www_authenticate;
}
@@ -985,7 +1066,7 @@ ngx_http_upstream_process_header(ngx_event_t *rev)
if (part->next == NULL) {
break;
}
-
+
part = part->next;
h = part->elts;
i = 0;
@@ -1054,7 +1135,7 @@ ngx_http_upstream_send_response(ngx_http_request_t *r, ngx_http_upstream_t *u)
if (part->next == NULL) {
break;
}
-
+
part = part->next;
h = part->elts;
i = 0;
@@ -1140,13 +1221,13 @@ ngx_http_upstream_send_response(ngx_http_request_t *r, ngx_http_upstream_t *u)
p->output_filter = (ngx_event_pipe_output_filter_pt) ngx_http_output_filter;
p->output_ctx = r;
p->tag = u->output.tag;
- p->bufs = u->conf->bufs;
+ p->bufs = u->conf->bufs;
p->busy_size = u->conf->busy_buffers_size;
p->upstream = u->peer.connection;
p->downstream = r->connection;
p->pool = r->pool;
p->log = r->connection->log;
-
+
p->cachable = u->cachable;
p->temp_file = ngx_pcalloc(r->pool, sizeof(ngx_temp_file_t));
@@ -1159,7 +1240,7 @@ ngx_http_upstream_send_response(ngx_http_request_t *r, ngx_http_upstream_t *u)
p->temp_file->file.log = r->connection->log;
p->temp_file->path = u->conf->temp_path;
p->temp_file->pool = r->pool;
-
+
if (u->cachable) {
p->temp_file->persistent = 1;
} else {
@@ -1257,13 +1338,13 @@ ngx_http_upstream_process_body(ngx_event_t *ev)
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
"http upstream process downstream");
c->log->action = "sending to client";
-
+
} else {
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
"http upstream process upstream");
c->log->action = "reading upstream";
}
-
+
p = &u->pipe;
if (ev->timedout) {
@@ -1292,12 +1373,13 @@ ngx_http_upstream_process_body(ngx_event_t *ev)
} else {
p->downstream_error = 1;
+ c->timedout = 1;
ngx_log_error(NGX_LOG_ERR, c->log, NGX_ETIMEDOUT,
"client timed out");
}
} else {
- p->upstream_error = 1;
+ p->upstream_error = 1;
ngx_log_error(NGX_LOG_ERR, c->log, NGX_ETIMEDOUT,
"upstream timed out");
}
@@ -1319,7 +1401,7 @@ ngx_http_upstream_process_body(ngx_event_t *ev)
return;
}
}
-
+
if (u->peer.connection) {
#if (NGX_HTTP_FILE_CACHE)
@@ -1399,7 +1481,7 @@ ngx_http_upstream_next(ngx_http_request_t *r, ngx_http_upstream_t *u,
ngx_log_error(NGX_LOG_ERR, r->connection->log, NGX_ETIMEDOUT,
"upstream timed out");
}
-
+
if (u->peer.cached && ft_type == NGX_HTTP_UPSTREAM_FT_ERROR) {
status = 0;
@@ -1458,7 +1540,12 @@ ngx_http_upstream_next(ngx_http_request_t *r, ngx_http_upstream_t *u,
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"close http upstream connection: %d",
u->peer.connection->fd);
-
+#if (NGX_HTTP_SSL)
+ if (u->peer.connection->ssl) {
+ ngx_http_upstream_ssl_shutdown(u->peer.connection,
+ &u->peer.peers->peer[u->peer.cur_peer]);
+ }
+#endif
ngx_close_connection(u->peer.connection);
}
@@ -1508,7 +1595,15 @@ ngx_http_upstream_finalize_request(ngx_http_request_t *r,
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"close http upstream connection: %d",
u->peer.connection->fd);
+#if (NGX_HTTP_SSL)
+
+ /* TODO: do not shutdown persistent connection */
+ if (u->peer.connection->ssl) {
+ ngx_http_upstream_ssl_shutdown(u->peer.connection,
+ &u->peer.peers->peer[u->peer.cur_peer]);
+ }
+#endif
ngx_close_connection(u->peer.connection);
}
@@ -1549,12 +1644,41 @@ ngx_http_upstream_finalize_request(ngx_http_request_t *r,
}
+#if (NGX_HTTP_SSL)
+
+static void
+ngx_http_upstream_ssl_shutdown(ngx_connection_t *c, ngx_peer_t *peer)
+{
+ /* lock peer mutex */
+
+ if (peer->ssl_session) {
+ ngx_ssl_free_session(peer->ssl_session);
+ }
+
+ peer->ssl_session = ngx_ssl_get_session(c);
+
+ /* unlock peer mutex */
+
+ /*
+ * We send the "close notify" shutdown alert to the upstream only
+ * and do not wait its "close notify" shutdown alert.
+ * It is acceptable according to the TLS standard.
+ */
+
+ c->ssl->no_wait_shutdown = 1;
+
+ (void) ngx_ssl_shutdown(c);
+}
+
+#endif
+
+
static ngx_int_t
ngx_http_upstream_process_header_line(ngx_http_request_t *r, ngx_table_elt_t *h,
ngx_uint_t offset)
-{
+{
ngx_table_elt_t **ph;
-
+
ph = (ngx_table_elt_t **) ((char *) &r->upstream->headers_in + offset);
if (*ph == NULL) {
@@ -1603,7 +1727,7 @@ ngx_http_upstream_ignore_header_line(ngx_http_request_t *r, ngx_table_elt_t *h,
static ngx_int_t
ngx_http_upstream_process_limit_rate(ngx_http_request_t *r, ngx_table_elt_t *h,
ngx_uint_t offset)
-{
+{
ngx_int_t n;
r->upstream->headers_in.x_accel_limit_rate = h;
@@ -2119,7 +2243,7 @@ ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf)
{
ngx_http_upstream_main_conf_t *umcf = conf;
- umcf->headers_in_hash.max_size = 100;
+ umcf->headers_in_hash.max_size = 100;
umcf->headers_in_hash.bucket_limit = 1;
umcf->headers_in_hash.bucket_size = sizeof(ngx_http_upstream_header_t);
umcf->headers_in_hash.name = "upstream_headers_in";
diff --git a/src/http/ngx_http_upstream.h b/src/http/ngx_http_upstream.h
index 027dd45f9..ad4c1d4cb 100644
--- a/src/http/ngx_http_upstream.h
+++ b/src/http/ngx_http_upstream.h
@@ -85,6 +85,11 @@ typedef struct {
ngx_str_t uri;
ngx_str_t location;
ngx_str_t url; /* used in proxy_rewrite_location */
+
+#if (NGX_HTTP_SSL)
+ ngx_ssl_t *ssl;
+#endif
+
} ngx_http_upstream_conf_t;
diff --git a/src/http/ngx_http_variables.c b/src/http/ngx_http_variables.c
index 2fc2e50ae..f00619d60 100644
--- a/src/http/ngx_http_variables.c
+++ b/src/http/ngx_http_variables.c
@@ -16,8 +16,14 @@ static ngx_int_t ngx_http_variable_header(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data);
static ngx_int_t ngx_http_variable_headers(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_variable_unknown_header(ngx_http_request_t *r,
+
+static ngx_int_t ngx_http_variable_unknown_header_in(ngx_http_request_t *r,
+ ngx_http_variable_value_t *v, uintptr_t data);
+static ngx_int_t ngx_http_variable_unknown_header_out(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data);
+static ngx_int_t ngx_http_variable_unknown_header(ngx_http_variable_value_t *v,
+ ngx_str_t *var, ngx_list_part_t *part, size_t prefix);
+
static ngx_int_t ngx_http_variable_host(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data);
static ngx_int_t ngx_http_variable_remote_addr(ngx_http_request_t *r,
@@ -124,6 +130,12 @@ static ngx_http_variable_t ngx_http_core_variables[] = {
};
+ngx_http_variable_value_t ngx_http_variable_null_value =
+ ngx_http_variable("");
+ngx_http_variable_value_t ngx_http_variable_true_value =
+ ngx_http_variable("1");
+
+
ngx_http_variable_t *
ngx_http_add_variable(ngx_conf_t *cf, ngx_str_t *name, ngx_uint_t flags)
{
@@ -324,7 +336,19 @@ ngx_http_get_variable(ngx_http_request_t *r, ngx_str_t *name)
if (ngx_strncmp(name->data, "http_", 5) == 0) {
- if (ngx_http_variable_unknown_header(r, vv, (uintptr_t) name) == NGX_OK)
+ if (ngx_http_variable_unknown_header_in(r, vv, (uintptr_t) name)
+ == NGX_OK)
+ {
+ return vv;
+ }
+
+ return NULL;
+ }
+
+ if (ngx_strncmp(name->data, "sent_http_", 10) == 0) {
+
+ if (ngx_http_variable_unknown_header_out(r, vv, (uintptr_t) name)
+ == NGX_OK)
{
return vv;
}
@@ -446,17 +470,33 @@ ngx_http_variable_headers(ngx_http_request_t *r, ngx_http_variable_value_t *v,
static ngx_int_t
-ngx_http_variable_unknown_header(ngx_http_request_t *r,
+ngx_http_variable_unknown_header_in(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data)
{
- ngx_str_t *var = (ngx_str_t *) data;
+ return ngx_http_variable_unknown_header(v, (ngx_str_t *) data,
+ &r->headers_in.headers.part,
+ sizeof("http_") - 1);
+}
+
+static ngx_int_t
+ngx_http_variable_unknown_header_out(ngx_http_request_t *r,
+ ngx_http_variable_value_t *v, uintptr_t data)
+{
+ return ngx_http_variable_unknown_header(v, (ngx_str_t *) data,
+ &r->headers_out.headers.part,
+ sizeof("sent_http_") - 1);
+}
+
+
+static ngx_int_t
+ngx_http_variable_unknown_header(ngx_http_variable_value_t *v, ngx_str_t *var,
+ ngx_list_part_t *part, size_t prefix)
+{
u_char ch;
ngx_uint_t i, n;
- ngx_list_part_t *part;
ngx_table_elt_t *header;
- part = &r->headers_in.headers.part;
header = part->elts;
for (i = 0; /* void */ ; i++) {
@@ -471,7 +511,7 @@ ngx_http_variable_unknown_header(ngx_http_request_t *r,
i = 0;
}
- for (n = 0; n + 5 < var->len && n < header[i].key.len; n++) {
+ for (n = 0; n + prefix < var->len && n < header[i].key.len; n++) {
ch = header[i].key.data[n];
if (ch >= 'A' && ch <= 'Z') {
@@ -481,12 +521,12 @@ ngx_http_variable_unknown_header(ngx_http_request_t *r,
ch = '_';
}
- if (var->data[n + 5] != ch) {
+ if (var->data[n + prefix] != ch) {
break;
}
}
- if (n + 5 == var->len) {
+ if (n + prefix == var->len) {
v->len = header[i].value.len;
v->valid = 1;
v->no_cachable = 0;
@@ -556,12 +596,12 @@ ngx_http_variable_remote_port(ngx_http_request_t *r,
}
/* AF_INET only */
-
+
if (r->connection->sockaddr->sa_family == AF_INET) {
sin = (struct sockaddr_in *) r->connection->sockaddr;
-
+
port = ntohs(sin->sin_port);
-
+
if (port > 0 && port < 65536) {
v->len = ngx_sprintf(v->data, "%ui", port) - v->data;
}
@@ -777,7 +817,14 @@ ngx_http_variables_init_vars(ngx_conf_t *cf)
}
if (ngx_strncmp(v[i].name.data, "http_", 5) == 0) {
- v[i].handler = ngx_http_variable_unknown_header;
+ v[i].handler = ngx_http_variable_unknown_header_in;
+ v[i].data = (uintptr_t) &v[i].name;
+
+ continue;
+ }
+
+ if (ngx_strncmp(v[i].name.data, "sent_http_", 10) == 0) {
+ v[i].handler = ngx_http_variable_unknown_header_out;
v[i].data = (uintptr_t) &v[i].name;
continue;
diff --git a/src/http/ngx_http_variables.h b/src/http/ngx_http_variables.h
index 67b781e6d..d1b23e8a7 100644
--- a/src/http/ngx_http_variables.h
+++ b/src/http/ngx_http_variables.h
@@ -64,4 +64,8 @@ ngx_int_t ngx_http_variables_add_core_vars(ngx_conf_t *cf);
ngx_int_t ngx_http_variables_init_vars(ngx_conf_t *cf);
+extern ngx_http_variable_value_t ngx_http_variable_null_value;
+extern ngx_http_variable_value_t ngx_http_variable_true_value;
+
+
#endif /* _NGX_HTTP_VARIABLES_H_INCLUDED_ */