$upstream_http_... variables

This commit is contained in:
Igor Sysoev 2007-04-10 07:08:06 +00:00
parent da4b660274
commit 2723361e76
4 changed files with 41 additions and 3 deletions

View File

@ -2608,6 +2608,21 @@ ngx_http_upstream_response_time_variable(ngx_http_request_t *r,
}
ngx_int_t
ngx_http_upstream_header_variable(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data)
{
if (r->upstream == NULL) {
v->not_found = 1;
return NGX_OK;
}
return ngx_http_variable_unknown_header(v, (ngx_str_t *) data,
&r->upstream->headers_in.headers.part,
sizeof("upstream_http_") - 1);
}
static char *
ngx_http_upstream(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
{

View File

@ -248,6 +248,9 @@ struct ngx_http_upstream_s {
};
ngx_int_t ngx_http_upstream_header_variable(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data);
void ngx_http_upstream_init(ngx_http_request_t *r);
ngx_http_upstream_srv_conf_t *ngx_http_upstream_add(ngx_conf_t *cf,
ngx_url_t *u, ngx_uint_t flags);

View File

@ -23,8 +23,6 @@ static ngx_int_t ngx_http_variable_unknown_header_in(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data);
static ngx_int_t ngx_http_variable_unknown_header_out(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data);
static ngx_int_t ngx_http_variable_unknown_header(ngx_http_variable_value_t *v,
ngx_str_t *var, ngx_list_part_t *part, size_t prefix);
static ngx_int_t ngx_http_variable_host(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data);
@ -451,6 +449,17 @@ ngx_http_get_variable(ngx_http_request_t *r, ngx_str_t *name, ngx_uint_t key,
return NULL;
}
if (ngx_strncmp(name->data, "upstream_http_", 10) == 0) {
if (ngx_http_upstream_header_variable(r, vv, (uintptr_t) name)
== NGX_OK)
{
return vv;
}
return NULL;
}
vv->not_found = 1;
if (nowarn == 0) {
@ -614,7 +623,7 @@ ngx_http_variable_unknown_header_out(ngx_http_request_t *r,
}
static ngx_int_t
ngx_int_t
ngx_http_variable_unknown_header(ngx_http_variable_value_t *v, ngx_str_t *var,
ngx_list_part_t *part, size_t prefix)
{
@ -1292,6 +1301,13 @@ ngx_http_variables_init_vars(ngx_conf_t *cf)
continue;
}
if (ngx_strncmp(v[i].name.data, "upstream_http_", 14) == 0) {
v[i].get_handler = ngx_http_upstream_header_variable;
v[i].data = (uintptr_t) &v[i].name;
continue;
}
ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
"unknown \"%V\" variable", &v[i].name);

View File

@ -61,6 +61,10 @@ ngx_http_variable_value_t *ngx_http_get_flushed_variable(ngx_http_request_t *r,
ngx_http_variable_value_t *ngx_http_get_variable(ngx_http_request_t *r,
ngx_str_t *name, ngx_uint_t key, ngx_uint_t nowarn);
ngx_int_t ngx_http_variable_unknown_header(ngx_http_variable_value_t *v,
ngx_str_t *var, ngx_list_part_t *part, size_t prefix);
#define ngx_http_clear_variable(r, index) r->variables0[index].text.data = NULL;