support "*" in gzip_types, ssi_types, etc

This commit is contained in:
Igor Sysoev 2009-11-30 13:15:10 +00:00
parent b56979c3da
commit 4a8cf7faad
9 changed files with 45 additions and 22 deletions

View file

@ -237,8 +237,8 @@ ngx_http_addition_merge_conf(ngx_conf_t *cf, void *parent, void *child)
ngx_conf_merge_str_value(conf->before_body, prev->before_body, "");
ngx_conf_merge_str_value(conf->after_body, prev->after_body, "");
if (ngx_http_merge_types(cf, conf->types_keys, &conf->types,
prev->types_keys, &prev->types,
if (ngx_http_merge_types(cf, &conf->types_keys, &conf->types,
&prev->types_keys, &prev->types,
ngx_http_html_default_types)
!= NGX_OK)
{

View file

@ -1550,8 +1550,8 @@ ngx_http_charset_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
ngx_http_charset_recode_t *recode;
ngx_http_charset_main_conf_t *mcf;
if (ngx_http_merge_types(cf, conf->types_keys, &conf->types,
prev->types_keys, &prev->types,
if (ngx_http_merge_types(cf, &conf->types_keys, &conf->types,
&prev->types_keys, &prev->types,
ngx_http_charset_default_types)
!= NGX_OK)
{

View file

@ -1123,8 +1123,8 @@ ngx_http_gzip_merge_conf(ngx_conf_t *cf, void *parent, void *child)
MAX_MEM_LEVEL - 1);
ngx_conf_merge_value(conf->min_length, prev->min_length, 20);
if (ngx_http_merge_types(cf, conf->types_keys, &conf->types,
prev->types_keys, &prev->types,
if (ngx_http_merge_types(cf, &conf->types_keys, &conf->types,
&prev->types_keys, &prev->types,
ngx_http_html_default_types)
!= NGX_OK)
{

View file

@ -2773,8 +2773,8 @@ ngx_http_ssi_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
ngx_conf_merge_size_value(conf->min_file_chunk, prev->min_file_chunk, 1024);
ngx_conf_merge_size_value(conf->value_len, prev->value_len, 256);
if (ngx_http_merge_types(cf, conf->types_keys, &conf->types,
prev->types_keys, &prev->types,
if (ngx_http_merge_types(cf, &conf->types_keys, &conf->types,
&prev->types_keys, &prev->types,
ngx_http_html_default_types)
!= NGX_OK)
{

View file

@ -671,8 +671,8 @@ ngx_http_sub_merge_conf(ngx_conf_t *cf, void *parent, void *child)
conf->value = prev->value;
}
if (ngx_http_merge_types(cf, conf->types_keys, &conf->types,
prev->types_keys, &prev->types,
if (ngx_http_merge_types(cf, &conf->types_keys, &conf->types,
&prev->types_keys, &prev->types,
ngx_http_html_default_types)
!= NGX_OK)
{

View file

@ -1230,8 +1230,8 @@ ngx_http_xslt_filter_merge_conf(ngx_conf_t *cf, void *parent, void *child)
conf->sheets = prev->sheets;
}
if (ngx_http_merge_types(cf, conf->types_keys, &conf->types,
prev->types_keys, &prev->types,
if (ngx_http_merge_types(cf, &conf->types_keys, &conf->types,
&prev->types_keys, &prev->types,
ngx_http_xslt_default_types)
!= NGX_OK)
{

View file

@ -1854,6 +1854,10 @@ ngx_http_types_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
types = (ngx_array_t **) (p + cmd->offset);
if (*types == (void *) -1) {
return NGX_CONF_OK;
}
default_type = cmd->post;
if (*types == NULL) {
@ -1879,6 +1883,11 @@ ngx_http_types_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
for (i = 1; i < cf->args->nelts; i++) {
if (value[i].len == 1 && value[i].data[0] == '*') {
*types = (void *) -1;
return NGX_CONF_OK;
}
hash = ngx_hash_strlow(value[i].data, value[i].data, value[i].len);
value[i].data[value[i].len] = '\0';
@ -1907,13 +1916,17 @@ ngx_http_types_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
char *
ngx_http_merge_types(ngx_conf_t *cf, ngx_array_t *keys, ngx_hash_t *types_hash,
ngx_array_t *prev_keys, ngx_hash_t *prev_types_hash,
ngx_http_merge_types(ngx_conf_t *cf, ngx_array_t **keys, ngx_hash_t *types_hash,
ngx_array_t **prev_keys, ngx_hash_t *prev_types_hash,
ngx_str_t *default_types)
{
ngx_hash_init_t hash;
if (keys) {
if (*keys) {
if (*keys == (void *) -1) {
return NGX_CONF_OK;
}
hash.hash = types_hash;
hash.key = NULL;
@ -1923,7 +1936,7 @@ ngx_http_merge_types(ngx_conf_t *cf, ngx_array_t *keys, ngx_hash_t *types_hash,
hash.pool = cf->pool;
hash.temp_pool = NULL;
if (ngx_hash_init(&hash, keys->elts, keys->nelts) != NGX_OK) {
if (ngx_hash_init(&hash, (*keys)->elts, (*keys)->nelts) != NGX_OK) {
return NGX_CONF_ERROR;
}
@ -1932,13 +1945,17 @@ ngx_http_merge_types(ngx_conf_t *cf, ngx_array_t *keys, ngx_hash_t *types_hash,
if (prev_types_hash->buckets == NULL) {
if (prev_keys == NULL) {
if (*prev_keys == NULL) {
if (ngx_http_set_default_types(cf, &prev_keys, default_types)
if (ngx_http_set_default_types(cf, prev_keys, default_types)
!= NGX_OK)
{
return NGX_CONF_ERROR;
}
} else if (*prev_keys == (void *) -1) {
*keys = *prev_keys;
return NGX_CONF_OK;
}
hash.hash = prev_types_hash;
@ -1949,7 +1966,9 @@ ngx_http_merge_types(ngx_conf_t *cf, ngx_array_t *keys, ngx_hash_t *types_hash,
hash.pool = cf->pool;
hash.temp_pool = NULL;
if (ngx_hash_init(&hash, prev_keys->elts, prev_keys->nelts) != NGX_OK) {
if (ngx_hash_init(&hash, (*prev_keys)->elts, (*prev_keys)->nelts)
!= NGX_OK)
{
return NGX_CONF_ERROR;
}
}

View file

@ -126,9 +126,9 @@ void ngx_http_test_reading(ngx_http_request_t *r);
char *ngx_http_types_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
char *ngx_http_merge_types(ngx_conf_t *cf, ngx_array_t *keys,
ngx_hash_t *types_hash, ngx_array_t *prev_keys, ngx_hash_t *prev_types_hash,
ngx_str_t *default_types);
char *ngx_http_merge_types(ngx_conf_t *cf, ngx_array_t **keys,
ngx_hash_t *types_hash, ngx_array_t **prev_keys,
ngx_hash_t *prev_types_hash, ngx_str_t *default_types);
ngx_int_t ngx_http_set_default_types(ngx_conf_t *cf, ngx_array_t **types,
ngx_str_t *default_type);

View file

@ -1572,6 +1572,10 @@ ngx_http_test_content_type(ngx_http_request_t *r, ngx_hash_t *types_hash)
size_t len;
ngx_uint_t i, hash;
if (types_hash->size == 0) {
return (void *) 4;
}
if (r->headers_out.content_type.len == 0) {
return NULL;
}