mirror of
https://github.com/nginx/nginx.git
synced 2024-12-01 11:19:00 +08:00
$upstream_http_... variables
This commit is contained in:
parent
da4b660274
commit
2723361e76
@ -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)
|
||||
{
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user