Skip to content

Commit feec1c1

Browse files
author
Stefan Fritsch
committed
Unify syntax of config directives taking an expression as optional contition argument
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1197413 13f79535-47bb-0310-9956-ffa450edef68
1 parent 3b58006 commit feec1c1

6 files changed

Lines changed: 38 additions & 26 deletions

File tree

CHANGES

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ Changes with Apache 2.3.15
1212
PR 51714. [Stefan Fritsch, Jim Jagielski, Ruediger Pluem, Eric Covener,
1313
<lowprio20 gmail.com>]
1414

15+
*) mod_log_debug: Rename optional argument from if= to expr=, to be more
16+
in line with other config directives. [Stefan Fritsch]
17+
18+
*) mod_headers: Require an expression to be specified with expr=, to be more
19+
in line with other config directives. [Stefan Fritsch]
20+
1521
*) mod_substitute: To prevent overboarding memory usage, limit line length
1622
to 1MB. [Stefan Fritsch]
1723

docs/manual/mod/mod_headers.xml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ headers</description>
184184
<li>
185185
Set a test cookie if and only if the client didn't send us a cookie
186186
<example>
187-
Header set Set-Cookie testcookie !$req{Cookie}
187+
Header set Set-Cookie testcookie "expr=-z %{req:Cookie}"
188188
</example>
189189
</li>
190190
</ol>
@@ -273,15 +273,15 @@ headers</description>
273273
<dl>
274274
<dt><code>early</code></dt>
275275
<dd>Specifies <a href="#early">early processing</a>.</dd>
276-
<dt><code>env=[!]varname</code></dt>
276+
<dt><code>env=[!]<var>varname</var></code></dt>
277277
<dd>The directive is applied if and only if the <a href="../env.html"
278278
>environment variable</a> <code>varname</code> exists.
279279
A <code>!</code> in front of <code>varname</code> reverses the test,
280280
so the directive applies only if <code>varname</code> is unset.</dd>
281-
<dt><code>expr</code></dt>
282-
<dd>An string that matches neither of the above is parsed as an
283-
expression. Details of expression syntax and evaluation are
284-
currently best documented on the <module>mod_filter</module> page.</dd>
281+
<dt><code>expr=<var>expression</var></code></dt>
282+
<dd>The directive is applied if and only if <var>expression</var>
283+
evaluates to true. Details of expression syntax and evaluation are
284+
documented in the <a href="../expr.html">ap_expr</a> documentation.</dd>
285285
</dl>
286286

287287
<p>Except in <a href="#early">early</a> mode, the
@@ -447,15 +447,15 @@ headers</description>
447447
<dl>
448448
<dt><code>early</code></dt>
449449
<dd>Specifies <a href="#early">early processing</a>.</dd>
450-
<dt><code>env=[!]varname</code></dt>
450+
<dt><code>env=[!]<var>varname</var></code></dt>
451451
<dd>The directive is applied if and only if the <a href="../env.html"
452452
>environment variable</a> <code>varname</code> exists.
453453
A <code>!</code> in front of <code>varname</code> reverses the test,
454454
so the directive applies only if <code>varname</code> is unset.</dd>
455-
<dt><code>expr</code></dt>
456-
<dd>An string that matches neither of the above is parsed as an
457-
expression. Details of expression syntax and evaluation are
458-
currently best documented on the <module>mod_filter</module> page.</dd>
455+
<dt><code>expr=<var>expression</var></code></dt>
456+
<dd>The directive is applied if and only if <var>expression</var>
457+
evaluates to true. Details of expression syntax and evaluation are
458+
documented in the <a href="../expr.html">ap_expr</a> documentation.</dd>
459459
</dl>
460460

461461
<p>Except in <a href="#early">early</a> mode, the

docs/manual/mod/mod_log_config.xml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,8 @@
388388
<description>Sets filename and format of log file</description>
389389
<syntax>CustomLog <var>file</var>|<var>pipe</var>
390390
<var>format</var>|<var>nickname</var>
391-
[env=[!]<var>environment-variable</var>]</syntax>
391+
[env=[!]<var>environment-variable</var>|
392+
expr=<var>expression</var>]</syntax>
392393
<contextlist><context>server config</context><context>virtual host</context>
393394
</contextlist>
394395

