mod_rewrite: Allow to set environment variables without
explicitely giving a value.
Before this patch using [ENV=VAR] instead of [ENV=VAR:VAL]
silently drops the flag (it is added to the list of vars to set,
but then never actually set).
Submitted by: rjung
Reviewed by: rjung, niq, rpluem
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.2.x@964741
13f79535-47bb-0310-9956-
ffa450edef68
an action to happen when a URL maps to no file, without resorting
to ErrorDocument or mod_rewrite. PR 47184 [Nick Kew]
+ *) mod_rewrite: Allow to set environment variables without explicitely
+ giving a value. [Rainer Jung]
+
Changes with Apache 2.2.15
PATCHES ACCEPTED TO BACKPORT FROM TRUNK:
[ start all new proposals below, under PATCHES PROPOSED. ]
- *) mod_rewrite: Allow to set environment variables using mod_rewrite without
- explicitely giving a value.
- Most modules only check presence of a variable, not the value, so it makes
- sense to make the VAL argument in the mod_rewrite ENV flag optional.
- Currently using [ENV=VAR] instead of [ENV=VAR:VAL] silently drops the flag
- (it is added to the list of vars to set, but then never actually set).
- Trunk version of patch:
- http://svn.apache.org/viewvc?rev=960233&view=rev
- Backport version for 2.2.x of patch:
- http://people.apache.org/~rjung/patches/httpd-branch-2.2-mod_rewrite-env_var-emptyvalue.patch
- +1: rjung, niq, rpluem
PATCHES PROPOSED TO BACKPORT FROM TRUNK:
[ New proposals should be added at the end of the list ]
appended.</p></dd>
<dt>
- '<code>env|E=</code><em>VAR</em>:<em>VAL</em>'
+ '<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 to the value <em>VAL</em>, where <em>VAL</em> can
- contain regexp backreferences (<code>$N</code> and
+ 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
appended.</p></dd>
<dt>
- '<code>env|E=</code><em>VAR</em>:<em>VAL</em>'
+ '<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 to the value <em>VAL</em>, where <em>VAL</em> can
- contain regexp backreferences (<code>$N</code> and
+ 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
name = do_expand(env->data, ctx, NULL);
if ((val = ap_strchr(name, ':')) != NULL) {
*val++ = '\0';
-
- apr_table_set(ctx->r->subprocess_env, name, val);
- rewritelog((ctx->r, 5, NULL, "setting env variable '%s' to '%s'",
- name, val));
+ } else {
+ 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;
}