mirror of
https://github.com/nginx/nginx.git
synced 2024-12-04 05:38:59 +08:00
$r->variable() supports perl only variables
This commit is contained in:
parent
e773324c30
commit
65b8a197b9
@ -773,6 +773,8 @@ variable(r, name, value = NULL)
|
||||
STRLEN len;
|
||||
ngx_str_t var, val;
|
||||
ngx_uint_t i, hash;
|
||||
ngx_http_perl_var_t *v;
|
||||
ngx_http_perl_ctx_t *ctx;
|
||||
ngx_http_variable_value_t *vv;
|
||||
|
||||
ngx_http_perl_set_request(r);
|
||||
@ -814,13 +816,69 @@ variable(r, name, value = NULL)
|
||||
var.len = len;
|
||||
var.data = lowcase;
|
||||
|
||||
#if (NGX_LOG_DEBUG)
|
||||
|
||||
if (value) {
|
||||
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
||||
"perl variable: \"%V\"=\"%V\"", &var, &val);
|
||||
} else {
|
||||
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
||||
"perl variable: \"%V\"", &var);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
vv = ngx_http_get_variable(r, &var, hash, 1);
|
||||
if (vv == NULL) {
|
||||
XSRETURN_UNDEF;
|
||||
}
|
||||
|
||||
if (vv->not_found) {
|
||||
if (value == NULL) {
|
||||
|
||||
ctx = ngx_http_get_module_ctx(r, ngx_http_perl_module);
|
||||
|
||||
if (ctx->variables) {
|
||||
|
||||
v = ctx->variables->elts;
|
||||
for (i = 0; i < ctx->variables->nelts; i++) {
|
||||
|
||||
if (hash != v[i].hash
|
||||
|| len != v[i].name.len
|
||||
|| ngx_strncmp(lowcase, v[i].name.data, len) != 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (value) {
|
||||
v[i].value = val;
|
||||
XSRETURN_UNDEF;
|
||||
}
|
||||
|
||||
ngx_http_perl_set_targ(v[i].value.data, v[i].value.len, 0);
|
||||
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
if (value) {
|
||||
if (ctx->variables == NULL) {
|
||||
ctx->variables = ngx_array_create(r->pool, 1,
|
||||
sizeof(ngx_http_perl_var_t));
|
||||
if (ctx->variables == NULL) {
|
||||
XSRETURN_UNDEF;
|
||||
}
|
||||
}
|
||||
|
||||
v = ngx_array_push(ctx->variables);
|
||||
if (v == NULL) {
|
||||
XSRETURN_UNDEF;
|
||||
}
|
||||
|
||||
v->hash = hash;
|
||||
v->name.len = len;
|
||||
v->name.data = lowcase;
|
||||
v->value = val;
|
||||
|
||||
XSRETURN_UNDEF;
|
||||
}
|
||||
|
||||
@ -842,6 +900,8 @@ variable(r, name, value = NULL)
|
||||
|
||||
ngx_http_perl_set_targ(vv->data, vv->len, 0);
|
||||
|
||||
done:
|
||||
|
||||
ST(0) = TARG;
|
||||
|
||||
|
||||
|
@ -29,12 +29,21 @@ typedef struct {
|
||||
|
||||
ngx_uint_t done; /* unsigned done:1; */
|
||||
|
||||
ngx_array_t *variables; /* array of ngx_http_perl_var_t */
|
||||
|
||||
#if (NGX_HTTP_SSI)
|
||||
ngx_http_ssi_ctx_t *ssi;
|
||||
#endif
|
||||
} ngx_http_perl_ctx_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
ngx_uint_t hash;
|
||||
ngx_str_t name;
|
||||
ngx_str_t value;
|
||||
} ngx_http_perl_var_t;
|
||||
|
||||
|
||||
extern ngx_module_t ngx_http_perl_module;
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user