nginx-0.1.24-RELEASE import
*) Feature: the ngx_http_ssi_filter_module supports the QUERY_STRING
and DOCUMENT_URI variables.
*) Bugfix: the ngx_http_autoindex_module may some times return the 404
response for existent directory, if this directory was used in
"alias" directive.
*) Bugfix: the ngx_http_ssi_filter_module ran incorrectly for large
responses.
*) Bugfix: the lack of the "Referer" header line was always accounted
as valid referrer.
diff --git a/src/http/modules/ngx_http_access_handler.c b/src/http/modules/ngx_http_access_handler.c
index 832f9c2..285570f 100644
--- a/src/http/modules/ngx_http_access_handler.c
+++ b/src/http/modules/ngx_http_access_handler.c
@@ -127,7 +127,7 @@
ngx_http_access_rule_t *rule;
if (alcf->rules == NULL) {
- alcf->rules = ngx_create_array(cf->pool, 5,
+ alcf->rules = ngx_create_array(cf->pool, 4,
sizeof(ngx_http_access_rule_t));
if (alcf->rules == NULL) {
return NGX_CONF_ERROR;
diff --git a/src/http/modules/ngx_http_autoindex_handler.c b/src/http/modules/ngx_http_autoindex_handler.c
index f7878c9..8976ad5 100644
--- a/src/http/modules/ngx_http_autoindex_handler.c
+++ b/src/http/modules/ngx_http_autoindex_handler.c
@@ -40,12 +40,12 @@
static int ngx_http_autoindex_cmp_entries(const void *one, const void *two);
-static ngx_int_t ngx_http_autoindex_error(ngx_http_request_t *r, ngx_dir_t *dir,
- u_char *name);
+static ngx_int_t ngx_http_autoindex_error(ngx_http_request_t *r,
+ ngx_dir_t *dir, u_char *name);
static ngx_int_t ngx_http_autoindex_init(ngx_cycle_t *cycle);
static void *ngx_http_autoindex_create_loc_conf(ngx_conf_t *cf);
static char *ngx_http_autoindex_merge_loc_conf(ngx_conf_t *cf,
- void *parent, void *child);
+ void *parent, void *child);
static ngx_command_t ngx_http_autoindex_commands[] = {
@@ -81,7 +81,7 @@
ngx_http_autoindex_commands, /* module directives */
NGX_HTTP_MODULE, /* module type */
ngx_http_autoindex_init, /* init module */
- NULL /* init child */
+ NULL /* init process */
};
@@ -103,7 +103,8 @@
;
-static ngx_int_t ngx_http_autoindex_handler(ngx_http_request_t *r)
+static ngx_int_t
+ngx_http_autoindex_handler(ngx_http_request_t *r)
{
u_char *last;
size_t len;
@@ -146,7 +147,7 @@
if (clcf->alias) {
dname.data = ngx_palloc(pool, clcf->root.len + r->uri.len
- + NGX_DIR_MASK_LEN
+ + NGX_DIR_MASK_LEN + 1
- clcf->name.len);
if (dname.data == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
@@ -154,7 +155,7 @@
last = ngx_cpymem(dname.data, clcf->root.data, clcf->root.len);
last = ngx_cpystrn(last, r->uri.data + clcf->name.len,
- r->uri.len - clcf->name.len);
+ r->uri.len - clcf->name.len + 1);
} else {
dname.data = ngx_palloc(pool, clcf->root.len + r->uri.len
@@ -165,7 +166,6 @@
last = ngx_cpymem(dname.data, clcf->root.data, clcf->root.len);
last = ngx_cpystrn(last, r->uri.data, r->uri.len);
-
}
dname.len = last - dname.data;
@@ -445,7 +445,8 @@
}
-static int ngx_http_autoindex_cmp_entries(const void *one, const void *two)
+static int
+ngx_http_autoindex_cmp_entries(const void *one, const void *two)
{
ngx_http_autoindex_entry_t *first = (ngx_http_autoindex_entry_t *) one;
ngx_http_autoindex_entry_t *second = (ngx_http_autoindex_entry_t *) two;
@@ -466,8 +467,8 @@
#if 0
-static ngx_buf_t *ngx_http_autoindex_alloc(ngx_http_autoindex_ctx_t *ctx,
- size_t size)
+static ngx_buf_t *
+ngx_http_autoindex_alloc(ngx_http_autoindex_ctx_t *ctx, size_t size)
{
ngx_chain_t *cl;
@@ -500,8 +501,8 @@
#endif
-static ngx_int_t ngx_http_autoindex_error(ngx_http_request_t *r, ngx_dir_t *dir,
- u_char *name)
+static ngx_int_t
+ngx_http_autoindex_error(ngx_http_request_t *r, ngx_dir_t *dir, u_char *name)
{
if (ngx_close_dir(dir) == NGX_ERROR) {
ngx_log_error(NGX_LOG_ALERT, r->connection->log, ngx_errno,
@@ -512,7 +513,8 @@
}
-static ngx_int_t ngx_http_autoindex_init(ngx_cycle_t *cycle)
+static ngx_int_t
+ngx_http_autoindex_init(ngx_cycle_t *cycle)
{
ngx_http_handler_pt *h;
ngx_http_core_main_conf_t *cmcf;
@@ -530,7 +532,8 @@
}
-static void *ngx_http_autoindex_create_loc_conf(ngx_conf_t *cf)
+static void *
+ngx_http_autoindex_create_loc_conf(ngx_conf_t *cf)
{
ngx_http_autoindex_loc_conf_t *conf;
@@ -545,8 +548,8 @@
}
-static char *ngx_http_autoindex_merge_loc_conf(ngx_conf_t *cf,
- void *parent, void *child)
+static char *
+ngx_http_autoindex_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
{
ngx_http_autoindex_loc_conf_t *prev = parent;
ngx_http_autoindex_loc_conf_t *conf = child;
diff --git a/src/http/modules/ngx_http_charset_filter.c b/src/http/modules/ngx_http_charset_filter.c
index 0aea91e..cbd0fca 100644
--- a/src/http/modules/ngx_http_charset_filter.c
+++ b/src/http/modules/ngx_http_charset_filter.c
@@ -456,10 +456,10 @@
return NGX_CONF_ERROR;
}
- ngx_init_array(mcf->charsets, cf->pool, 5, sizeof(ngx_http_charset_t),
+ ngx_init_array(mcf->charsets, cf->pool, 2, sizeof(ngx_http_charset_t),
NGX_CONF_ERROR);
- ngx_init_array(mcf->tables, cf->pool, 10, sizeof(ngx_http_charset_tables_t),
+ ngx_init_array(mcf->tables, cf->pool, 4, sizeof(ngx_http_charset_tables_t),
NGX_CONF_ERROR);
return mcf;
diff --git a/src/http/modules/ngx_http_fastcgi_handler.c b/src/http/modules/ngx_http_fastcgi_handler.c
index d613079..5b384b8 100644
--- a/src/http/modules/ngx_http_fastcgi_handler.c
+++ b/src/http/modules/ngx_http_fastcgi_handler.c
@@ -599,7 +599,7 @@
for (i = 0; i < flcf->vars->nelts; i++) {
- if (!(value = ngx_http_get_variable(r, vindex[i]))) {
+ if (!(value = ngx_http_get_indexed_variable(r, vindex[i]))) {
continue;
}
@@ -998,7 +998,7 @@
if (flcf->vars) {
for (i = 0; i < flcf->vars->nelts; i++) {
- if (!(value = ngx_http_get_variable(r, vindex[i]))) {
+ if (!(value = ngx_http_get_indexed_variable(r, vindex[i]))) {
continue;
}
diff --git a/src/http/modules/ngx_http_headers_filter.c b/src/http/modules/ngx_http_headers_filter.c
index ab33414..39b3583 100644
--- a/src/http/modules/ngx_http_headers_filter.c
+++ b/src/http/modules/ngx_http_headers_filter.c
@@ -59,7 +59,7 @@
ngx_http_headers_filter_commands, /* module directives */
NGX_HTTP_MODULE, /* module type */
ngx_http_headers_filter_init, /* init module */
- NULL /* init child */
+ NULL /* init process */
};
diff --git a/src/http/modules/ngx_http_index_handler.c b/src/http/modules/ngx_http_index_handler.c
index 1c7d0df..4e37557 100644
--- a/src/http/modules/ngx_http_index_handler.c
+++ b/src/http/modules/ngx_http_index_handler.c
@@ -86,7 +86,7 @@
ngx_http_index_commands, /* module directives */
NGX_HTTP_MODULE, /* module type */
ngx_http_index_init, /* init module */
- NULL /* init child */
+ NULL /* init process */
};
diff --git a/src/http/modules/ngx_http_range_filter.c b/src/http/modules/ngx_http_range_filter.c
index 0049af6..03f2745 100644
--- a/src/http/modules/ngx_http_range_filter.c
+++ b/src/http/modules/ngx_http_range_filter.c
@@ -73,7 +73,7 @@
NULL, /* module directives */
NGX_HTTP_MODULE, /* module type */
ngx_http_range_header_filter_init, /* init module */
- NULL /* init child */
+ NULL /* init process */
};
@@ -97,7 +97,7 @@
NULL, /* module directives */
NGX_HTTP_MODULE, /* module type */
ngx_http_range_body_filter_init, /* init module */
- NULL /* init child */
+ NULL /* init process */
};
@@ -144,7 +144,7 @@
return ngx_http_next_header_filter(r);
}
- if (ngx_array_init(&r->headers_out.ranges, r->pool, 5,
+ if (ngx_array_init(&r->headers_out.ranges, r->pool, 2,
sizeof(ngx_http_range_t)) == NGX_ERROR)
{
return NGX_ERROR;
diff --git a/src/http/modules/ngx_http_rewrite_handler.c b/src/http/modules/ngx_http_rewrite_handler.c
index d3c721f..3080bd6 100644
--- a/src/http/modules/ngx_http_rewrite_handler.c
+++ b/src/http/modules/ngx_http_rewrite_handler.c
@@ -540,7 +540,7 @@
e->ip += sizeof(ngx_http_rewrite_var_code_t);
- if (!(value = ngx_http_get_variable(e->request, code->index))) {
+ if (!(value = ngx_http_get_indexed_variable(e->request, code->index))) {
*e->sp = (uintptr_t) 0;
return;
}
@@ -698,6 +698,10 @@
ngx_conf_merge_value(conf->no_referer, prev->no_referer, 0);
}
+ if (conf->no_referer == NGX_CONF_UNSET) {
+ conf->no_referer = 0;
+ }
+
if (conf->codes == NULL) {
return NGX_CONF_OK;
}
@@ -1025,12 +1029,12 @@
char *rv;
u_char *elts;
ngx_str_t *value;
+ ngx_int_t index;
ngx_uint_t i;
ngx_conf_t save;
ngx_http_rewrite_code_pt *code;
ngx_http_module_t *module;
ngx_http_conf_ctx_t *ctx, *pctx;
- ngx_http_variable_t *var;
ngx_http_core_loc_conf_t *clcf, *pclcf, **clcfp;
ngx_http_core_main_conf_t *cmcf;
ngx_http_rewrite_if_code_t *if_code;
@@ -1119,23 +1123,11 @@
*code = ngx_http_rewrite_invalid_referer_code;
} else {
-
cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
- var = cmcf->variables.elts;
- for (i = 0; i < cmcf->variables.nelts; i++) {
- if (var[i].name.len != value[1].len) {
- continue;
- }
+ index = ngx_http_get_variable_index(cmcf, &value[1]);
- if (ngx_strncasecmp(var[i].name.data, value[1].data,
- var[i].name.len) == 0)
- {
- break;
- }
- }
-
- if (i == cmcf->variables.nelts) {
+ if (index == -1) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"unknown variable name \"%V\"", &value[1]);
return NGX_CONF_ERROR;
@@ -1148,7 +1140,7 @@
}
var_code->code = ngx_http_rewrite_var_code;
- var_code->index = var[i].index;
+ var_code->index = index;
}
if_code = ngx_array_push_n(lcf->codes, sizeof(ngx_http_rewrite_if_code_t));
diff --git a/src/http/modules/ngx_http_ssi_filter.c b/src/http/modules/ngx_http_ssi_filter.c
index f4b9737..ca877ac 100644
--- a/src/http/modules/ngx_http_ssi_filter.c
+++ b/src/http/modules/ngx_http_ssi_filter.c
@@ -41,6 +41,8 @@
ngx_chain_t *in;
ngx_chain_t *out;
ngx_chain_t **last_out;
+ ngx_chain_t *busy;
+ ngx_chain_t *free;
ngx_uint_t state;
ngx_uint_t saved_state;
@@ -158,7 +160,7 @@
ngx_http_ssi_filter_commands, /* module directives */
NGX_HTTP_MODULE, /* module type */
ngx_http_ssi_filter_init, /* init module */
- NULL /* init child */
+ NULL /* init process */
};
@@ -212,7 +214,8 @@
}
- if (!(ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_ssi_ctx_t)))) {
+ ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_ssi_ctx_t));
+ if (ctx == NULL) {
return NGX_ERROR;
}
@@ -262,7 +265,7 @@
ctx = ngx_http_get_module_ctx(r, ngx_http_ssi_filter_module);
- if (ctx == NULL || (in == NULL && ctx->in == NULL)) {
+ if (ctx == NULL || (in == NULL && ctx->in == NULL && ctx->busy == NULL)) {
return ngx_http_next_body_filter(r, in);
}
@@ -279,19 +282,21 @@
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"http ssi filter");
- b = NULL;
+ while (ctx->in || ctx->buf) {
- while (ctx->in) {
-
- ctx->buf = ctx->in->buf;
- ctx->in = ctx->in->next;
- ctx->pos = ctx->buf->pos;
+ if (ctx->buf == NULL ){
+ ctx->buf = ctx->in->buf;
+ ctx->in = ctx->in->next;
+ ctx->pos = ctx->buf->pos;
+ }
if (ctx->state == ssi_start_state) {
ctx->copy_start = ctx->pos;
ctx->copy_end = ctx->pos;
}
+ b = NULL;
+
while (ctx->pos < ctx->buf->last) {
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
@@ -313,32 +318,60 @@
"saved: %d", ctx->saved);
if (ctx->saved) {
- if (!(b = ngx_calloc_buf(r->pool))) {
- return NGX_ERROR;
+
+ if (ctx->free) {
+ cl = ctx->free;
+ ctx->free = ctx->free->next;
+ b = cl->buf;
+ ngx_memzero(b, sizeof(ngx_buf_t));
+
+ } else {
+ b = ngx_calloc_buf(r->pool);
+ if (b == NULL) {
+ return NGX_ERROR;
+ }
+
+ cl = ngx_alloc_chain_link(r->pool);
+ if (cl == NULL) {
+ return NGX_ERROR;
+ }
+
+ cl->buf = b;
}
b->memory = 1;
b->pos = ngx_http_ssi_string;
b->last = ngx_http_ssi_string + ctx->saved;
- if (!(cl = ngx_alloc_chain_link(r->pool))) {
- return NGX_ERROR;
- }
-
- cl->buf = b;
*ctx->last_out = cl;
ctx->last_out = &cl->next;
ctx->saved = 0;
}
- if (!(b = ngx_calloc_buf(r->pool))) {
- return NGX_ERROR;
+ if (ctx->free) {
+ cl = ctx->free;
+ ctx->free = ctx->free->next;
+ b = cl->buf;
+
+ } else {
+ b = ngx_alloc_buf(r->pool);
+ if (b == NULL) {
+ return NGX_ERROR;
+ }
+
+ cl = ngx_alloc_chain_link(r->pool);
+ if (cl == NULL) {
+ return NGX_ERROR;
+ }
+
+ cl->buf = b;
}
ngx_memcpy(b, ctx->buf, sizeof(ngx_buf_t));
b->last_buf = 0;
+ b->recycled = 0;
b->pos = ctx->copy_start;
b->last = ctx->copy_end;
@@ -353,11 +386,6 @@
}
}
- if (!(cl = ngx_alloc_chain_link(r->pool))) {
- return NGX_ERROR;
- }
-
- cl->buf = b;
cl->next = NULL;
*ctx->last_out = cl;
ctx->last_out = &cl->next;
@@ -461,14 +489,30 @@
/* rc == NGX_HTTP_SSI_ERROR */
-ssi_error:
+ ssi_error:
if (conf->silent_errors) {
continue;
}
- if (!(b = ngx_calloc_buf(r->pool))) {
- return NGX_ERROR;
+ if (ctx->free) {
+ cl = ctx->free;
+ ctx->free = ctx->free->next;
+ b = cl->buf;
+ ngx_memzero(b, sizeof(ngx_buf_t));
+
+ } else {
+ b = ngx_calloc_buf(r->pool);
+ if (b == NULL) {
+ return NGX_ERROR;
+ }
+
+ cl = ngx_alloc_chain_link(r->pool);
+ if (cl == NULL) {
+ return NGX_ERROR;
+ }
+
+ cl->buf = b;
}
b->memory = 1;
@@ -476,11 +520,6 @@
b->last = ngx_http_ssi_error_string
+ sizeof(ngx_http_ssi_error_string) - 1;
- if (!(cl = ngx_alloc_chain_link(r->pool))) {
- return NGX_ERROR;
- }
-
- cl->buf = b;
cl->next = NULL;
*ctx->last_out = cl;
ctx->last_out = &cl->next;
@@ -488,24 +527,85 @@
continue;
}
- ctx->buf->pos = ctx->buf->last;
+ if (ctx->buf->recycled || ctx->buf->last_buf) {
+ if (b == NULL) {
- if (b && ctx->buf->last_buf) {
- b->last_buf = 1;
+ if (ctx->free) {
+ cl = ctx->free;
+ ctx->free = ctx->free->next;
+ b = cl->buf;
+ ngx_memzero(b, sizeof(ngx_buf_t));
+
+ } else {
+ b = ngx_calloc_buf(r->pool);
+ if (b == NULL) {
+ return NGX_ERROR;
+ }
+
+ cl = ngx_alloc_chain_link(r->pool);
+ if (cl == NULL) {
+ return NGX_ERROR;
+ }
+
+ cl->buf = b;
+ }
+
+ cl->next = NULL;
+ *ctx->last_out = cl;
+ ctx->last_out = &cl->next;
+ }
+
+ b->last_buf = ctx->buf->last_buf;
+ b->flush = ctx->buf->recycled;
+ b->shadow = ctx->buf;
}
+ ctx->buf = NULL;
+
ctx->saved = ctx->looked;
}
- if (ctx->out == NULL) {
+ if (ctx->out == NULL && ctx->busy == NULL) {
return NGX_OK;
}
rc = ngx_http_next_body_filter(r, ctx->out);
+ if (ctx->busy == NULL) {
+ ctx->busy = ctx->out;
+
+ } else {
+ for (cl = ctx->busy; cl->next; cl = cl->next) { /* void */ }
+ cl->next = ctx->out;
+ }
+
ctx->out = NULL;
ctx->last_out = &ctx->out;
+ while (ctx->busy) {
+
+ b = ctx->busy->buf;
+
+ if (ngx_buf_size(b) != 0) {
+ break;
+ }
+
+#if (NGX_HAVE_WRITE_ZEROCOPY)
+ if (b->zerocopy_busy) {
+ break;
+ }
+#endif
+
+ if (b->shadow) {
+ b->shadow->pos = b->shadow->last;
+ }
+
+ cl = ctx->busy;
+ ctx->busy = cl->next;
+ cl->next = ctx->free;
+ ctx->free = cl;
+ }
+
return rc;
}
@@ -530,16 +630,20 @@
/* the tight loop */
- for ( /* void */ ; p < last; ch = *(++p)) {
- if (ch != '<') {
- continue;
+ for ( ;; ) {
+ if (ch == '<') {
+ copy_end = p;
+ looked = 1;
+ state = ssi_tag_state;
+
+ goto tag_started;
}
- copy_end = p;
- looked = 1;
- state = ssi_tag_state;
+ if (++p == last) {
+ break;
+ }
- goto tag_started;
+ ch = *p;
}
ctx->pos = p;
@@ -552,7 +656,8 @@
return NGX_AGAIN;
-tag_started:
+ tag_started:
+
continue;
}
@@ -715,7 +820,8 @@
break;
default:
- if (!(ctx->param = ngx_array_push(&ctx->params))) {
+ ctx->param = ngx_array_push(&ctx->params);
+ if (ctx->param == NULL) {
return NGX_ERROR;
}
@@ -1041,80 +1147,45 @@
ngx_http_ssi_echo(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx,
ngx_str_t **params)
{
- u_char ch;
- ngx_uint_t i, n;
- ngx_buf_t *b;
- ngx_str_t *var, *value;
- ngx_chain_t *cl;
- ngx_list_part_t *part;
- ngx_table_elt_t *header;
+ ngx_buf_t *b;
+ ngx_str_t *var, *value;
+ ngx_chain_t *cl;
+ ngx_http_variable_value_t *v;
var = params[NGX_HTTP_SSI_ECHO_VAR];
value = NULL;
- if (var->len > 5 && ngx_strncmp(var->data, "HTTP_", 5) == 0) {
+ v = ngx_http_get_variable(r, var);
- part = &r->headers_in.headers.part;
- header = part->elts;
-
- for (i = 0; /* void */ ; i++) {
-
- if (i >= part->nelts) {
- if (part->next == NULL) {
- break;
- }
-
- part = part->next;
- header = part->elts;
- i = 0;
- }
-
- for (n = 0; n + 5 < var->len && n < header[i].key.len; n++)
- {
- ch = header[i].key.data[n];
-
- if (ch >= 'a' && ch <= 'z') {
- ch &= ~0x20;
-
- } else if (ch == '-') {
- ch = '_';
- }
-
- if (var->data[n + 5] != ch) {
- break;
- }
- }
-
- if (n + 5 == var->len) {
- value = &header[i].value;
- break;
- }
- }
-
- } else if (var->len == sizeof("REMOTE_ADDR") - 1
- && ngx_strncmp(var->data, "REMOTE_ADDR",
- sizeof("REMOTE_ADDR") - 1) == 0)
- {
- value = &r->connection->addr_text;
- }
-
-
- if (value == NULL) {
- value = params[NGX_HTTP_SSI_ECHO_DEFAULT];
- }
-
- if (value == NULL) {
- value = &ngx_http_ssi_none;
-
- } else if (value->len == 0) {
- return NGX_OK;
- }
-
- if (!(b = ngx_calloc_buf(r->pool))) {
+ if (v == NULL) {
return NGX_HTTP_SSI_ERROR;
}
- if (!(cl = ngx_alloc_chain_link(r->pool))) {
+ if (v == NGX_HTTP_VARIABLE_NOT_FOUND) {
+ value = params[NGX_HTTP_SSI_ECHO_DEFAULT];
+
+ if (value == NULL) {
+ value = &ngx_http_ssi_none;
+
+ } else if (value->len == 0) {
+ return NGX_OK;
+ }
+
+ } else {
+ value = &v->text;
+
+ if (value->len == 0) {
+ return NGX_OK;
+ }
+ }
+
+ b = ngx_calloc_buf(r->pool);
+ if (b == NULL) {
+ return NGX_HTTP_SSI_ERROR;
+ }
+
+ cl = ngx_alloc_chain_link(r->pool);
+ if (cl == NULL) {
return NGX_HTTP_SSI_ERROR;
}
@@ -1136,7 +1207,8 @@
{
ngx_http_ssi_conf_t *conf;
- if (!(conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_ssi_conf_t)))) {
+ conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_ssi_conf_t));
+ if (conf == NULL) {
return NGX_CONF_ERROR;
}
diff --git a/src/http/modules/ngx_http_static_handler.c b/src/http/modules/ngx_http_static_handler.c
index 1ff45da..4f0f96d 100644
--- a/src/http/modules/ngx_http_static_handler.c
+++ b/src/http/modules/ngx_http_static_handler.c
@@ -59,7 +59,7 @@
ngx_http_static_commands, /* module directives */
NGX_HTTP_MODULE, /* module type */
ngx_http_static_init, /* init module */
- NULL /* init child */
+ NULL /* init process */
};
diff --git a/src/http/modules/ngx_http_userid_filter.c b/src/http/modules/ngx_http_userid_filter.c
index aee161b..ea49f92 100644
--- a/src/http/modules/ngx_http_userid_filter.c
+++ b/src/http/modules/ngx_http_userid_filter.c
@@ -38,30 +38,29 @@
static ngx_int_t ngx_http_userid_get_uid(ngx_http_request_t *r,
- ngx_http_userid_ctx_t *ctx,
- ngx_http_userid_conf_t *conf);
+ ngx_http_userid_ctx_t *ctx, ngx_http_userid_conf_t *conf);
static ngx_int_t ngx_http_userid_set_uid(ngx_http_request_t *r,
- ngx_http_userid_ctx_t *ctx,
- ngx_http_userid_conf_t *conf);
+ ngx_http_userid_ctx_t *ctx, ngx_http_userid_conf_t *conf);
static size_t ngx_http_userid_log_uid_got_getlen(ngx_http_request_t *r,
- uintptr_t data);
+ uintptr_t data);
static u_char *ngx_http_userid_log_uid_got(ngx_http_request_t *r, u_char *buf,
- ngx_http_log_op_t *op);
+ ngx_http_log_op_t *op);
static size_t ngx_http_userid_log_uid_set_getlen(ngx_http_request_t *r,
- uintptr_t data);
+ uintptr_t data);
static u_char *ngx_http_userid_log_uid_set(ngx_http_request_t *r, u_char *buf,
- ngx_http_log_op_t *op);
+ ngx_http_log_op_t *op);
static ngx_int_t ngx_http_userid_add_log_formats(ngx_conf_t *cf);
static ngx_int_t ngx_http_userid_init(ngx_cycle_t *cycle);
static void *ngx_http_userid_create_conf(ngx_conf_t *cf);
static char *ngx_http_userid_merge_conf(ngx_conf_t *cf, void *parent,
- void *child);
-char *ngx_http_userid_domain(ngx_conf_t *cf, void *post, void *data);
-char *ngx_http_userid_path(ngx_conf_t *cf, void *post, void *data);
-char *ngx_http_userid_expires(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
-char *ngx_http_userid_p3p(ngx_conf_t *cf, void *post, void *data);
+ void *child);
+static char *ngx_http_userid_domain(ngx_conf_t *cf, void *post, void *data);
+static char *ngx_http_userid_path(ngx_conf_t *cf, void *post, void *data);
+static char *ngx_http_userid_expires(ngx_conf_t *cf, ngx_command_t *cmd,
+ void *conf);
+static char *ngx_http_userid_p3p(ngx_conf_t *cf, void *post, void *data);
static uint32_t sequencer_v1 = 1;
@@ -141,7 +140,7 @@
offsetof(ngx_http_userid_conf_t, p3p),
&ngx_http_userid_p3p_p },
- ngx_null_command
+ ngx_null_command
};
@@ -180,7 +179,8 @@
};
-static ngx_int_t ngx_http_userid_filter(ngx_http_request_t *r)
+static ngx_int_t
+ngx_http_userid_filter(ngx_http_request_t *r)
{
ngx_int_t rc;
ngx_http_userid_ctx_t *ctx;
@@ -192,8 +192,14 @@
return ngx_http_next_header_filter(r);
}
- ngx_http_create_ctx(r, ctx, ngx_http_userid_filter_module,
- sizeof(ngx_http_userid_ctx_t), NGX_ERROR);
+
+ ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_userid_ctx_t));
+ if (ctx == NULL) {
+ return NGX_ERROR;
+ }
+
+ ngx_http_set_ctx(r, ctx, ngx_http_userid_filter_module);
+
rc = ngx_http_userid_get_uid(r, ctx, conf);
@@ -215,9 +221,9 @@
}
-static ngx_int_t ngx_http_userid_get_uid(ngx_http_request_t *r,
- ngx_http_userid_ctx_t *ctx,
- ngx_http_userid_conf_t *conf)
+static ngx_int_t
+ngx_http_userid_get_uid(ngx_http_request_t *r, ngx_http_userid_ctx_t *ctx,
+ ngx_http_userid_conf_t *conf)
{
u_char *start, *last, *end;
ngx_uint_t i;
@@ -299,9 +305,9 @@
}
-static ngx_int_t ngx_http_userid_set_uid(ngx_http_request_t *r,
- ngx_http_userid_ctx_t *ctx,
- ngx_http_userid_conf_t *conf)
+static ngx_int_t
+ngx_http_userid_set_uid(ngx_http_request_t *r, ngx_http_userid_ctx_t *ctx,
+ ngx_http_userid_conf_t *conf)
{
u_char *cookie, *p;
size_t len;
@@ -363,7 +369,8 @@
len += conf->domain.len;
}
- if (!(cookie = ngx_palloc(r->pool, len))) {
+ cookie = ngx_palloc(r->pool, len);
+ if (cookie == NULL) {
return NGX_ERROR;
}
@@ -392,7 +399,8 @@
p = ngx_cpymem(p, conf->path.data, conf->path.len);
- if (!(set_cookie = ngx_list_push(&r->headers_out.headers))) {
+ set_cookie = ngx_list_push(&r->headers_out.headers);
+ if (set_cookie == NULL) {
return NGX_ERROR;
}
@@ -408,7 +416,8 @@
return NGX_OK;
}
- if (!(p3p = ngx_list_push(&r->headers_out.headers))) {
+ p3p = ngx_list_push(&r->headers_out.headers);
+ if (p3p == NULL) {
return NGX_ERROR;
}
@@ -420,8 +429,8 @@
}
-static size_t ngx_http_userid_log_uid_got_getlen(ngx_http_request_t *r,
- uintptr_t data)
+static size_t
+ngx_http_userid_log_uid_got_getlen(ngx_http_request_t *r, uintptr_t data)
{
ngx_http_userid_ctx_t *ctx;
ngx_http_userid_conf_t *conf;
@@ -438,8 +447,9 @@
}
-static u_char *ngx_http_userid_log_uid_got(ngx_http_request_t *r, u_char *buf,
- ngx_http_log_op_t *op)
+static u_char *
+ngx_http_userid_log_uid_got(ngx_http_request_t *r, u_char *buf,
+ ngx_http_log_op_t *op)
{
ngx_http_userid_ctx_t *ctx;
ngx_http_userid_conf_t *conf;
@@ -463,8 +473,8 @@
}
-static size_t ngx_http_userid_log_uid_set_getlen(ngx_http_request_t *r,
- uintptr_t data)
+static size_t
+ngx_http_userid_log_uid_set_getlen(ngx_http_request_t *r, uintptr_t data)
{
ngx_http_userid_ctx_t *ctx;
ngx_http_userid_conf_t *conf;
@@ -481,8 +491,9 @@
}
-static u_char *ngx_http_userid_log_uid_set(ngx_http_request_t *r, u_char *buf,
- ngx_http_log_op_t *op)
+static u_char *
+ngx_http_userid_log_uid_set(ngx_http_request_t *r, u_char *buf,
+ ngx_http_log_op_t *op)
{
ngx_http_userid_ctx_t *ctx;
ngx_http_userid_conf_t *conf;
@@ -506,7 +517,8 @@
}
-static ngx_int_t ngx_http_userid_add_log_formats(ngx_conf_t *cf)
+static ngx_int_t
+ngx_http_userid_add_log_formats(ngx_conf_t *cf)
{
ngx_http_log_op_name_t *op;
@@ -525,7 +537,8 @@
}
-static ngx_int_t ngx_http_userid_init(ngx_cycle_t *cycle)
+static ngx_int_t
+ngx_http_userid_init(ngx_cycle_t *cycle)
{
ngx_http_next_header_filter = ngx_http_top_header_filter;
ngx_http_top_header_filter = ngx_http_userid_filter;
@@ -534,11 +547,13 @@
}
-static void *ngx_http_userid_create_conf(ngx_conf_t *cf)
+static void *
+ngx_http_userid_create_conf(ngx_conf_t *cf)
{
ngx_http_userid_conf_t *conf;
- if (!(conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_userid_conf_t)))) {
+ conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_userid_conf_t));
+ if (conf == NULL) {
return NGX_CONF_ERROR;
}
@@ -563,8 +578,8 @@
}
-static char *ngx_http_userid_merge_conf(ngx_conf_t *cf, void *parent,
- void *child)
+static char *
+ngx_http_userid_merge_conf(ngx_conf_t *cf, void *parent, void *child)
{
ngx_http_userid_conf_t *prev = parent;
ngx_http_userid_conf_t *conf = child;
@@ -583,7 +598,8 @@
}
-char *ngx_http_userid_domain(ngx_conf_t *cf, void *post, void *data)
+static char *
+ngx_http_userid_domain(ngx_conf_t *cf, void *post, void *data)
{
ngx_str_t *domain = data;
@@ -596,7 +612,8 @@
return NGX_CONF_OK;
}
- if (!(new = ngx_palloc(cf->pool, sizeof("; domain=") - 1 + domain->len))) {
+ new = ngx_palloc(cf->pool, sizeof("; domain=") - 1 + domain->len);
+ if (new == NULL) {
return NGX_CONF_ERROR;
}
@@ -610,13 +627,15 @@
}
-char *ngx_http_userid_path(ngx_conf_t *cf, void *post, void *data)
+static char *
+ngx_http_userid_path(ngx_conf_t *cf, void *post, void *data)
{
ngx_str_t *path = data;
u_char *p, *new;
- if (!(new = ngx_palloc(cf->pool, sizeof("; path=") - 1 + path->len))) {
+ new = ngx_palloc(cf->pool, sizeof("; path=") - 1 + path->len);
+ if (new == NULL) {
return NGX_CONF_ERROR;
}
@@ -630,7 +649,8 @@
}
-char *ngx_http_userid_expires(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
+static char *
+ngx_http_userid_expires(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_http_userid_conf_t *ucf = conf;
@@ -665,7 +685,8 @@
}
-char *ngx_http_userid_p3p(ngx_conf_t *cf, void *post, void *data)
+static char *
+ngx_http_userid_p3p(ngx_conf_t *cf, void *post, void *data)
{
ngx_str_t *p3p = data;
diff --git a/src/http/modules/proxy/ngx_http_proxy_upstream.c b/src/http/modules/proxy/ngx_http_proxy_upstream.c
index e35433b..061ab9f 100644
--- a/src/http/modules/proxy/ngx_http_proxy_upstream.c
+++ b/src/http/modules/proxy/ngx_http_proxy_upstream.c
@@ -190,7 +190,7 @@
for (i = 0; i < p->lcf->x_vars->nelts; i++) {
- if (!(value = ngx_http_get_variable(r, index[i]))) {
+ if (!(value = ngx_http_get_indexed_variable(r, index[i]))) {
continue;
}
@@ -379,7 +379,7 @@
if (p->lcf->x_vars) {
for (i = 0; i < p->lcf->x_vars->nelts; i++) {
- if (!(value = ngx_http_get_variable(r, index[i]))) {
+ if (!(value = ngx_http_get_indexed_variable(r, index[i]))) {
continue;
}
diff --git a/src/http/ngx_http.c b/src/http/ngx_http.c
index 26f1cb4..f9c9260 100644
--- a/src/http/ngx_http.c
+++ b/src/http/ngx_http.c
@@ -13,18 +13,13 @@
static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
static int ngx_cmp_server_names(const void *one, const void *two);
static ngx_int_t ngx_http_add_address(ngx_conf_t *cf,
- ngx_http_in_port_t *in_port,
- ngx_http_listen_t *lscf,
- ngx_http_core_srv_conf_t *cscf);
+ ngx_http_in_port_t *in_port, ngx_http_listen_t *lscf,
+ ngx_http_core_srv_conf_t *cscf);
static ngx_int_t ngx_http_add_names(ngx_conf_t *cf,
- ngx_http_in_addr_t *in_addr,
- ngx_http_core_srv_conf_t *cscf);
-
+ ngx_http_in_addr_t *in_addr, ngx_http_core_srv_conf_t *cscf);
static char *ngx_http_merge_locations(ngx_conf_t *cf,
- ngx_array_t *locations,
- void **loc_conf,
- ngx_http_module_t *module,
- ngx_uint_t ctx_index);
+ ngx_array_t *locations, void **loc_conf, ngx_http_module_t *module,
+ ngx_uint_t ctx_index);
ngx_uint_t ngx_http_max_module;
@@ -38,14 +33,14 @@
static ngx_command_t ngx_http_commands[] = {
- {ngx_string("http"),
- NGX_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS,
- ngx_http_block,
- 0,
- 0,
- NULL},
+ { ngx_string("http"),
+ NGX_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS,
+ ngx_http_block,
+ 0,
+ 0,
+ NULL },
- ngx_null_command
+ ngx_null_command
};
@@ -62,11 +57,12 @@
ngx_http_commands, /* module directives */
NGX_CORE_MODULE, /* module type */
NULL, /* init module */
- NULL /* init child */
+ NULL /* init process */
};
-static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
+static char *
+ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
char *rv;
ngx_uint_t mi, m, s, l, p, a, n;
@@ -686,7 +682,8 @@
}
-static int ngx_cmp_server_names(const void *one, const void *two)
+static int
+ngx_cmp_server_names(const void *one, const void *two)
{
ngx_http_server_name_t *first = (ngx_http_server_name_t *) one;
ngx_http_server_name_t *second = (ngx_http_server_name_t *) two;
@@ -700,10 +697,9 @@
* configurations to the port (in_port)
*/
-static ngx_int_t ngx_http_add_address(ngx_conf_t *cf,
- ngx_http_in_port_t *in_port,
- ngx_http_listen_t *lscf,
- ngx_http_core_srv_conf_t *cscf)
+static ngx_int_t
+ngx_http_add_address(ngx_conf_t *cf, ngx_http_in_port_t *in_port,
+ ngx_http_listen_t *lscf, ngx_http_core_srv_conf_t *cscf)
{
ngx_http_in_addr_t *in_addr;
@@ -744,9 +740,9 @@
* configurations to the address:port (in_addr)
*/
-static ngx_int_t ngx_http_add_names(ngx_conf_t *cf,
- ngx_http_in_addr_t *in_addr,
- ngx_http_core_srv_conf_t *cscf)
+static ngx_int_t
+ngx_http_add_names(ngx_conf_t *cf, ngx_http_in_addr_t *in_addr,
+ ngx_http_core_srv_conf_t *cscf)
{
ngx_uint_t i, n;
ngx_array_t *array;
@@ -800,11 +796,9 @@
}
-static char *ngx_http_merge_locations(ngx_conf_t *cf,
- ngx_array_t *locations,
- void **loc_conf,
- ngx_http_module_t *module,
- ngx_uint_t ctx_index)
+static char *
+ngx_http_merge_locations(ngx_conf_t *cf, ngx_array_t *locations,
+ void **loc_conf, ngx_http_module_t *module, ngx_uint_t ctx_index)
{
char *rv;
ngx_uint_t i;
diff --git a/src/http/ngx_http.h b/src/http/ngx_http.h
index a21c670..6f19af1 100644
--- a/src/http/ngx_http.h
+++ b/src/http/ngx_http.h
@@ -29,6 +29,7 @@
#include <ngx_http_busy_lock.h>
#include <ngx_http_log_handler.h>
#include <ngx_http_core_module.h>
+#include <ngx_http_variables.h>
#if (NGX_HTTP_SSL)
#include <ngx_http_ssl_module.h>
@@ -41,9 +42,9 @@
};
-#define ngx_http_get_module_ctx(r, module) r->ctx[module.ctx_index]
+#define ngx_http_get_module_ctx(r, module) (r)->ctx[module.ctx_index]
#define ngx_http_get_module_err_ctx(r, module) \
- (r->err_ctx ? r->err_ctx[module.ctx_index] : r->ctx[module.ctx_index])
+ ((r)->err_ctx ? (r)->err_ctx[module.ctx_index] : (r)->ctx[module.ctx_index])
/* STUB */
#define ngx_http_create_ctx(r, cx, module, size, error) \
@@ -53,11 +54,9 @@
} while (0)
/**/
-#define ngx_http_set_ctx(r, c, module) \
- r->ctx[module.ctx_index] = c;
+#define ngx_http_set_ctx(r, c, module) r->ctx[module.ctx_index] = c;
-#define ngx_http_delete_ctx(r, module) \
- r->ctx[module.ctx_index] = NULL;
+#define ngx_http_delete_ctx(r, module) r->ctx[module.ctx_index] = NULL;
void ngx_http_init_connection(ngx_connection_t *c);
@@ -79,10 +78,11 @@
ngx_int_t ngx_http_read_client_request_body(ngx_http_request_t *r,
- ngx_http_client_body_handler_pt post_handler);
+ ngx_http_client_body_handler_pt post_handler);
ngx_int_t ngx_http_send_header(ngx_http_request_t *r);
-ngx_int_t ngx_http_special_response_handler(ngx_http_request_t *r, int error);
+ngx_int_t ngx_http_special_response_handler(ngx_http_request_t *r,
+ ngx_int_t error);
time_t ngx_http_parse_time(u_char *value, size_t len);
diff --git a/src/http/ngx_http_config.h b/src/http/ngx_http_config.h
index 85be911..0bf6338 100644
--- a/src/http/ngx_http_config.h
+++ b/src/http/ngx_http_config.h
@@ -48,9 +48,10 @@
#define NGX_HTTP_LOC_CONF_OFFSET offsetof(ngx_http_conf_ctx_t, loc_conf)
-#define ngx_http_get_module_main_conf(r, module) r->main_conf[module.ctx_index]
-#define ngx_http_get_module_srv_conf(r, module) r->srv_conf[module.ctx_index]
-#define ngx_http_get_module_loc_conf(r, module) r->loc_conf[module.ctx_index]
+#define ngx_http_get_module_main_conf(r, module) \
+ (r)->main_conf[module.ctx_index]
+#define ngx_http_get_module_srv_conf(r, module) (r)->srv_conf[module.ctx_index]
+#define ngx_http_get_module_loc_conf(r, module) (r)->loc_conf[module.ctx_index]
/*
* ngx_http_conf_get_module_srv_conf() and ngx_http_conf_get_module_loc_conf()
diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
index b3c1a14..c773d8f 100644
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -55,6 +55,7 @@
void *conf);
static char *ngx_http_core_lowat_check(ngx_conf_t *cf, void *post, void *data);
+static ngx_int_t ngx_http_core_init(ngx_cycle_t *cycle);
static ngx_conf_post_t ngx_http_core_lowat_post =
{ ngx_http_core_lowat_check };
@@ -355,7 +356,7 @@
&ngx_http_core_module_ctx, /* module context */
ngx_http_core_commands, /* module directives */
NGX_HTTP_MODULE, /* module type */
- NULL, /* init module */
+ ngx_http_core_init, /* init module */
NULL /* init process */
};
@@ -984,54 +985,6 @@
#endif
-ngx_http_variable_t *
-ngx_http_add_variable(ngx_conf_t *cf)
-{
- ngx_http_variable_t *var;
- ngx_http_core_main_conf_t *cmcf;
-
- cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
-
- if (cmcf->variables.elts == NULL) {
- if (ngx_array_init(&cmcf->variables, cf->pool, 5,
- sizeof(ngx_http_variable_t)) == NGX_ERROR)
- {
- return NULL;
- }
- }
-
- if (!(var = ngx_array_push(&cmcf->variables))) {
- return NULL;
- }
-
- var->index = cmcf->variables.nelts - 1;
-
- return var;
-}
-
-
-ngx_http_variable_value_t *
-ngx_http_get_variable(ngx_http_request_t *r, ngx_uint_t index)
-{
- ngx_http_variable_t *v;
- ngx_http_core_main_conf_t *cmcf;
-
- /* TODO: cached variables */
-
- cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
-
- if (cmcf->variables.elts == NULL || cmcf->variables.nelts <= index) {
- ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
- "unknown variable index: %d", index);
- return NULL;
- }
-
- v = cmcf->variables.elts;
-
- return v[index].handler(r, v[index].data);
-}
-
-
static char *
ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
{
@@ -1381,7 +1334,7 @@
}
for (i = 0; i < NGX_HTTP_TYPES_HASH_PRIME; i++) {
- if (ngx_array_init(&lcf->types[i], cf->pool, 5,
+ if (ngx_array_init(&lcf->types[i], cf->pool, 4,
sizeof(ngx_http_type_t)) == NGX_ERROR)
{
return NGX_CONF_ERROR;
@@ -1415,7 +1368,7 @@
return NGX_CONF_ERROR;
}
- if (ngx_array_init(&cmcf->servers, cf->pool, 5,
+ if (ngx_array_init(&cmcf->servers, cf->pool, 4,
sizeof(ngx_http_core_srv_conf_t *)) == NGX_ERROR)
{
return NGX_CONF_ERROR;
@@ -1460,19 +1413,19 @@
* conf->client_large_buffers.num = 0;
*/
- if (ngx_array_init(&cscf->locations, cf->pool, 5, sizeof(void *))
+ if (ngx_array_init(&cscf->locations, cf->pool, 4, sizeof(void *))
== NGX_ERROR)
{
return NGX_CONF_ERROR;
}
- if (ngx_array_init(&cscf->listen, cf->pool, 5, sizeof(ngx_http_listen_t))
+ if (ngx_array_init(&cscf->listen, cf->pool, 4, sizeof(ngx_http_listen_t))
== NGX_ERROR)
{
return NGX_CONF_ERROR;
}
- if (ngx_array_init(&cscf->server_names, cf->pool, 5,
+ if (ngx_array_init(&cscf->server_names, cf->pool, 4,
sizeof(ngx_http_server_name_t)) == NGX_ERROR)
{
return NGX_CONF_ERROR;
@@ -1654,7 +1607,7 @@
}
for (i = 0; i < NGX_HTTP_TYPES_HASH_PRIME; i++) {
- if (ngx_array_init(&conf->types[i], cf->pool, 5,
+ if (ngx_array_init(&conf->types[i], cf->pool, 4,
sizeof(ngx_http_type_t)) == NGX_ERROR)
{
return NGX_CONF_ERROR;
@@ -2063,3 +2016,10 @@
return NGX_CONF_OK;
}
+
+
+static ngx_int_t
+ngx_http_core_init(ngx_cycle_t *cycle)
+{
+ return ngx_http_core_variables_init(cycle);
+}
diff --git a/src/http/ngx_http_core_module.h b/src/http/ngx_http_core_module.h
index dbaef6f..f8c6017 100644
--- a/src/http/ngx_http_core_module.h
+++ b/src/http/ngx_http_core_module.h
@@ -37,27 +37,6 @@
typedef struct {
- ngx_uint_t value;
- ngx_str_t text;
-} ngx_http_variable_value_t;
-
-
-typedef struct ngx_http_variable_s ngx_http_variable_t;
-
-typedef ngx_http_variable_value_t
- *(*ngx_http_get_variable_pt) (ngx_http_request_t *r, void *var);
-
-
-struct ngx_http_variable_s {
- ngx_str_t name;
- ngx_uint_t index;
- ngx_http_get_variable_pt handler;
- void *data;
- ngx_uint_t uses;
-};
-
-
-typedef struct {
ngx_array_t handlers;
ngx_int_t type; /* NGX_OK, NGX_DECLINED */
} ngx_http_phase_t;
@@ -250,16 +229,12 @@
ngx_int_t ngx_http_set_exten(ngx_http_request_t *r);
ngx_int_t ngx_http_internal_redirect(ngx_http_request_t *r,
- ngx_str_t *uri, ngx_str_t *args);
-
-ngx_http_variable_t *ngx_http_add_variable(ngx_conf_t *cf);
-ngx_http_variable_value_t *ngx_http_get_variable(ngx_http_request_t *r,
- ngx_uint_t index);
+ ngx_str_t *uri, ngx_str_t *args);
typedef ngx_int_t (*ngx_http_output_header_filter_pt)(ngx_http_request_t *r);
typedef ngx_int_t (*ngx_http_output_body_filter_pt)
- (ngx_http_request_t *r, ngx_chain_t *chain);
+ (ngx_http_request_t *r, ngx_chain_t *chain);
ngx_int_t ngx_http_output_filter(ngx_http_request_t *r, ngx_chain_t *chain);
diff --git a/src/http/ngx_http_header_filter.c b/src/http/ngx_http_header_filter.c
index ea0907f..65d8dee 100644
--- a/src/http/ngx_http_header_filter.c
+++ b/src/http/ngx_http_header_filter.c
@@ -34,7 +34,7 @@
NULL, /* module directives */
NGX_HTTP_MODULE, /* module type */
ngx_http_header_filter_init, /* init module */
- NULL /* init child */
+ NULL /* init process */
};
@@ -50,47 +50,68 @@
ngx_null_string, /* "204 No Content" */
ngx_null_string, /* "205 Reset Content" */
ngx_string("206 Partial Content"),
- ngx_null_string, /* "207 Multi-Status" */
-#if 0
- ngx_null_string, /* "300 Multiple Choices" */
-#endif
+ /* ngx_null_string, */ /* "207 Multi-Status" */
+
+#define NGX_HTTP_LEVEL_200 7
+
+ /* ngx_null_string, */ /* "300 Multiple Choices" */
ngx_string("301 Moved Permanently"),
-#if 0
ngx_string("302 Moved Temporarily"),
-#else
- ngx_string("302 Found"),
-#endif
ngx_null_string, /* "303 See Other" */
ngx_string("304 Not Modified"),
+ /* ngx_null_string, */ /* "305 Use Proxy" */
+ /* ngx_null_string, */ /* "306 unused" */
+ /* ngx_null_string, */ /* "307 Temporary Redirect" */
+
+#define NGX_HTTP_LEVEL_300 4
+
ngx_string("400 Bad Request"),
ngx_string("401 Unauthorized"),
- ngx_null_string, /* "402 Payment Required" */
+ ngx_string("402 Payment Required"),
ngx_string("403 Forbidden"),
ngx_string("404 Not Found"),
ngx_string("405 Not Allowed"),
- ngx_null_string, /* "406 Not Acceptable" */
+ ngx_string("406 Not Acceptable"),
ngx_null_string, /* "407 Proxy Authentication Required" */
ngx_string("408 Request Time-out"),
ngx_null_string, /* "409 Conflict" */
- ngx_null_string, /* "410 Gone" */
+ ngx_string("410 Gone"),
ngx_string("411 Length Required"),
ngx_null_string, /* "412 Precondition Failed" */
ngx_string("413 Request Entity Too Large"),
- ngx_null_string, /* "414 Request-URI Too Large" but we never send it
+ ngx_null_string, /* "414 Request-URI Too Large", but we never send it
* because we treat such requests as the HTTP/0.9
* requests and send only a body without a header
*/
ngx_null_string, /* "415 Unsupported Media Type" */
ngx_string("416 Requested Range Not Satisfiable"),
+ /* ngx_null_string, */ /* "417 Expectation Failed" */
+ /* ngx_null_string, */ /* "418 unused" */
+ /* ngx_null_string, */ /* "419 unused" */
+ /* ngx_null_string, */ /* "420 unused" */
+ /* ngx_null_string, */ /* "421 unused" */
+ /* ngx_null_string, */ /* "422 Unprocessable Entity" */
+ /* ngx_null_string, */ /* "423 Locked" */
+ /* ngx_null_string, */ /* "424 Failed Dependency" */
+
+#define NGX_HTTP_LEVEL_400 17
+
ngx_string("500 Internal Server Error"),
ngx_string("501 Method Not Implemented"),
ngx_string("502 Bad Gateway"),
ngx_string("503 Service Temporarily Unavailable"),
ngx_string("504 Gateway Time-out")
+
+ /* ngx_null_string, */ /* "505 HTTP Version Not Supported" */
+ /* ngx_null_string, */ /* "506 Variant Also Negotiates" */
+ /* ngx_null_string, */ /* "507 Insufficient Storage" */
+ /* ngx_null_string, */ /* "508 unused" */
+ /* ngx_null_string, */ /* "509 unused" */
+ /* ngx_null_string, */ /* "510 Not Extended" */
};
@@ -98,19 +119,19 @@
{ ngx_string("Server"), offsetof(ngx_http_headers_out_t, server) },
{ ngx_string("Date"), offsetof(ngx_http_headers_out_t, date) },
{ ngx_string("Content-Type"),
- offsetof(ngx_http_headers_out_t, content_type) },
+ offsetof(ngx_http_headers_out_t, content_type) },
{ ngx_string("Content-Length"),
- offsetof(ngx_http_headers_out_t, content_length) },
+ offsetof(ngx_http_headers_out_t, content_length) },
{ ngx_string("Content-Encoding"),
- offsetof(ngx_http_headers_out_t, content_encoding) },
+ offsetof(ngx_http_headers_out_t, content_encoding) },
{ ngx_string("Location"), offsetof(ngx_http_headers_out_t, location) },
{ ngx_string("Last-Modified"),
- offsetof(ngx_http_headers_out_t, last_modified) },
+ offsetof(ngx_http_headers_out_t, last_modified) },
{ ngx_string("Accept-Ranges"),
- offsetof(ngx_http_headers_out_t, accept_ranges) },
+ offsetof(ngx_http_headers_out_t, accept_ranges) },
{ ngx_string("Expires"), offsetof(ngx_http_headers_out_t, expires) },
{ ngx_string("Cache-Control"),
- offsetof(ngx_http_headers_out_t, cache_control) },
+ offsetof(ngx_http_headers_out_t, cache_control) },
{ ngx_string("ETag"), offsetof(ngx_http_headers_out_t, etag) },
{ ngx_null_string, 0 }
@@ -167,7 +188,8 @@
} else if (r->headers_out.status < NGX_HTTP_BAD_REQUEST) {
/* 3XX */
- status = r->headers_out.status - NGX_HTTP_MOVED_PERMANENTLY + 8;
+ status = r->headers_out.status - NGX_HTTP_MOVED_PERMANENTLY
+ + NGX_HTTP_LEVEL_200;
if (r->headers_out.status == NGX_HTTP_NOT_MODIFIED) {
r->header_only = 1;
@@ -175,12 +197,16 @@
} else if (r->headers_out.status < NGX_HTTP_INTERNAL_SERVER_ERROR) {
/* 4XX */
- status = r->headers_out.status - NGX_HTTP_BAD_REQUEST + 8 + 4;
+ status = r->headers_out.status - NGX_HTTP_BAD_REQUEST
+ + NGX_HTTP_LEVEL_200
+ + NGX_HTTP_LEVEL_300;
} else {
/* 5XX */
- status = r->headers_out.status
- - NGX_HTTP_INTERNAL_SERVER_ERROR + 8 + 4 + 17;
+ status = r->headers_out.status - NGX_HTTP_INTERNAL_SERVER_ERROR
+ + NGX_HTTP_LEVEL_200
+ + NGX_HTTP_LEVEL_300
+ + NGX_HTTP_LEVEL_400;
}
len += http_codes[status].len;
diff --git a/src/http/ngx_http_log_handler.c b/src/http/ngx_http_log_handler.c
index 5a3efe2..4cb4af7 100644
--- a/src/http/ngx_http_log_handler.c
+++ b/src/http/ngx_http_log_handler.c
@@ -119,7 +119,7 @@
ngx_http_log_commands, /* module directives */
NGX_HTTP_MODULE, /* module type */
NULL, /* init module */
- NULL /* init child */
+ NULL /* init process */
};
diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c
index dd104d4..d41cb8d 100644
--- a/src/http/ngx_http_request.c
+++ b/src/http/ngx_http_request.c
@@ -93,7 +93,6 @@
{ ngx_string("Accept"), offsetof(ngx_http_headers_in_t, accept) },
{ ngx_string("Accept-Language"),
offsetof(ngx_http_headers_in_t, accept_language) },
- { ngx_string("Via"), offsetof(ngx_http_headers_in_t, via) },
#endif
{ ngx_null_string, 0 }
@@ -394,7 +393,7 @@
return;
}
- if (ngx_array_init(&r->cleanup, r->pool, 5, sizeof(ngx_http_cleanup_t))
+ if (ngx_array_init(&r->cleanup, r->pool, 4, sizeof(ngx_http_cleanup_t))
== NGX_ERROR)
{
ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
@@ -642,7 +641,7 @@
}
- if (ngx_array_init(&r->headers_in.cookies, r->pool, 5,
+ if (ngx_array_init(&r->headers_in.cookies, r->pool, 2,
sizeof(ngx_table_elt_t *)) == NGX_ERROR)
{
ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
diff --git a/src/http/ngx_http_special_response.c b/src/http/ngx_http_special_response.c
index a269374..572ad0a 100644
--- a/src/http/ngx_http_special_response.c
+++ b/src/http/ngx_http_special_response.c
@@ -51,6 +51,22 @@
;
+static char error_401_page[] =
+"<html>" CRLF
+"<head><title>401 Unauthorized</title></head>" CRLF
+"<body bgcolor=\"white\">" CRLF
+"<center><h1>401 Unauthorized</h1></center>" CRLF
+;
+
+
+static char error_402_page[] =
+"<html>" CRLF
+"<head><title>402 Payment Required</title></head>" CRLF
+"<body bgcolor=\"white\">" CRLF
+"<center><h1>402 Payment Required</h1></center>" CRLF
+;
+
+
static char error_403_page[] =
"<html>" CRLF
"<head><title>403 Forbidden</title></head>" CRLF
@@ -75,6 +91,14 @@
;
+static char error_406_page[] =
+"<html>" CRLF
+"<head><title>406 Not Acceptable</title></head>" CRLF
+"<body bgcolor=\"white\">" CRLF
+"<center><h1>406 Not Acceptable</h1></center>" CRLF
+;
+
+
static char error_408_page[] =
"<html>" CRLF
"<head><title>408 Request Time-out</title></head>" CRLF
@@ -83,6 +107,14 @@
;
+static char error_410_page[] =
+"<html>" CRLF
+"<head><title>410 Gone</title></head>" CRLF
+"<body bgcolor=\"white\">" CRLF
+"<center><h1>410 Gone</h1></center>" CRLF
+;
+
+
static char error_413_page[] =
"<html>" CRLF
"<head><title>413 Request Entity Too Large</title></head>" CRLF
@@ -158,22 +190,25 @@
static ngx_str_t error_pages[] = {
- /* ngx_null_string, */ /* 300 */
+
+ /* ngx_null_string, */ /* 300 */
ngx_string(error_301_page),
ngx_string(error_302_page),
ngx_null_string, /* 303 */
+#define NGX_HTTP_LEVEL_300 3
+
ngx_string(error_400_page),
- ngx_null_string, /* 401 */
- ngx_null_string, /* 402 */
+ ngx_string(error_401_page),
+ ngx_string(error_402_page),
ngx_string(error_403_page),
ngx_string(error_404_page),
ngx_string(error_405_page),
- ngx_null_string, /* 406 */
+ ngx_string(error_406_page),
ngx_null_string, /* 407 */
ngx_string(error_408_page),
ngx_null_string, /* 409 */
- ngx_null_string, /* 410 */
+ ngx_string(error_410_page),
ngx_null_string, /* 411 */
ngx_null_string, /* 412 */
ngx_string(error_413_page),
@@ -181,9 +216,11 @@
ngx_null_string, /* 415 */
ngx_string(error_416_page),
+#define NGX_HTTP_LEVEL_400 17
+
ngx_string(error_497_page), /* 497, http to https */
ngx_string(error_404_page), /* 498, invalid host name */
- ngx_null_string, /* 499, client closed connection */
+ ngx_null_string, /* 499, client had closed connection */
ngx_string(error_500_page),
ngx_string(error_501_page),
@@ -259,12 +296,12 @@
} else if (error < NGX_HTTP_NGX_CODES) {
/* 4XX */
- err = error - NGX_HTTP_BAD_REQUEST + 3;
+ err = error - NGX_HTTP_BAD_REQUEST + NGX_HTTP_LEVEL_300;
} else {
/* 49X, 5XX */
- err = error - NGX_HTTP_NGX_CODES + 3 + 17;
-
+ err = error - NGX_HTTP_NGX_CODES + NGX_HTTP_LEVEL_300
+ + NGX_HTTP_LEVEL_400;
switch (error) {
case NGX_HTTP_TO_HTTPS:
r->headers_out.status = NGX_HTTP_BAD_REQUEST;
diff --git a/src/http/ngx_http_variables.c b/src/http/ngx_http_variables.c
new file mode 100644
index 0000000..e65f388
--- /dev/null
+++ b/src/http/ngx_http_variables.c
@@ -0,0 +1,338 @@
+
+/*
+ * Copyright (C) Igor Sysoev
+ */
+
+
+#include <ngx_config.h>
+#include <ngx_core.h>
+#include <ngx_event.h>
+#include <ngx_http.h>
+
+
+#define NGX_HTTP_VARS_HASH_PRIME 29
+
+#define ngx_http_vars_hash_key(key, vn) \
+ { \
+ ngx_uint_t n; \
+ for (key = 0, n = 0; n < (vn)->len; n++) { \
+ key += (vn)->data[n]; \
+ } \
+ key %= NGX_HTTP_VARS_HASH_PRIME; \
+ }
+
+
+static ngx_http_variable_value_t *
+ ngx_http_variable_header(ngx_http_request_t *r, uintptr_t data);
+static ngx_http_variable_value_t *
+ ngx_http_variable_unknown_header(ngx_http_request_t *r, ngx_str_t *var);
+static ngx_http_variable_value_t *
+ ngx_http_variable_remote_addr(ngx_http_request_t *r, uintptr_t data);
+static ngx_http_variable_value_t *
+ ngx_http_variable_uri(ngx_http_request_t *r, uintptr_t data);
+static ngx_http_variable_value_t *
+ ngx_http_variable_query_string(ngx_http_request_t *r, uintptr_t data);
+
+
+static ngx_array_t *ngx_http_core_variables_hash;
+
+
+static ngx_http_core_variable_t ngx_http_core_variables[] = {
+
+ { ngx_string("HTTP_HOST"), ngx_http_variable_header,
+ offsetof(ngx_http_headers_in_t, host) },
+
+ { ngx_string("HTTP_USER_AGENT"), ngx_http_variable_header,
+ offsetof(ngx_http_headers_in_t, user_agent) },
+
+ { ngx_string("HTTP_REFERER"), ngx_http_variable_header,
+ offsetof(ngx_http_headers_in_t, referer) },
+
+#if (NGX_HTTP_GZIP)
+ { ngx_string("HTTP_VIA"), ngx_http_variable_header,
+ offsetof(ngx_http_headers_in_t, via) },
+#endif
+
+#if (NGX_HTTP_PROXY)
+ { ngx_string("HTTP_X_FORWARDED_FOR"), ngx_http_variable_header,
+ offsetof(ngx_http_headers_in_t, x_forwarded_for) },
+#endif
+
+ { ngx_string("REMOTE_ADDR"), ngx_http_variable_remote_addr, 0 },
+
+ { ngx_string("DOCUMENT_URI"), ngx_http_variable_uri, 0 },
+
+ { ngx_string("QUERY_STRING"), ngx_http_variable_query_string, 0 },
+
+ { ngx_null_string, NULL, 0 }
+};
+
+
+ngx_http_variable_t *
+ngx_http_add_variable(ngx_conf_t *cf)
+{
+ ngx_http_variable_t *var;
+ ngx_http_core_main_conf_t *cmcf;
+
+ cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
+
+ if (cmcf->variables.elts == NULL) {
+ if (ngx_array_init(&cmcf->variables, cf->pool, 4,
+ sizeof(ngx_http_variable_t)) == NGX_ERROR)
+ {
+ return NULL;
+ }
+ }
+
+ if (!(var = ngx_array_push(&cmcf->variables))) {
+ return NULL;
+ }
+
+ var->index = cmcf->variables.nelts - 1;
+
+ return var;
+}
+
+
+ngx_http_variable_value_t *
+ngx_http_get_indexed_variable(ngx_http_request_t *r, ngx_uint_t index)
+{
+ ngx_http_variable_t *var;
+ ngx_http_core_main_conf_t *cmcf;
+
+ /* TODO: cached variables */
+
+ cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
+
+ if (cmcf->variables.elts == NULL || cmcf->variables.nelts <= index) {
+ ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
+ "unknown variable index: %d", index);
+ return NULL;
+ }
+
+ var = cmcf->variables.elts;
+
+ return var[index].handler(r, var[index].data);
+}
+
+
+ngx_int_t
+ngx_http_get_variable_index(ngx_http_core_main_conf_t *cmcf, ngx_str_t *name)
+{
+ ngx_uint_t i;
+ ngx_http_variable_t *var;
+
+ var = cmcf->variables.elts;
+ for (i = 0; i < cmcf->variables.nelts; i++) {
+ if (var[i].name.len != name->len) {
+ continue;
+ }
+
+ if (ngx_strncasecmp(var[i].name.data, name->data, name->len) == 0) {
+ return var[i].index;
+ }
+ }
+
+ return -1;
+}
+
+
+ngx_http_variable_value_t *
+ngx_http_get_variable(ngx_http_request_t *r, ngx_str_t *name)
+{
+ ngx_int_t index;
+ ngx_uint_t i, key;
+ ngx_http_core_variable_t *var;
+ ngx_http_core_main_conf_t *cmcf;
+
+ cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
+
+ index = ngx_http_get_variable_index(cmcf, name);
+
+ if (index != -1) {
+ return ngx_http_get_indexed_variable(r, index);
+ }
+
+ ngx_http_vars_hash_key(key, name);
+
+ var = ngx_http_core_variables_hash[key].elts;
+ for (i = 0; i < ngx_http_core_variables_hash[key].nelts; i++) {
+
+ if (var[i].name.len != name->len
+ || ngx_strncasecmp(var[i].name.data, name->data, name->len) != 0)
+ {
+ continue;
+ }
+
+ return var[i].handler(r, var[i].data);
+ }
+
+ if (ngx_strncasecmp(name->data, "HTTP_", 5) != 0) {
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
+ "unknown \"%V\" variable", name);
+ return NGX_HTTP_VARIABLE_NOT_FOUND;
+ }
+
+ return ngx_http_variable_unknown_header(r, name);
+}
+
+
+static ngx_http_variable_value_t *
+ngx_http_variable_header(ngx_http_request_t *r, uintptr_t data)
+{
+ ngx_table_elt_t *h;
+ ngx_http_variable_value_t *v;
+
+ h = *(ngx_table_elt_t **) ((char *) &r->headers_in + data);
+
+ if (h == NULL) {
+ return NGX_HTTP_VARIABLE_NOT_FOUND;
+ }
+
+ if (!(v = ngx_palloc(r->pool, sizeof(ngx_http_variable_value_t)))) {
+ return NULL;
+ }
+
+ v->value = 0;
+ v->text = h->value;
+
+ return v;
+}
+
+
+static ngx_http_variable_value_t *
+ngx_http_variable_unknown_header(ngx_http_request_t *r, ngx_str_t *var)
+{
+ u_char ch;
+ ngx_uint_t i, n;
+ ngx_list_part_t *part;
+ ngx_table_elt_t *header;
+ ngx_http_variable_value_t *v;
+
+ part = &r->headers_in.headers.part;
+ header = part->elts;
+
+ for (i = 0; /* void */ ; i++) {
+
+ if (i >= part->nelts) {
+ if (part->next == NULL) {
+ break;
+ }
+
+ part = part->next;
+ header = part->elts;
+ i = 0;
+ }
+
+ for (n = 0; n + 5 < var->len && n < header[i].key.len; n++)
+ {
+ ch = header[i].key.data[n];
+
+ if (ch >= 'a' && ch <= 'z') {
+ ch &= ~0x20;
+
+ } else if (ch == '-') {
+ ch = '_';
+ }
+
+ if (var->data[n + 5] != ch) {
+ break;
+ }
+ }
+
+ if (n + 5 == var->len) {
+ if (!(v = ngx_palloc(r->pool, sizeof(ngx_http_variable_value_t)))) {
+ return NULL;
+ }
+
+ v->value = 0;
+ v->text = header[i].value;
+ return v;
+ }
+ }
+
+ return NGX_HTTP_VARIABLE_NOT_FOUND;
+}
+
+
+static ngx_http_variable_value_t *
+ngx_http_variable_remote_addr(ngx_http_request_t *r, uintptr_t data)
+{
+ ngx_http_variable_value_t *v;
+
+ if (!(v = ngx_palloc(r->pool, sizeof(ngx_http_variable_value_t)))) {
+ return NULL;
+ }
+
+ v->value = 0;
+ v->text = r->connection->addr_text;
+
+ return v;
+}
+
+
+static ngx_http_variable_value_t *
+ngx_http_variable_uri(ngx_http_request_t *r, uintptr_t data)
+{
+ ngx_http_variable_value_t *v;
+
+ if (!(v = ngx_palloc(r->pool, sizeof(ngx_http_variable_value_t)))) {
+ return NULL;
+ }
+
+ v->value = 0;
+ v->text = r->uri;
+
+ return v;
+}
+
+
+static ngx_http_variable_value_t *
+ngx_http_variable_query_string(ngx_http_request_t *r, uintptr_t data)
+{
+ ngx_http_variable_value_t *v;
+
+ if (!(v = ngx_palloc(r->pool, sizeof(ngx_http_variable_value_t)))) {
+ return NULL;
+ }
+
+ v->value = 0;
+ v->text = r->args;
+
+ return v;
+}
+
+
+ngx_int_t
+ngx_http_core_variables_init(ngx_cycle_t *cycle)
+{
+ ngx_uint_t i, key;
+ ngx_http_core_variable_t *var, *v;
+
+ ngx_http_core_variables_hash = ngx_palloc(cycle->pool,
+ NGX_HTTP_VARS_HASH_PRIME
+ * sizeof(ngx_array_t));
+ if (ngx_http_core_variables_hash == NULL) {
+ return NGX_ERROR;
+ }
+
+ for (i = 0; i < NGX_HTTP_VARS_HASH_PRIME; i++) {
+ if (ngx_array_init(&ngx_http_core_variables_hash[i], cycle->pool, 4,
+ sizeof(ngx_http_core_variable_t)) == NGX_ERROR)
+ {
+ return NGX_ERROR;
+ }
+ }
+
+ for (var = ngx_http_core_variables; var->name.len; var++) {
+ ngx_http_vars_hash_key(key, &var->name);
+
+ if (!(v = ngx_array_push(&ngx_http_core_variables_hash[key]))) {
+ return NGX_ERROR;
+ }
+
+ *v = *var;
+ }
+
+ return NGX_OK;
+}
diff --git a/src/http/ngx_http_variables.h b/src/http/ngx_http_variables.h
new file mode 100644
index 0000000..c7ccdc1
--- /dev/null
+++ b/src/http/ngx_http_variables.h
@@ -0,0 +1,61 @@
+
+/*
+ * Copyright (C) Igor Sysoev
+ */
+
+
+#ifndef _NGX_HTTP_VARIABLES_H_INCLUDED_
+#define _NGX_HTTP_VARIABLES_H_INCLUDED_
+
+
+#include <ngx_config.h>
+#include <ngx_core.h>
+#include <ngx_event.h>
+#include <ngx_http.h>
+
+
+#define NGX_HTTP_VARIABLE_NOT_FOUND (ngx_http_variable_value_t *) -1
+
+
+typedef struct {
+ ngx_uint_t value;
+ ngx_str_t text;
+} ngx_http_variable_value_t;
+
+
+typedef struct ngx_http_variable_s ngx_http_variable_t;
+
+typedef ngx_http_variable_value_t *
+ (*ngx_http_get_variable_pt) (ngx_http_request_t *r, void *var);
+
+
+struct ngx_http_variable_s {
+ ngx_str_t name;
+ ngx_uint_t index;
+ ngx_http_get_variable_pt handler;
+ void *data;
+ ngx_uint_t uses;
+};
+
+
+typedef ngx_http_variable_value_t *
+ (*ngx_http_get_core_variable_pt) (ngx_http_request_t *r, uintptr_t data);
+
+typedef struct {
+ ngx_str_t name;
+ ngx_http_get_core_variable_pt handler;
+ uintptr_t data;
+} ngx_http_core_variable_t;
+
+
+ngx_http_variable_t *ngx_http_add_variable(ngx_conf_t *cf);
+ngx_int_t ngx_http_get_variable_index(ngx_http_core_main_conf_t *cmcf,
+ ngx_str_t *name);
+ngx_http_variable_value_t *ngx_http_get_indexed_variable(ngx_http_request_t *r,
+ ngx_uint_t index);
+ngx_http_variable_value_t *ngx_http_get_variable(ngx_http_request_t *r,
+ ngx_str_t *name);
+ngx_int_t ngx_http_core_variables_init(ngx_cycle_t *cycle);
+
+
+#endif /* _NGX_HTTP_VARIABLES_H_INCLUDED_ */
diff --git a/src/http/ngx_http_write_filter.c b/src/http/ngx_http_write_filter.c
index 759801f..1269909 100644
--- a/src/http/ngx_http_write_filter.c
+++ b/src/http/ngx_http_write_filter.c
@@ -44,8 +44,8 @@
ngx_int_t ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
{
- int last;
- off_t size, flush, sent;
+ off_t size, sent;
+ ngx_uint_t last, flush;
ngx_chain_t *cl, *ln, **ll, *chain;
ngx_connection_t *c;
ngx_http_core_loc_conf_t *clcf;
@@ -101,7 +101,7 @@
size += ngx_buf_size(cl->buf);
if (cl->buf->flush || cl->buf->recycled) {
- flush = size;
+ flush = 1;
}
if (cl->buf->last_buf) {
@@ -152,7 +152,7 @@
size += ngx_buf_size(cl->buf);
if (cl->buf->flush || cl->buf->recycled) {
- flush = size;
+ flush = 1;
}
if (cl->buf->last_buf) {
@@ -165,7 +165,7 @@
c = r->connection;
ngx_log_debug3(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http write filter: l:%d f:%O s:%O", last, flush, size);
+ "http write filter: l:%d f:%d s:%O", last, flush, size);
clcf = ngx_http_get_module_loc_conf(r->main ? r->main : r,
ngx_http_core_module);
@@ -176,7 +176,7 @@
* is smaller than "postpone_output" directive
*/
- if (!last && flush == 0 && in && size < (off_t) clcf->postpone_output) {
+ if (!last && !flush && in && size < (off_t) clcf->postpone_output) {
return NGX_OK;
}
@@ -189,6 +189,11 @@
return NGX_OK;
}
+ if (flush) {
+ while ((ctx->out = ctx->out->next)) { /* void */ }
+ return NGX_OK;
+ }
+
ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
"the http output chain is empty");