Commit 98b682dd authored by Rainer Jung's avatar Rainer Jung
Browse files

mod_rewrite: Allow to unset environment variables.

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
parent 6ce70c5f
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
                                                         -*- 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]
+0 −8
Original line number Diff line number Diff line
@@ -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 ]

+6 −6
Original line number Diff line number Diff line
@@ -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 
+33 −1
Original line number Diff line number Diff line
@@ -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>
+14 −7
Original line number Diff line number Diff line
@@ -2347,6 +2347,12 @@ static void do_expand_env(data_item *env, rewrite_ctx *ctx)

    while (env) {
        name = do_expand(env->data, ctx, NULL);
        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 {
@@ -2356,6 +2362,7 @@ static void do_expand_env(data_item *env, rewrite_ctx *ctx)
            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;
    }