From: Stefan Fritsch Date: Wed, 29 Dec 2010 20:41:55 +0000 (+0000) Subject: Allow to unset environment variables using E=!VAR. X-Git-Tag: 2.3.11~311 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7f6106542e5ec3aec4c85f4cdb8777a8cdb29510;p=apache Allow to unset environment variables using E=!VAR. PR: 49512 Submitted by: Mark Drayton , Stefan Fritsch git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1053726 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index 44dba865b3..9f1e631b43 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,9 @@ Changes with Apache 2.3.11 + *) mod_rewrite: Allow to unset environment variables using E=!VAR. + PR 49512. [Mark Drayton , Stefan Fritsch] + *) mod_headers: Restore the 2.3.8 and earlier default for the first argument of the Header directive ("onsuccess"). [Eric Covener] diff --git a/docs/manual/mod/mod_rewrite.xml b/docs/manual/mod/mod_rewrite.xml index 4896f4dcfa..d219cda527 100644 --- a/docs/manual/mod/mod_rewrite.xml +++ b/docs/manual/mod/mod_rewrite.xml @@ -1036,9 +1036,10 @@ cannot use $N in the substitution string! ... - env|E=VAR[:VAL] + env|E=[!]VAR[:VAL] Causes an environment variable VAR to be set (to the - value VAL if provided). VAL if provided). The form !VAR causes + the environment variable VAR to be unset.details ... diff --git a/docs/manual/rewrite/flags.xml b/docs/manual/rewrite/flags.xml index c36978ebda..7457b7853b 100644 --- a/docs/manual/rewrite/flags.xml +++ b/docs/manual/rewrite/flags.xml @@ -212,6 +212,7 @@ variables work.

[E=VAR:VAL] +[E=!VAR]

VAL may contain backreferences ($N or @@ -226,6 +227,15 @@ variables work.

you can set the environment variable named VAR to an empty value.

+

The form

+ + +[E=!VAR] + + +

allows to unset a previouslz set environment variable named +VAR.

+

Environment variables can then be used in a variety of contexts, including CGI programs, other RewriteRule directives, or CustomLog directives.

diff --git a/modules/mappers/mod_rewrite.c b/modules/mappers/mod_rewrite.c index 44ff0b46cc..2571e2ca84 100644 --- a/modules/mappers/mod_rewrite.c +++ b/modules/mappers/mod_rewrite.c @@ -2408,15 +2408,22 @@ static void do_expand_env(data_item *env, rewrite_ctx *ctx) while (env) { name = do_expand(env->data, ctx, NULL); - if ((val = ap_strchr(name, ':')) != NULL) { - *val++ = '\0'; - } else { - val = ""; + if (*name == '!') { + name++; + apr_table_unset(ctx->r->subprocess_env, name); + rewritelog((ctx->r, 5, NULL, "unsetting env variable '%s'", name)); } + else { + if ((val = ap_strchr(name, ':')) != NULL) { + *val++ = '\0'; + } else { + val = ""; + } - apr_table_set(ctx->r->subprocess_env, name, val); - rewritelog((ctx->r, 5, NULL, "setting env variable '%s' to '%s'", - name, val)); + apr_table_set(ctx->r->subprocess_env, name, val); + rewritelog((ctx->r, 5, NULL, "setting env variable '%s' to '%s'", + name, val)); + } env = env->next; }