# HG changeset patch # User Igor Sysoev # Date 1142929241 0 # Node ID fbed40ce7cb4fd7203fecc22a617b9ce5b950fb3 # Parent 16dd488c514bcbe65be553a3e7610a2c1569de8c nginx-0.3.34-RELEASE import *) Feature: the "add_header" directive supports the variables. diff --git a/docs/xml/nginx/changes.xml b/docs/xml/nginx/changes.xml --- a/docs/xml/nginx/changes.xml +++ b/docs/xml/nginx/changes.xml @@ -9,6 +9,20 @@ nginx changelog + + + + +директива add_header поддерживает переменные. + + +the "add_header" directive supports the variables. + + + + + + diff --git a/src/core/nginx.h b/src/core/nginx.h --- a/src/core/nginx.h +++ b/src/core/nginx.h @@ -8,7 +8,7 @@ #define _NGINX_H_INCLUDED_ -#define NGINX_VER "nginx/0.3.33" +#define NGINX_VER "nginx/0.3.34" #define NGINX_VAR "NGINX" #define NGX_OLDPID_EXT ".oldbin" diff --git a/src/http/modules/ngx_http_headers_filter_module.c b/src/http/modules/ngx_http_headers_filter_module.c --- a/src/http/modules/ngx_http_headers_filter_module.c +++ b/src/http/modules/ngx_http_headers_filter_module.c @@ -10,9 +10,16 @@ typedef struct { - time_t expires; - ngx_str_t cache_control; - ngx_array_t *headers; + ngx_table_elt_t value; + ngx_array_t *lengths; + ngx_array_t *values; +} ngx_http_header_val_t; + + +typedef struct { + time_t expires; + ngx_str_t cache_control; + ngx_array_t *headers; } ngx_http_headers_conf_t; @@ -92,7 +99,8 @@ ngx_http_headers_filter(ngx_http_request { size_t len; ngx_uint_t i; - ngx_table_elt_t *expires, *cc, **ccp, *h, *out; + ngx_table_elt_t *expires, *cc, **ccp, *out; + ngx_http_header_val_t *h; ngx_http_headers_conf_t *conf; if ((r->headers_out.status != NGX_HTTP_OK @@ -242,7 +250,20 @@ ngx_http_headers_filter(ngx_http_request return NGX_ERROR; } - *out = h[i]; + out->hash = h[i].value.hash; + out->key = h[i].value.key; + + if (h[i].lengths == NULL) { + out->value = h[i].value.value; + continue; + } + + if (ngx_http_script_run(r, &out->value, h[i].lengths->elts, 0, + h[i].values->elts) + == NULL) + { + return NGX_ERROR; + } } } @@ -368,8 +389,10 @@ ngx_http_headers_add(ngx_conf_t *cf, ngx { ngx_http_headers_conf_t *hcf = conf; - ngx_str_t *value; - ngx_table_elt_t *h; + ngx_int_t n; + ngx_str_t *value; + ngx_http_header_val_t *h; + ngx_http_script_compile_t sc; value = cf->args->elts; @@ -379,7 +402,8 @@ ngx_http_headers_add(ngx_conf_t *cf, ngx } if (hcf->headers == NULL) { - hcf->headers = ngx_array_create(cf->pool, 1, sizeof(ngx_table_elt_t)); + hcf->headers = ngx_array_create(cf->pool, 1, + sizeof(ngx_http_header_val_t)); if (hcf->headers == NULL) { return NGX_CONF_ERROR; } @@ -390,9 +414,31 @@ ngx_http_headers_add(ngx_conf_t *cf, ngx return NGX_CONF_ERROR; } - h->hash = 1; - h->key = value[1]; - h->value = value[2]; + h->value.hash = 1; + h->value.key = value[1]; + h->value.value = value[2]; + h->lengths = NULL; + h->values = NULL; + + n = ngx_http_script_variables_count(&value[2]); + + if (n == 0) { + return NGX_CONF_OK; + } + + ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); + + sc.cf = cf; + sc.source = &value[2]; + sc.lengths = &h->lengths; + sc.values = &h->values; + sc.variables = n; + sc.complete_lengths = 1; + sc.complete_values = 1; + + if (ngx_http_script_compile(&sc) != NGX_OK) { + return NGX_CONF_ERROR; + } return NGX_CONF_OK; } diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c --- a/src/http/ngx_http_core_module.c +++ b/src/http/ngx_http_core_module.c @@ -2012,6 +2012,7 @@ ngx_http_core_merge_loc_conf(ngx_conf_t if (conf->root.data == NULL) { + conf->alias = prev->alias; conf->root = prev->root; conf->root_lengths = prev->root_lengths; conf->root_values = prev->root_values; diff --git a/src/http/ngx_http_parse.c b/src/http/ngx_http_parse.c --- a/src/http/ngx_http_parse.c +++ b/src/http/ngx_http_parse.c @@ -689,6 +689,7 @@ ngx_http_parse_header_line(ngx_http_requ default: return NGX_HTTP_PARSE_INVALID_HEADER; } + break; /* end of header */ case sw_header_almost_done: