]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
mod_rewrite: Allow to unset environment variables.
authorRainer Jung <rjung@apache.org>
Mon, 7 Mar 2011 20:39:54 +0000 (20:39 +0000)
committerRainer Jung <rjung@apache.org>
Mon, 7 Mar 2011 20:39:54 +0000 (20:39 +0000)
PR: 50746
Submitted by: rjung
Reviewed  by: covener, rpluem

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.2.x@1078933 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
STATUS
docs/manual/mod/mod_rewrite.xml
docs/manual/rewrite/rewrite_flags.xml
modules/mappers/mod_rewrite.c

diff --git a/CHANGES b/CHANGES
index 488182d7892601aeccbc1faf2a3f315e80cbc4e7..7710ed66e9e22679498ee7d28efcce7606c56902 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,10 +1,13 @@
                                                          -*- coding: utf-8 -*-
 Changes with Apache 2.2.18
 
+  *) mod_rewrite: Allow to unset environment variables. PR 50746.
+     [Rainer Jung]
+
   *) suEXEC: Add Suexec directive to disable suEXEC without renaming the
      binary (Suexec Off), or force startup failure if suEXEC is required
      but not supported (Suexec On).  [Jeff Trawick]
+
   *) mod_proxy: Put the worker in error state if the SSL handshake with the
      backend fails. PR 50332.
      [Daniel Ruggeri <DRuggeri primary.net>, Ruediger Pluem]
diff --git a/STATUS b/STATUS
index 930c1e81bf5607eb81c66b4887d39e8c027326f4..a06be5e2cda6a6cf8112a3af7786704619988d99 100644 (file)
--- a/STATUS
+++ b/STATUS
@@ -105,14 +105,6 @@ PATCHES ACCEPTED TO BACKPORT FROM TRUNK:
                  Non-optional broken features are worse :)
                  Trunk must be patched identically.
 
-  * mod_rewrite: Allow to unset environment variables.
-     Direct backport from trunk.
-     PR: 50746
-     2.2.x patch: https://issues.apache.org/bugzilla/attachment.cgi?id=26646
-     (patch is simpler if viewed with whitespace changes ignored)
-     +1 rjung, covener, rpluem
-        (needs doc too including the behavior change in 2.2.16)
-
 PATCHES PROPOSED TO BACKPORT FROM TRUNK:
   [ New proposals should be added at the end of the list ]
 
index 29e924c50cf5103b5de372ae195b524b267cca95..5588803d66d76e23c3b04e2ee48655d61a389e5c 100644 (file)
@@ -1382,16 +1382,16 @@ cannot use <code>$N</code> in the substitution string!
         only the direct result of substitutions, without any PATH_INFO 
         appended.</p></dd>
 
-        <dt>
-        '<code>env|E=</code><em>VAR</em>[:<em>VAL</em>]'
+        <dt>'<code>env|E=!</code><em>VAR</em>[:<em>VAL</em>]'
         (set environment variable)</dt><dd>
         This forces an environment variable named <em>VAR</em> to
         be set. The value will be <em>VAL</em> if provided, where <em>VAL</em>
         can contain regexp backreferences (<code>$N</code> and
-        <code>%N</code>) which will be expanded. You can use this
-        flag more than once, to set more than one variable. The
-        variables can later be dereferenced in many situations, most commonly
-       from within XSSI (via <code>&lt;!--#echo
+        <code>%N</code>) which will be expanded. The form !<em>VAR</em> causes
+        the environment variable <em>VAR</em> to be unset and does not accept
+        any <em>VAL</em>. You can use this flag more than once, to set more
+        than one variable. The variables can later be dereferenced in many
+        situations, most commonly from within XSSI (via <code>&lt;!--#echo
         var="VAR"--&gt;</code>) or CGI (<code>$ENV{'VAR'}</code>). 
        You can also dereference the variable in a later RewriteCond pattern, using
         <code>%{ENV:VAR}</code>. Use this to strip 
index ae2b97f9f479980f1350d7deb55ea75b4112685f..2d11ec93186cbf76fe6620d996681d48388b5019 100644 (file)
@@ -108,7 +108,39 @@ is run, thus unsetting what you have set. See <a href="../env.html">the
 Environment Variables document</a> for more details on how Environment
 variables work.</p>
 
-<p>The following example sets an evironment variable called 'image' to a
+<p>The full syntax for this flag is:</p>
+
+<example>
+[E=VAR:VAL]
+[E=!VAR]
+</example>
+
+<p><code>VAL</code> may contain backreferences (<code>$N</code> or
+<code>%N</code>) which will be expanded.</p>
+
+<p>Using the short form</p>
+
+<example>
+[E=VAR]
+</example>
+
+<p>you can set the environment variable named <code>VAR</code> to an
+empty value.</p>
+
+<p>The form</p>
+
+<example>
+[E=!VAR]
+</example>
+
+<p>allows to unset a previously set environment variable named
+<code>VAR</code>.</p>
+
+<p>Environment variables can then be used in a variety of
+contexts, including CGI programs, other RewriteRule directives, or
+CustomLog directives.</p>
+
+<p>The following example sets an environment variable called 'image' to a
 value of '1' if the requested URI is an image file. Then, that
 environment variable is used to exclude those requests from the access
 log.</p>
index 36609ccaa947cd20599d0a3ea1f5243818f32607..700107385f260b58ac875485e2f83d0b5558121c 100644 (file)
@@ -2347,15 +2347,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;
     }