@@ -445,12 +446,13 @@
445446
</example>
446447

447448
<p>The third argument is optional and controls whether or
448-
not to log a particular request based on the
449-
presence or absence of a particular variable in the server
450-
environment. If the specified <a href="../env.html">environment
451-
variable</a> is set for the request (or is not set, in the case
452-
of a '<code>env=!<var>name</var></code>' clause), then the
453-
request will be logged.</p>
449+
not to log a particular request. The condition can be the
450+
presence or absence (in the case of a '<code>env=!<var>name</var></code>'
451+
clause) of a particular variable in the server
452+
<a href="../env.html">environment</a>. Alternatively, the condition
453+
can be expressed as arbitrary boolean <a href="../expr.html"
454+
>expression</a>. If the condition is not satisfied, the request
455+
will not be logged.</p>
454456

455457
<p>Environment variables can be set on a per-request
456458
basis using the <module>mod_setenvif</module>

docs/manual/mod/mod_log_debug.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
Log message if request to /foo/* is processed in a sub-request:
4747
<example>
4848
&lt;Location /foo/&gt;<br/>
49-
&nbsp;&nbsp;LogMessage "subrequest to /foo/" hook=type_checker if=%{IS_SUBREQ}<br/>
49+
&nbsp;&nbsp;LogMessage "subrequest to /foo/" hook=type_checker expr=%{IS_SUBREQ}<br/>
5050
&lt;/Location&gt;<br/>
5151
</example>
5252

@@ -59,9 +59,9 @@
5959
Log message if an IPv6 client causes a request timeout:
6060
<example>
6161
LogMessage "IPv6 timeout from %{REMOTE_ADDR}"
62-
"if=-T %{IPV6} &amp;&amp; %{REQUEST_STATUS} = 408"
62+
"expr=-T %{IPV6} &amp;&amp; %{REQUEST_STATUS} = 408"
6363
</example>
64-
Note the placing of the double quotes for the <code>if=</code> argument.
64+
Note the placing of the double quotes for the <code>expr=</code> argument.
6565
</li>
6666

6767
<li>
@@ -85,7 +85,7 @@
8585
<description>Log userdefined message to error log
8686
</description>
8787
<syntax>LogMessage <var>message</var>
88-
[hook=<var>hook</var>] [if=<var>expression</var>]
88+
[hook=<var>hook</var>] [expr=<var>expression</var>]
8989
</syntax>
9090
<default>Unset</default>
9191
<contextlist><context>directory</context>

modules/loggers/mod_log_debug.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,8 @@ static const char *cmd_log_message(cmd_parms *cmd, void *dconf_, const char *arg
221221
return apr_psprintf(cmd->pool, "Invalid hook name: %s", name);
222222
}
223223
}
224-
else if (strncasecmp(args[i], "if=", 3) == 0) {
225-
const char *expr = args[i] + 3;
224+
else if (strncasecmp(args[i], "expr=", 5) == 0) {
225+
const char *expr = args[i] + 5;
226226
entry->condition = ap_expr_parse_cmd(cmd, expr,
227227
AP_EXPR_FLAG_DONT_VARY,
228228
&err, NULL);

modules/metadata/mod_headers.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,15 +490,19 @@ static APR_INLINE const char *header_inout_cmd(cmd_parms *cmd,
490490
}
491491
condition_var = envclause + 4;
492492
}
493-
else {
493+
else if (strncasecmp(envclause, "expr=", 5) == 0) {
494494
const char *err = NULL;
495-
expr = ap_expr_parse_cmd(cmd, envclause, 0, &err, NULL);
495+
expr = ap_expr_parse_cmd(cmd, envclause + 5, 0, &err, NULL);
496496
if (err) {
497497
return apr_pstrcat(cmd->pool,
498498
"Can't parse envclause/expression: ", err,
499499
NULL);
500500
}
501501
}
502+
else {
503+
return apr_pstrcat(cmd->pool, "Unknown parameter: ", envclause,
504+
NULL);
505+
}
502506
}
503507

504508
if ((colon = ap_strchr_c(hdr, ':'))) {

0 commit comments

Comments
 (0)