mirror of
https://github.com/nginx/nginx.git
synced 2026-08-28 12:45:21 +00:00
nginx-0.3.16-RELEASE import
*) Feature: the ngx_http_map_module.
*) Feature: the "types_hash_max_size" and "types_hash_bucket_size"
directives.
*) Feature: the "ssi_value_length" directive.
*) Feature: the "worker_rlimit_core" directive.
*) Workaround: the connection number in logs was always 1 if nginx was
built by the icc 8.1 or 9.0 compilers with optimization for
Pentium 4.
*) Bugfix: the "config timefmt" SSI command set incorrect time format.
*) Bugfix: nginx did not close connection to IMAP/POP3 backend for the
SSL connections; the bug had appeared in 0.3.13.
Thanks to Rob Mueller.
*) Bugfix: segmentation fault may occurred in at SSL shutdown; the bug
had appeared in 0.3.13.
This commit is contained in:
parent
74297c285e
commit
2402502c2f
41 changed files with 1630 additions and 208 deletions
|
|
@ -13,7 +13,7 @@ typedef struct {
|
|||
ngx_radix_tree_t *tree;
|
||||
ngx_pool_t *pool;
|
||||
ngx_array_t values;
|
||||
} ngx_http_geo_conf_t;
|
||||
} ngx_http_geo_conf_ctx_t;
|
||||
|
||||
|
||||
static char *ngx_http_geo_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
||||
|
|
@ -95,12 +95,12 @@ ngx_http_geo_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v,
|
|||
static char *
|
||||
ngx_http_geo_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
{
|
||||
char *rv;
|
||||
ngx_str_t *value, name;
|
||||
ngx_conf_t save;
|
||||
ngx_pool_t *pool;
|
||||
ngx_radix_tree_t *tree;
|
||||
ngx_http_geo_conf_t geo;
|
||||
char *rv;
|
||||
ngx_str_t *value, name;
|
||||
ngx_conf_t save;
|
||||
ngx_pool_t *pool;
|
||||
ngx_radix_tree_t *tree;
|
||||
ngx_http_geo_conf_ctx_t ctx;
|
||||
ngx_http_variable_t *var;
|
||||
|
||||
value = cf->args->elts;
|
||||
|
|
@ -135,20 +135,20 @@ ngx_http_geo_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
if (ngx_array_init(&geo.values, pool, 512,
|
||||
if (ngx_array_init(&ctx.values, pool, 512,
|
||||
sizeof(ngx_http_variable_value_t *))
|
||||
== NGX_ERROR)
|
||||
!= NGX_OK)
|
||||
{
|
||||
ngx_destroy_pool(pool);
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
geo.tree = tree;
|
||||
geo.pool = cf->pool;
|
||||
ctx.tree = tree;
|
||||
ctx.pool = cf->pool;
|
||||
|
||||
save = *cf;
|
||||
cf->pool = pool;
|
||||
cf->ctx = &geo;
|
||||
cf->ctx = &ctx;
|
||||
cf->handler = ngx_http_geo;
|
||||
cf->handler_conf = conf;
|
||||
|
||||
|
|
@ -182,10 +182,10 @@ ngx_http_geo(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
|
|||
ngx_str_t *value, file;
|
||||
ngx_uint_t i;
|
||||
ngx_inet_cidr_t cidrin;
|
||||
ngx_http_geo_conf_t *geo;
|
||||
ngx_http_geo_conf_ctx_t *ctx;
|
||||
ngx_http_variable_value_t *var, *old, **v;
|
||||
|
||||
geo = cf->ctx;
|
||||
ctx = cf->ctx;
|
||||
|
||||
if (cf->args->nelts != 2) {
|
||||
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
||||
|
|
@ -223,28 +223,27 @@ ngx_http_geo(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
|
|||
}
|
||||
|
||||
var = NULL;
|
||||
v = geo->values.elts;
|
||||
v = ctx->values.elts;
|
||||
|
||||
for (i = 0; i < geo->values.nelts; i++) {
|
||||
for (i = 0; i < ctx->values.nelts; i++) {
|
||||
if ((size_t) v[i]->len != value[1].len) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ngx_strncmp(value[1].data, v[i]->data, value[1].len) == 0)
|
||||
{
|
||||
if (ngx_strncmp(value[1].data, v[i]->data, value[1].len) == 0) {
|
||||
var = v[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (var == NULL) {
|
||||
var = ngx_palloc(geo->pool, sizeof(ngx_http_variable_value_t));
|
||||
var = ngx_palloc(ctx->pool, sizeof(ngx_http_variable_value_t));
|
||||
if (var == NULL) {
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
var->len = value[1].len;
|
||||
var->data = ngx_pstrdup(geo->pool, &value[1]);
|
||||
var->data = ngx_pstrdup(ctx->pool, &value[1]);
|
||||
if (var->data == NULL) {
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
|
@ -253,7 +252,7 @@ ngx_http_geo(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
|
|||
var->no_cachable = 0;
|
||||
var->not_found = 0;
|
||||
|
||||
v = ngx_array_push(&geo->values);
|
||||
v = ngx_array_push(&ctx->values);
|
||||
if (v == NULL) {
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
|
@ -262,7 +261,7 @@ ngx_http_geo(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
|
|||
}
|
||||
|
||||
for (i = 2; i; i--) {
|
||||
rc = ngx_radix32tree_insert(geo->tree, cidrin.addr, cidrin.mask,
|
||||
rc = ngx_radix32tree_insert(ctx->tree, cidrin.addr, cidrin.mask,
|
||||
(uintptr_t) var);
|
||||
if (rc == NGX_OK) {
|
||||
return NGX_CONF_OK;
|
||||
|
|
@ -275,14 +274,14 @@ ngx_http_geo(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
|
|||
/* rc == NGX_BUSY */
|
||||
|
||||
old = (ngx_http_variable_value_t *)
|
||||
ngx_radix32tree_find(geo->tree, cidrin.addr & cidrin.mask);
|
||||
ngx_radix32tree_find(ctx->tree, cidrin.addr & cidrin.mask);
|
||||
|
||||
ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
|
||||
"duplicate parameter \"%V\", value: \"%V\", "
|
||||
"old value: \"%V\"",
|
||||
&value[0], var, old);
|
||||
|
||||
rc = ngx_radix32tree_delete(geo->tree, cidrin.addr, cidrin.mask);
|
||||
rc = ngx_radix32tree_delete(ctx->tree, cidrin.addr, cidrin.mask);
|
||||
|
||||
if (rc == NGX_ERROR) {
|
||||
return NGX_CONF_ERROR;
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ typedef struct {
|
|||
ngx_uint_t http_version;
|
||||
ngx_uint_t proxied;
|
||||
|
||||
int level;
|
||||
ngx_int_t level;
|
||||
size_t wbits;
|
||||
size_t memlevel;
|
||||
ssize_t min_length;
|
||||
|
|
@ -509,7 +509,7 @@ ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
|
|||
ctx->zstream.zfree = ngx_http_gzip_filter_free;
|
||||
ctx->zstream.opaque = ctx;
|
||||
|
||||
rc = deflateInit2(&ctx->zstream, conf->level, Z_DEFLATED,
|
||||
rc = deflateInit2(&ctx->zstream, (int) conf->level, Z_DEFLATED,
|
||||
-wbits, memlevel, Z_DEFAULT_STRATEGY);
|
||||
|
||||
if (rc != Z_OK) {
|
||||
|
|
|
|||
637
src/http/modules/ngx_http_map_module.c
Normal file
637
src/http/modules/ngx_http_map_module.c
Normal file
|
|
@ -0,0 +1,637 @@
|
|||
|
||||
/*
|
||||
* Copyright (C) Igor Sysoev
|
||||
*/
|
||||
|
||||
|
||||
#include <ngx_config.h>
|
||||
#include <ngx_core.h>
|
||||
#include <ngx_http.h>
|
||||
|
||||
|
||||
#define NGX_HTTP_MAP_HASH 10007
|
||||
|
||||
typedef struct {
|
||||
ngx_uint_t hash_max_size;
|
||||
ngx_uint_t hash_bucket_size;
|
||||
} ngx_http_map_conf_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
ngx_pool_t *pool;
|
||||
|
||||
ngx_array_t keys;
|
||||
ngx_array_t *keys_hash;
|
||||
|
||||
ngx_array_t dns_wildcards;
|
||||
ngx_array_t *dns_hash;
|
||||
|
||||
ngx_array_t *values_hash;
|
||||
|
||||
ngx_http_variable_value_t *default_value;
|
||||
ngx_uint_t hostnames; /* unsigned hostnames:1 */
|
||||
} ngx_http_map_conf_ctx_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
ngx_hash_t hash;
|
||||
ngx_hash_wildcard_t *dns_wildcards;
|
||||
ngx_int_t index;
|
||||
ngx_http_variable_value_t *default_value;
|
||||
ngx_uint_t hostnames; /* unsigned hostnames:1 */
|
||||
} ngx_http_map_ctx_t;
|
||||
|
||||
|
||||
static int ngx_libc_cdecl ngx_http_map_cmp_dns_wildcards(const void *one,
|
||||
const void *two);
|
||||
static void *ngx_http_map_create_conf(ngx_conf_t *cf);
|
||||
static char *ngx_http_map_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
||||
static char *ngx_http_map(ngx_conf_t *cf, ngx_command_t *dummy, void *conf);
|
||||
|
||||
|
||||
static ngx_command_t ngx_http_map_commands[] = {
|
||||
|
||||
{ ngx_string("map"),
|
||||
NGX_HTTP_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_TAKE2,
|
||||
ngx_http_map_block,
|
||||
NGX_HTTP_MAIN_CONF_OFFSET,
|
||||
0,
|
||||
NULL },
|
||||
|
||||
{ ngx_string("map_hash_max_size"),
|
||||
NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
|
||||
ngx_conf_set_num_slot,
|
||||
NGX_HTTP_MAIN_CONF_OFFSET,
|
||||
offsetof(ngx_http_map_conf_t, hash_max_size),
|
||||
NULL },
|
||||
|
||||
{ ngx_string("map_hash_bucket_size"),
|
||||
NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
|
||||
ngx_conf_set_num_slot,
|
||||
NGX_HTTP_MAIN_CONF_OFFSET,
|
||||
offsetof(ngx_http_map_conf_t, hash_bucket_size),
|
||||
NULL },
|
||||
|
||||
ngx_null_command
|
||||
};
|
||||
|
||||
|
||||
static ngx_http_module_t ngx_http_map_module_ctx = {
|
||||
NULL, /* preconfiguration */
|
||||
NULL, /* postconfiguration */
|
||||
|
||||
ngx_http_map_create_conf, /* 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_map_module = {
|
||||
NGX_MODULE_V1,
|
||||
&ngx_http_map_module_ctx, /* module context */
|
||||
ngx_http_map_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_map_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v,
|
||||
uintptr_t data)
|
||||
{
|
||||
ngx_http_map_ctx_t *map = (ngx_http_map_ctx_t *) data;
|
||||
|
||||
size_t len;
|
||||
u_char *name;
|
||||
ngx_uint_t key, i;
|
||||
ngx_http_variable_value_t *vv, *value;
|
||||
|
||||
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
||||
"http map started");
|
||||
|
||||
vv = ngx_http_get_flushed_variable(r, map->index);
|
||||
|
||||
len = vv->len;
|
||||
|
||||
if (len && map->hostnames && vv->data[len - 1] == '.') {
|
||||
len--;
|
||||
}
|
||||
|
||||
if (len == 0) {
|
||||
*v = *map->default_value;
|
||||
return NGX_OK;
|
||||
}
|
||||
|
||||
name = ngx_palloc(r->pool, len);
|
||||
if (name == NULL) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
key = 0;
|
||||
for (i = 0; i < len; i++) {
|
||||
name[i] = ngx_tolower(vv->data[i]);
|
||||
key = ngx_hash(key, name[i]);
|
||||
}
|
||||
|
||||
value = NULL;
|
||||
|
||||
if (map->hash.buckets) {
|
||||
value = ngx_hash_find(&map->hash, key, name, len);
|
||||
}
|
||||
|
||||
if (value) {
|
||||
*v = *value;
|
||||
|
||||
} else {
|
||||
if (map->dns_wildcards && map->dns_wildcards->hash.buckets) {
|
||||
value = ngx_hash_find_wildcard(map->dns_wildcards, name, len);
|
||||
if (value) {
|
||||
*v = *value;
|
||||
|
||||
} else {
|
||||
*v = *map->default_value;
|
||||
}
|
||||
|
||||
} else {
|
||||
*v = *map->default_value;
|
||||
}
|
||||
}
|
||||
|
||||
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
||||
"http map: \"%V\" \"%V\"", vv, v);
|
||||
|
||||
return NGX_OK;
|
||||
}
|
||||
|
||||
|
||||
static void *
|
||||
ngx_http_map_create_conf(ngx_conf_t *cf)
|
||||
{
|
||||
ngx_http_map_conf_t *mcf;
|
||||
|
||||
mcf = ngx_palloc(cf->pool, sizeof(ngx_http_map_conf_t));
|
||||
if (mcf == NULL) {
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
mcf->hash_max_size = NGX_CONF_UNSET_UINT;
|
||||
mcf->hash_bucket_size = NGX_CONF_UNSET_UINT;
|
||||
|
||||
return mcf;
|
||||
}
|
||||
|
||||
|
||||
static char *
|
||||
ngx_http_map_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
{
|
||||
ngx_http_map_conf_t *mcf = conf;
|
||||
|
||||
char *rv;
|
||||
ngx_str_t *value, name;
|
||||
ngx_conf_t save;
|
||||
ngx_pool_t *pool;
|
||||
ngx_hash_init_t hash;
|
||||
ngx_http_map_ctx_t *map;
|
||||
ngx_http_variable_t *var;
|
||||
ngx_http_map_conf_ctx_t ctx;
|
||||
|
||||
if (mcf->hash_max_size == NGX_CONF_UNSET_UINT) {
|
||||
mcf->hash_max_size = 2048;
|
||||
}
|
||||
|
||||
if (mcf->hash_bucket_size == NGX_CONF_UNSET_UINT) {
|
||||
mcf->hash_bucket_size = ngx_cacheline_size;
|
||||
|
||||
} else {
|
||||
mcf->hash_bucket_size = ngx_align(mcf->hash_bucket_size,
|
||||
ngx_cacheline_size);
|
||||
}
|
||||
|
||||
map = ngx_pcalloc(cf->pool, sizeof(ngx_http_map_ctx_t));
|
||||
if (map == NULL) {
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
value = cf->args->elts;
|
||||
|
||||
name = value[1];
|
||||
name.len--;
|
||||
name.data++;
|
||||
|
||||
map->index = ngx_http_get_variable_index(cf, &name);
|
||||
|
||||
if (map->index == NGX_ERROR) {
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
name = value[2];
|
||||
name.len--;
|
||||
name.data++;
|
||||
|
||||
var = ngx_http_add_variable(cf, &name, NGX_HTTP_VAR_CHANGABLE);
|
||||
if (var == NULL) {
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
var->handler = ngx_http_map_variable;
|
||||
var->data = (uintptr_t) map;
|
||||
|
||||
pool = ngx_create_pool(16384, cf->log);
|
||||
if (pool == NULL) {
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
if (ngx_array_init(&ctx.keys, pool, 16384, sizeof(ngx_hash_key_t))
|
||||
!= NGX_OK)
|
||||
{
|
||||
ngx_destroy_pool(pool);
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
if (ngx_array_init(&ctx.dns_wildcards, pool, 16384, sizeof(ngx_hash_key_t))
|
||||
!= NGX_OK)
|
||||
{
|
||||
ngx_destroy_pool(pool);
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
ctx.keys_hash = ngx_pcalloc(pool, sizeof(ngx_array_t) * NGX_HTTP_MAP_HASH);
|
||||
if (ctx.keys_hash == NULL) {
|
||||
ngx_destroy_pool(pool);
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
ctx.dns_hash = ngx_pcalloc(pool, sizeof(ngx_array_t) * NGX_HTTP_MAP_HASH);
|
||||
if (ctx.dns_hash == NULL) {
|
||||
ngx_destroy_pool(pool);
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
ctx.values_hash = ngx_pcalloc(pool,
|
||||
sizeof(ngx_array_t) * NGX_HTTP_MAP_HASH);
|
||||
if (ctx.values_hash == NULL) {
|
||||
ngx_destroy_pool(pool);
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
ctx.pool = cf->pool;
|
||||
ctx.default_value = NULL;
|
||||
ctx.hostnames = 0;
|
||||
|
||||
save = *cf;
|
||||
cf->pool = pool;
|
||||
cf->ctx = &ctx;
|
||||
cf->handler = ngx_http_map;
|
||||
cf->handler_conf = conf;
|
||||
|
||||
rv = ngx_conf_parse(cf, NULL);
|
||||
|
||||
*cf = save;
|
||||
|
||||
if (rv != NGX_CONF_OK) {
|
||||
ngx_destroy_pool(pool);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
hash.key = ngx_hash_key_lc;
|
||||
hash.max_size = mcf->hash_max_size;
|
||||
hash.bucket_size = mcf->hash_bucket_size;
|
||||
hash.name = "map_hash";
|
||||
hash.pool = cf->pool;
|
||||
|
||||
if (ctx.keys.nelts) {
|
||||
hash.hash = &map->hash;
|
||||
hash.temp_pool = NULL;
|
||||
|
||||
if (ngx_hash_init(&hash, ctx.keys.elts, ctx.keys.nelts) != NGX_OK) {
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
map->default_value = ctx.default_value ? ctx.default_value:
|
||||
&ngx_http_variable_null_value;
|
||||
|
||||
if (ctx.dns_wildcards.nelts) {
|
||||
|
||||
ngx_qsort(ctx.dns_wildcards.elts, (size_t) ctx.dns_wildcards.nelts,
|
||||
sizeof(ngx_hash_key_t), ngx_http_map_cmp_dns_wildcards);
|
||||
|
||||
hash.hash = NULL;
|
||||
hash.temp_pool = pool;
|
||||
|
||||
if (ngx_hash_wildcard_init(&hash, ctx.dns_wildcards.elts,
|
||||
ctx.dns_wildcards.nelts)
|
||||
!= NGX_OK)
|
||||
{
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
map->dns_wildcards = (ngx_hash_wildcard_t *) hash.hash;
|
||||
}
|
||||
|
||||
ngx_destroy_pool(pool);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
static int ngx_libc_cdecl
|
||||
ngx_http_map_cmp_dns_wildcards(const void *one, const void *two)
|
||||
{
|
||||
ngx_hash_key_t *first, *second;
|
||||
|
||||
first = (ngx_hash_key_t *) one;
|
||||
second = (ngx_hash_key_t *) two;
|
||||
|
||||
return ngx_strcmp(first->key.data, second->key.data);
|
||||
}
|
||||
|
||||
|
||||
static char *
|
||||
ngx_http_map(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
|
||||
{
|
||||
size_t len;
|
||||
ngx_str_t *value, file, *name;
|
||||
ngx_uint_t i, n, key;
|
||||
ngx_hash_key_t *m;
|
||||
ngx_http_map_conf_ctx_t *ctx;
|
||||
ngx_http_variable_value_t *var, *old, **vp;
|
||||
u_char buf[2048];
|
||||
|
||||
ctx = cf->ctx;
|
||||
|
||||
value = cf->args->elts;
|
||||
|
||||
if (cf->args->nelts == 1
|
||||
&& ngx_strcmp(value[0].data, "hostnames") == 0)
|
||||
{
|
||||
ctx->hostnames = 1;
|
||||
return NGX_CONF_OK;
|
||||
|
||||
} else if (cf->args->nelts != 2) {
|
||||
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
||||
"invalid number of the map parameters");
|
||||
return NGX_CONF_ERROR;
|
||||
|
||||
} else if (value[0].len == 0) {
|
||||
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
||||
"invalid first parameter");
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
if (ngx_strcmp(value[0].data, "include") == 0) {
|
||||
file = value[1];
|
||||
|
||||
if (ngx_conf_full_name(cf->cycle, &file) == NGX_ERROR){
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
ngx_log_debug1(NGX_LOG_DEBUG_CORE, cf->log, 0, "include %s", file.data);
|
||||
|
||||
return ngx_conf_parse(cf, &file);
|
||||
}
|
||||
|
||||
key = 0;
|
||||
|
||||
for (i = 0; i < value[1].len; i++) {
|
||||
key = ngx_hash(key, value[1].data[i]);
|
||||
}
|
||||
|
||||
key %= NGX_HTTP_MAP_HASH;
|
||||
|
||||
vp = ctx->values_hash[key].elts;
|
||||
|
||||
if (vp) {
|
||||
for (i = 0; i < ctx->values_hash[key].nelts; i++) {
|
||||
if (value[1].len != (size_t) vp[i]->len) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ngx_strncmp(value[1].data, vp[i]->data, value[1].len) == 0) {
|
||||
var = vp[i];
|
||||
goto found;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
if (ngx_array_init(&ctx->values_hash[key], cf->pool, 4,
|
||||
sizeof(ngx_http_variable_value_t *))
|
||||
!= NGX_OK)
|
||||
{
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
var = ngx_palloc(ctx->pool, sizeof(ngx_http_variable_value_t));
|
||||
if (var == NULL) {
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
var->len = value[1].len;
|
||||
var->data = ngx_pstrdup(ctx->pool, &value[1]);
|
||||
if (var->data == NULL) {
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
var->valid = 1;
|
||||
var->no_cachable = 0;
|
||||
var->not_found = 0;
|
||||
|
||||
vp = ngx_array_push(&ctx->values_hash[key]);
|
||||
if (vp == NULL) {
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
*vp = var;
|
||||
|
||||
found:
|
||||
|
||||
if (value[0].data[0] != '*' || ctx->hostnames == 0) {
|
||||
|
||||
if (ngx_strcmp(value[0].data, "default") != 0) {
|
||||
|
||||
if (value[0].len && value[0].data[0] == '!') {
|
||||
value[0].len--;
|
||||
value[0].data++;
|
||||
}
|
||||
|
||||
key = 0;
|
||||
|
||||
for (i = 0; i < value[0].len; i++) {
|
||||
value[0].data[i] = ngx_tolower(value[0].data[i]);
|
||||
key = ngx_hash(key, value[0].data[i]);
|
||||
}
|
||||
|
||||
key %= NGX_HTTP_MAP_HASH;
|
||||
|
||||
name = ctx->keys_hash[key].elts;
|
||||
|
||||
if (name) {
|
||||
for (i = 0; i < ctx->keys_hash[key].nelts; i++) {
|
||||
if (value[0].len != name[i].len) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ngx_strncmp(value[0].data, name[i].data, value[0].len)
|
||||
== 0)
|
||||
{
|
||||
m = ctx->keys.elts;
|
||||
for (i = 0; i < ctx->keys.nelts; i++) {
|
||||
if (ngx_strcmp(value[0].data, m[i].key.data) == 0) {
|
||||
old = m[i].value;
|
||||
m[i].value = var;
|
||||
|
||||
goto duplicate;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
if (ngx_array_init(&ctx->keys_hash[key], cf->pool, 4,
|
||||
sizeof(ngx_str_t))
|
||||
!= NGX_OK)
|
||||
{
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
name = ngx_array_push(&ctx->keys_hash[key]);
|
||||
if (name == NULL) {
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
*name = value[0];
|
||||
|
||||
m = ngx_array_push(&ctx->keys);
|
||||
if (m == NULL) {
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
m->key = value[0];
|
||||
m->key_hash = ngx_hash_key(value[0].data, value[0].len);
|
||||
m->value = var;
|
||||
|
||||
} else {
|
||||
if (ctx->default_value) {
|
||||
old = ctx->default_value;
|
||||
ctx->default_value = var;
|
||||
|
||||
goto duplicate;
|
||||
}
|
||||
|
||||
ctx->default_value = var;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if (value[0].len < 3 || value[0].data[1] != '.') {
|
||||
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
||||
"invalid DNS wildcard \"%V\"", &value[0]);
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
key = 0;
|
||||
|
||||
for (i = 2; i < value[0].len; i++) {
|
||||
value[0].data[i] = ngx_tolower(value[0].data[i]);
|
||||
key = ngx_hash(key, value[0].data[i]);
|
||||
}
|
||||
|
||||
key %= NGX_HTTP_MAP_HASH;
|
||||
|
||||
/* convert "*.example.com" into "com.example.\0" */
|
||||
|
||||
len = 0;
|
||||
n = 0;
|
||||
|
||||
for (i = value[0].len - 1; i; i--) {
|
||||
if (value[0].data[i] == '.') {
|
||||
ngx_memcpy(&buf[n], &value[0].data[i + 1], len);
|
||||
n += len;
|
||||
buf[n++] = '.';
|
||||
len = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
len++;
|
||||
}
|
||||
|
||||
buf[n] = '\0';
|
||||
|
||||
name = ctx->dns_hash[key].elts;
|
||||
|
||||
if (name) {
|
||||
for (i = 0; i < ctx->dns_hash[key].nelts; i++) {
|
||||
if (value[0].len != name[i].len) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ngx_strncmp(value[0].data, name[i].data, value[0].len)
|
||||
== 0)
|
||||
{
|
||||
m = ctx->dns_wildcards.elts;
|
||||
for (i = 0; i < ctx->dns_wildcards.nelts; i++) {
|
||||
if (ngx_strcmp(buf, m[i].key.data) == 0) {
|
||||
old = m[i].value;
|
||||
m[i].value = var;
|
||||
|
||||
goto duplicate;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
if (ngx_array_init(&ctx->dns_hash[key], cf->pool, 4,
|
||||
sizeof(ngx_str_t))
|
||||
!= NGX_OK)
|
||||
{
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
name = ngx_array_push(&ctx->dns_hash[key]);
|
||||
if (name == NULL) {
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
*name = value[0];
|
||||
|
||||
ngx_memcpy(value[0].data, buf, value[0].len);
|
||||
value[0].len--;
|
||||
|
||||
m = ngx_array_push(&ctx->dns_wildcards);
|
||||
if (m == NULL) {
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
m->key = value[0];
|
||||
m->key_hash = 0;
|
||||
m->value = var;
|
||||
}
|
||||
|
||||
return NGX_CONF_OK;
|
||||
|
||||
duplicate:
|
||||
|
||||
ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
|
||||
"duplicate parameter \"%V\", value: \"%V\", "
|
||||
"old value: \"%V\"",
|
||||
&value[0], var, old);
|
||||
|
||||
return NGX_CONF_OK;
|
||||
}
|
||||
|
|
@ -42,7 +42,7 @@ typedef struct {
|
|||
ngx_array_t *body_set;
|
||||
ngx_array_t *headers_set_len;
|
||||
ngx_array_t *headers_set;
|
||||
ngx_hash_t *headers_set_hash;
|
||||
ngx_hash0_t *headers_set_hash;
|
||||
|
||||
ngx_array_t *headers_source;
|
||||
ngx_array_t *headers_names;
|
||||
|
|
@ -1892,7 +1892,7 @@ ngx_http_proxy_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
|
|||
*code = (uintptr_t) NULL;
|
||||
|
||||
|
||||
conf->headers_set_hash = ngx_pcalloc(cf->pool, sizeof(ngx_hash_t));
|
||||
conf->headers_set_hash = ngx_pcalloc(cf->pool, sizeof(ngx_hash0_t));
|
||||
if (conf->headers_set_hash == NULL) {
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
|
@ -1902,8 +1902,9 @@ ngx_http_proxy_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
|
|||
conf->headers_set_hash->bucket_size = sizeof(ngx_str_t);
|
||||
conf->headers_set_hash->name = "proxy_headers";
|
||||
|
||||
if (ngx_hash_init(conf->headers_set_hash, cf->pool,
|
||||
conf->headers_names->elts, conf->headers_names->nelts) != NGX_OK)
|
||||
if (ngx_hash0_init(conf->headers_set_hash, cf->pool,
|
||||
conf->headers_names->elts, conf->headers_names->nelts)
|
||||
!= NGX_OK)
|
||||
{
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -186,6 +186,13 @@ static ngx_command_t ngx_http_ssi_filter_commands[] = {
|
|||
offsetof(ngx_http_ssi_conf_t, min_file_chunk),
|
||||
NULL },
|
||||
|
||||
{ ngx_string("ssi_value_length"),
|
||||
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
||||
ngx_conf_set_size_slot,
|
||||
NGX_HTTP_LOC_CONF_OFFSET,
|
||||
offsetof(ngx_http_ssi_conf_t, value_len),
|
||||
NULL },
|
||||
|
||||
{ ngx_string("ssi_types"),
|
||||
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
|
||||
ngx_http_ssi_types,
|
||||
|
|
@ -1728,7 +1735,13 @@ ngx_http_ssi_config(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx,
|
|||
value = params[NGX_HTTP_SSI_CONFIG_TIMEFMT];
|
||||
|
||||
if (value) {
|
||||
ctx->timefmt = *value;
|
||||
ctx->timefmt.len = value->len;
|
||||
ctx->timefmt.data = ngx_palloc(r->pool, value->len + 1);
|
||||
if (ctx->timefmt.data == NULL) {
|
||||
return NGX_HTTP_SSI_ERROR;
|
||||
}
|
||||
|
||||
ngx_cpystrn(ctx->timefmt.data, value->data, value->len + 1);
|
||||
}
|
||||
|
||||
value = params[NGX_HTTP_SSI_CONFIG_ERRMSG];
|
||||
|
|
|
|||
|
|
@ -371,7 +371,7 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|||
cmcf->headers_in_hash.bucket_size = sizeof(ngx_http_header_t);
|
||||
cmcf->headers_in_hash.name = "http headers_in";
|
||||
|
||||
if (ngx_hash_init(&cmcf->headers_in_hash, cf->pool, ngx_http_headers_in, 0)
|
||||
if (ngx_hash0_init(&cmcf->headers_in_hash, cf->pool, ngx_http_headers_in, 0)
|
||||
!= NGX_OK)
|
||||
{
|
||||
return NGX_CONF_ERROR;
|
||||
|
|
@ -770,10 +770,10 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|||
}
|
||||
}
|
||||
|
||||
#if (NGX_DEBUG0)
|
||||
#if 0
|
||||
{
|
||||
u_char address[20];
|
||||
ngx_uint_t p, a, nn;
|
||||
ngx_uint_t p, a;
|
||||
|
||||
in_port = in_ports.elts;
|
||||
for (p = 0; p < in_ports.nelts; p++) {
|
||||
|
|
|
|||
|
|
@ -164,6 +164,20 @@ static ngx_command_t ngx_http_core_commands[] = {
|
|||
0,
|
||||
NULL },
|
||||
|
||||
{ ngx_string("types_hash_max_size"),
|
||||
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
||||
ngx_conf_set_num_slot,
|
||||
NGX_HTTP_LOC_CONF_OFFSET,
|
||||
offsetof(ngx_http_core_loc_conf_t, types_hash_max_size),
|
||||
NULL },
|
||||
|
||||
{ ngx_string("types_hash_bucket_size"),
|
||||
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
||||
ngx_conf_set_num_slot,
|
||||
NGX_HTTP_LOC_CONF_OFFSET,
|
||||
offsetof(ngx_http_core_loc_conf_t, types_hash_bucket_size),
|
||||
NULL },
|
||||
|
||||
{ ngx_string("types"),
|
||||
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF
|
||||
|NGX_CONF_BLOCK|NGX_CONF_NOARGS,
|
||||
|
|
@ -849,9 +863,8 @@ ngx_int_t
|
|||
ngx_http_set_content_type(ngx_http_request_t *r)
|
||||
{
|
||||
u_char c, *p, *exten;
|
||||
uint32_t key;
|
||||
ngx_str_t *type;
|
||||
ngx_uint_t i;
|
||||
ngx_http_type_t *type;
|
||||
ngx_http_core_loc_conf_t *clcf;
|
||||
|
||||
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
||||
|
|
@ -876,11 +889,7 @@ ngx_http_set_content_type(ngx_http_request_t *r)
|
|||
|
||||
for (i = 0; i < r->exten.len; i++) {
|
||||
c = r->exten.data[i];
|
||||
if (c >= 'A' && c <= 'Z') {
|
||||
*p++ = (u_char) (c | 0x20);
|
||||
} else {
|
||||
*p++ = c;
|
||||
}
|
||||
*p++ = ngx_tolower(c);
|
||||
}
|
||||
|
||||
r->exten.data = exten;
|
||||
|
|
@ -889,26 +898,17 @@ ngx_http_set_content_type(ngx_http_request_t *r)
|
|||
r->low_case_exten = 1;
|
||||
}
|
||||
|
||||
ngx_http_types_hash_key(key, r->exten);
|
||||
type = ngx_hash_find(&clcf->types_hash,
|
||||
ngx_hash_key(r->exten.data, r->exten.len),
|
||||
r->exten.data, r->exten.len);
|
||||
|
||||
type = clcf->types[key].elts;
|
||||
for (i = 0; i < clcf->types[key].nelts; i++) {
|
||||
if (r->exten.len != type[i].exten.len) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ngx_memcmp(r->exten.data, type[i].exten.data, r->exten.len)
|
||||
== 0)
|
||||
{
|
||||
r->headers_out.content_type = type[i].type;
|
||||
break;
|
||||
}
|
||||
if (type) {
|
||||
r->headers_out.content_type = *type;
|
||||
return NGX_OK;
|
||||
}
|
||||
}
|
||||
|
||||
if (r->headers_out.content_type.len == 0) {
|
||||
r->headers_out.content_type= clcf->default_type;
|
||||
}
|
||||
r->headers_out.content_type = clcf->default_type;
|
||||
|
||||
return NGX_OK;
|
||||
}
|
||||
|
|
@ -1636,39 +1636,55 @@ ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
|
|||
{
|
||||
ngx_http_core_loc_conf_t *lcf = conf;
|
||||
|
||||
uint32_t key;
|
||||
ngx_uint_t i;
|
||||
ngx_str_t *value;
|
||||
ngx_http_type_t *type;
|
||||
ngx_str_t *value, *content_type, *old;
|
||||
ngx_uint_t i, n;
|
||||
ngx_hash_key_t *type;
|
||||
|
||||
if (lcf->types == NULL) {
|
||||
lcf->types = ngx_palloc(cf->pool, NGX_HTTP_TYPES_HASH_PRIME
|
||||
* sizeof(ngx_array_t));
|
||||
lcf->types = ngx_array_create(cf->pool, 64, sizeof(ngx_hash_key_t));
|
||||
if (lcf->types == NULL) {
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < NGX_HTTP_TYPES_HASH_PRIME; i++) {
|
||||
if (ngx_array_init(&lcf->types[i], cf->pool, 4,
|
||||
sizeof(ngx_http_type_t)) == NGX_ERROR)
|
||||
{
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
}
|
||||
content_type = ngx_palloc(cf->pool, sizeof(ngx_str_t));
|
||||
if (content_type == NULL) {
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
value = cf->args->elts;
|
||||
*content_type = value[0];
|
||||
|
||||
for (i = 1; i < cf->args->nelts; i++) {
|
||||
ngx_http_types_hash_key(key, value[i]);
|
||||
|
||||
type = ngx_array_push(&lcf->types[key]);
|
||||
for (n = 0; n < value[i].len; n++) {
|
||||
value[i].data[n] = ngx_tolower(value[i].data[n]);
|
||||
}
|
||||
|
||||
type = lcf->types->elts;
|
||||
for (n = 0; n < lcf->types->nelts; n++) {
|
||||
if (ngx_strcmp(value[i].data, type[n].key.data) == 0) {
|
||||
old = type[n].value;
|
||||
type[n].value = content_type;
|
||||
|
||||
ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
|
||||
"duplicate extention \"%V\", "
|
||||
"content type: \"%V\", "
|
||||
"old content type: \"%V\"",
|
||||
&value[i], content_type, old);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
type = ngx_array_push(lcf->types);
|
||||
if (type == NULL) {
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
type->exten = value[i];
|
||||
type->type = value[0];
|
||||
type->key = value[i];
|
||||
type->key_hash = ngx_hash_key(value[i].data, value[i].len);
|
||||
type->value = content_type;
|
||||
}
|
||||
|
||||
return NGX_CONF_OK;
|
||||
|
|
@ -1905,29 +1921,34 @@ ngx_http_core_create_loc_conf(ngx_conf_t *cf)
|
|||
lcf->port_in_redirect = NGX_CONF_UNSET;
|
||||
lcf->msie_padding = NGX_CONF_UNSET;
|
||||
lcf->log_not_found = NGX_CONF_UNSET;
|
||||
lcf->types_hash_max_size = NGX_CONF_UNSET_UINT;
|
||||
lcf->types_hash_bucket_size = NGX_CONF_UNSET_UINT;
|
||||
|
||||
return lcf;
|
||||
}
|
||||
|
||||
|
||||
static ngx_http_type_t ngx_http_core_default_types[] = {
|
||||
{ ngx_string("html"), ngx_string("text/html") },
|
||||
{ ngx_string("gif"), ngx_string("image/gif") },
|
||||
{ ngx_string("jpg"), ngx_string("image/jpeg") },
|
||||
{ ngx_null_string, ngx_null_string }
|
||||
static ngx_str_t ngx_http_core_text_html_type = ngx_string("text/html");
|
||||
static ngx_str_t ngx_http_core_image_gif_type = ngx_string("image/gif");
|
||||
static ngx_str_t ngx_http_core_image_jpeg_type = ngx_string("image/jpeg");
|
||||
|
||||
static ngx_hash_key_t ngx_http_core_default_types[] = {
|
||||
{ ngx_string("html"), 0, &ngx_http_core_text_html_type },
|
||||
{ ngx_string("gif"), 0, &ngx_http_core_image_gif_type },
|
||||
{ ngx_string("jpg"), 0, &ngx_http_core_image_jpeg_type },
|
||||
{ ngx_null_string, 0, NULL }
|
||||
};
|
||||
|
||||
|
||||
static char *
|
||||
ngx_http_core_merge_loc_conf(ngx_conf_t *cf,
|
||||
void *parent, void *child)
|
||||
ngx_http_core_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
|
||||
{
|
||||
ngx_http_core_loc_conf_t *prev = parent;
|
||||
ngx_http_core_loc_conf_t *conf = child;
|
||||
|
||||
uint32_t key;
|
||||
ngx_uint_t i;
|
||||
ngx_http_type_t *type;
|
||||
ngx_hash_key_t *type;
|
||||
ngx_hash_init_t types_hash;
|
||||
|
||||
ngx_conf_merge_str_value(conf->root, prev->root, "html");
|
||||
|
||||
|
|
@ -1939,36 +1960,77 @@ ngx_http_core_merge_loc_conf(ngx_conf_t *cf,
|
|||
conf->post_action = prev->post_action;
|
||||
}
|
||||
|
||||
if (conf->types == NULL) {
|
||||
if (prev->types) {
|
||||
conf->types = prev->types;
|
||||
ngx_conf_merge_unsigned_value(conf->types_hash_max_size,
|
||||
prev->types_hash_max_size, 512);
|
||||
|
||||
} else {
|
||||
conf->types = ngx_palloc(cf->pool, NGX_HTTP_TYPES_HASH_PRIME
|
||||
* sizeof(ngx_array_t));
|
||||
if (conf->types == NULL) {
|
||||
ngx_conf_merge_unsigned_value(conf->types_hash_bucket_size,
|
||||
prev->types_hash_bucket_size,
|
||||
ngx_cacheline_size);
|
||||
|
||||
conf->types_hash_bucket_size = ngx_align(conf->types_hash_bucket_size,
|
||||
ngx_cacheline_size);
|
||||
|
||||
/*
|
||||
* the special handling the "types" directive in the "http" section
|
||||
* to inherit the http's conf->types_hash to all servers
|
||||
*/
|
||||
|
||||
if (prev->types && prev->types_hash.buckets == NULL) {
|
||||
|
||||
types_hash.hash = &prev->types_hash;
|
||||
types_hash.key = ngx_hash_key_lc;
|
||||
types_hash.max_size = conf->types_hash_max_size;
|
||||
types_hash.bucket_size = conf->types_hash_bucket_size;
|
||||
types_hash.name = "mime_types";
|
||||
types_hash.pool = cf->pool;
|
||||
types_hash.temp_pool = NULL;
|
||||
|
||||
if (ngx_hash_init(&types_hash, prev->types->elts, prev->types->nelts)
|
||||
!= NGX_OK)
|
||||
{
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
if (conf->types == NULL) {
|
||||
conf->types = prev->types;
|
||||
conf->types_hash = prev->types_hash;
|
||||
}
|
||||
|
||||
if (conf->types == NULL) {
|
||||
conf->types = ngx_array_create(cf->pool, 4, sizeof(ngx_hash_key_t));
|
||||
if (conf->types == NULL) {
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
for (i = 0; ngx_http_core_default_types[i].key.len; i++) {
|
||||
type = ngx_array_push(conf->types);
|
||||
if (type == NULL) {
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
for (i = 0; i < NGX_HTTP_TYPES_HASH_PRIME; i++) {
|
||||
if (ngx_array_init(&conf->types[i], cf->pool, 4,
|
||||
sizeof(ngx_http_type_t)) == NGX_ERROR)
|
||||
{
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
}
|
||||
type->key = ngx_http_core_default_types[i].key;
|
||||
type->key_hash =
|
||||
ngx_hash_key_lc(ngx_http_core_default_types[i].key.data,
|
||||
ngx_http_core_default_types[i].key.len);
|
||||
type->value = ngx_http_core_default_types[i].value;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; ngx_http_core_default_types[i].exten.len; i++) {
|
||||
ngx_http_types_hash_key(key,
|
||||
ngx_http_core_default_types[i].exten);
|
||||
if (conf->types_hash.buckets == NULL) {
|
||||
|
||||
type = ngx_array_push(&conf->types[key]);
|
||||
if (type == NULL) {
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
types_hash.hash = &conf->types_hash;
|
||||
types_hash.key = ngx_hash_key_lc;
|
||||
types_hash.max_size = conf->types_hash_max_size;
|
||||
types_hash.bucket_size = conf->types_hash_bucket_size;
|
||||
types_hash.name = "mime_types";
|
||||
types_hash.pool = cf->pool;
|
||||
types_hash.temp_pool = NULL;
|
||||
|
||||
*type = ngx_http_core_default_types[i];
|
||||
}
|
||||
if (ngx_hash_init(&types_hash, conf->types->elts, conf->types->nelts)
|
||||
!= NGX_OK)
|
||||
{
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2115,6 +2177,7 @@ ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|||
if (ngx_strcmp(value[2].data, "default") == 0) {
|
||||
ls->conf.default_server = 1;
|
||||
n = 3;
|
||||
|
||||
} else {
|
||||
n = 2;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,8 +70,8 @@ typedef struct {
|
|||
|
||||
ngx_http_phase_t phases[NGX_HTTP_LOG_PHASE + 1];
|
||||
|
||||
ngx_hash_t headers_in_hash;
|
||||
ngx_hash_t variables_hash;
|
||||
ngx_hash0_t headers_in_hash;
|
||||
ngx_hash0_t variables_hash;
|
||||
|
||||
ngx_uint_t server_names_hash;
|
||||
ngx_uint_t server_names_hash_threshold;
|
||||
|
|
@ -154,23 +154,6 @@ typedef struct {
|
|||
}
|
||||
|
||||
|
||||
#define NGX_HTTP_TYPES_HASH_PRIME 13
|
||||
|
||||
#define ngx_http_types_hash_key(key, ext) \
|
||||
{ \
|
||||
ngx_uint_t n; \
|
||||
for (key = 0, n = 0; n < ext.len; n++) { \
|
||||
key += ext.data[n]; \
|
||||
} \
|
||||
key %= NGX_HTTP_TYPES_HASH_PRIME; \
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
ngx_str_t exten;
|
||||
ngx_str_t type;
|
||||
} ngx_http_type_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
ngx_int_t status;
|
||||
ngx_int_t overwrite;
|
||||
|
|
@ -203,12 +186,13 @@ struct ngx_http_core_loc_conf_s {
|
|||
|
||||
ngx_http_handler_pt handler;
|
||||
|
||||
ngx_array_t *types;
|
||||
ngx_str_t default_type;
|
||||
|
||||
ngx_str_t root; /* root, alias */
|
||||
ngx_str_t post_action;
|
||||
|
||||
ngx_array_t *types;
|
||||
ngx_hash_t types_hash;
|
||||
ngx_str_t default_type;
|
||||
|
||||
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 */
|
||||
|
|
@ -241,6 +225,9 @@ struct ngx_http_core_loc_conf_s {
|
|||
|
||||
ngx_log_t *err_log;
|
||||
|
||||
ngx_uint_t types_hash_max_size;
|
||||
ngx_uint_t types_hash_bucket_size;
|
||||
|
||||
#if 0
|
||||
ngx_http_core_loc_conf_t *prev_location;
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1561,6 +1561,10 @@ ngx_http_finalize_request(ngx_http_request_t *r, ngx_int_t rc)
|
|||
ngx_del_timer(r->connection->write);
|
||||
}
|
||||
|
||||
if (r->connection->destroyed) {
|
||||
return;
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (r->connection->read->pending_eof) {
|
||||
#if (NGX_HAVE_KQUEUE)
|
||||
|
|
|
|||
|
|
@ -2541,7 +2541,7 @@ ngx_http_core_init_main_conf(ngx_conf_t *cf, void *conf)
|
|||
umcf->headers_in_hash.bucket_size = sizeof(ngx_http_upstream_header_t);
|
||||
umcf->headers_in_hash.name = "upstream_headers_in";
|
||||
|
||||
if (ngx_hash_init(&umcf->headers_in_hash, cf->pool,
|
||||
if (ngx_hash0_init(&umcf->headers_in_hash, cf->pool,
|
||||
ngx_http_upstream_headers_in, 0) != NGX_OK)
|
||||
{
|
||||
return NGX_CONF_ERROR;
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ typedef struct {
|
|||
|
||||
|
||||
typedef struct {
|
||||
ngx_hash_t headers_in_hash;
|
||||
ngx_hash0_t headers_in_hash;
|
||||
} ngx_http_upstream_main_conf_t;
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -116,6 +116,10 @@ static ngx_http_variable_t ngx_http_core_variables[] = {
|
|||
offsetof(ngx_http_request_t, args),
|
||||
NGX_HTTP_VAR_NOCACHABLE, 0 },
|
||||
|
||||
{ ngx_string("args"), ngx_http_variable_request,
|
||||
offsetof(ngx_http_request_t, args),
|
||||
NGX_HTTP_VAR_NOCACHABLE, 0 },
|
||||
|
||||
{ ngx_string("request_filename"), ngx_http_variable_request_filename, 0,
|
||||
NGX_HTTP_VAR_NOCACHABLE, 0 },
|
||||
|
||||
|
|
@ -857,7 +861,7 @@ ngx_http_variables_init_vars(ngx_conf_t *cf)
|
|||
cmcf->variables_hash.bucket_size = sizeof(ngx_http_variable_t);
|
||||
cmcf->variables_hash.name = "http variables";
|
||||
|
||||
if (ngx_hash_init(&cmcf->variables_hash, cf->pool,
|
||||
if (ngx_hash0_init(&cmcf->variables_hash, cf->pool,
|
||||
cmcf->all_variables.elts, cmcf->all_variables.nelts)
|
||||
!= NGX_OK)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue