Commit dc8e3c08 authored by Stefan Fritsch's avatar Stefan Fritsch
Browse files

- Add <ElseIf> and <Else> to complement <If> sections. These are both easier

  to use and more efficient than using several <If> sections.
- Update <If> documentation a bit.


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1132469 13f79535-47bb-0310-9956-ffa450edef68
parent 3e24f874
Loading
Loading
Loading
Loading
+3 −0
Changes for CHANGES: 3 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -2,6 +2,9 @@

Changes with Apache 2.3.13

  *) core: Add <ElseIf> and <Else> to complement <If> sections.
     [Stefan Fritsch]

  *) mod_ext_filter: Remove DebugLevel option in favor of per-module loglevel.
     [Stefan Fritsch]

+3 −1
Changes for docs/manual/expr.xml: 3 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -38,7 +38,9 @@
    </p>
  </summary>

<seealso><directive module="core">If</directive></seealso>
<seealso><directive module="core" type="section">If</directive></seealso>
<seealso><directive module="core" type="section">ElseIf</directive></seealso>
<seealso><directive module="core" type="section">Else</directive></seealso>
<seealso><directive module="mod_rewrite">RewriteCond</directive></seealso>
<seealso><directive module="mod_setenvif">SetEnvIfExpr</directive></seealso>
<seealso><directive module="mod_filter">FilterProvider</directive></seealso>
+115 −12
Changes for docs/manual/mod/core.xml: 115 added lines, 12 removed lines.
Original line number Diff line number Diff line
@@ -801,6 +801,102 @@ from the web</description>
Locations</a></seealso>
</directivesynopsis>

<directivesynopsis type="section">
<name>Else</name>
<description>Contains directives that apply only if the condition of a
previous <directive type="section" module="core">If</directive> or
<directive type="section" module="core">ElseIf</directive> section is not
satisfied by a request at runtime</description>
<syntax>&lt;Else&gt; ... &lt;/Else&gt;</syntax>
<contextlist><context>server config</context><context>virtual host</context>
<context>directory</context><context>.htaccess</context>
</contextlist>
<override>All</override>

<usage>
    <p>The <directive type="section">Else</directive> applies the enclosed
    directives if and only if the most recent
    <directive type="section">If</directive> or
    <directive type="section">ElseIf</directive> section
    in the same scope has not been applied.
    For example: In </p>

    <example>
        &lt;If "-z req('Host')"&gt;<br/>
        ...<br/>
        &lt;/If&gt;<br/>
        &lt;Else&gt;<br/>
        ...<br/>
        &lt;/Else&gt;<br/>
    </example>

    <p> The <directive type="section">If</directive> would match HTTP/1.0
        requests without a <var>Host:</var> header and the
        <directive type="section">Else</directive> would match requests
        with a <var>Host:</var> header.</p>

</usage>
<seealso><directive type="section" module="core">If</directive></seealso>
<seealso><directive type="section" module="core">ElseIf</directive></seealso>
<seealso><a href="../sections.html">How &lt;Directory&gt;, &lt;Location&gt;,
    &lt;Files&gt; sections work</a> for an explanation of how these
    different sections are combined when a request is received.
    <directive type="section">If</directive>,
    <directive type="section">ElseIf</directive>, and
    <directive type="section">Else</directive> are applied last.</seealso>
</directivesynopsis>

<directivesynopsis type="section">
<name>ElseIf</name>
<description>Contains directives that apply only if a condition is satisfied
by a request at runtime while the condition of a previous
<directive type="section" module="core">If</directive> or
<directive type="section">ElseIf</directive> section is not
satisfied</description>
<syntax>&lt;ElseIf <var>expression</var>&gt; ... &lt;/ElseIf&gt;</syntax>
<contextlist><context>server config</context><context>virtual host</context>
<context>directory</context><context>.htaccess</context>
</contextlist>
<override>All</override>

<usage>
    <p>The <directive type="section">ElseIf</directive> applies the enclosed
    directives if and only if both the given condition evaluates to true and
    the most recent <directive type="section">If</directive> or
    <directive type="section">ElseIf</directive> section in the same scope has
    not been applied.  For example: In </p>

    <example>
        &lt;If "-R '10.1.0.0/16'"&gt;<br/>
        ...<br/>
        &lt;/If&gt;<br/>
        &lt;ElseIf "-R '10.0.0.0/8'"&gt;<br/>
        ...<br/>
        &lt;/ElseIf&gt;<br/>
        &lt;Else&gt;<br/>
        ...<br/>
        &lt;/Else&gt;<br/>
    </example>

    <p>The <directive type="section">ElseIf</directive> would match if
    the remote address of a request belongs to the subnet 10.0.0.0/8 but
    not to the subnet 10.1.0.0/16.</p>

</usage>
<seealso><a href="../expr.html">Expressions in Apache HTTP Server</a>,
for a complete reference and more examples.</seealso>
<seealso><directive type="section" module="core">If</directive></seealso>
<seealso><directive type="section" module="core">Else</directive></seealso>
<seealso><a href="../sections.html">How &lt;Directory&gt;, &lt;Location&gt;,
    &lt;Files&gt; sections work</a> for an explanation of how these
    different sections are combined when a request is received.
    <directive type="section">If</directive>,
    <directive type="section">ElseIf</directive>, and
    <directive type="section">Else</directive> are applied last.</seealso>
</directivesynopsis>



<directivesynopsis>
<name>EnableMMAP</name>
<description>Use memory-mapping to read files during delivery</description>
@@ -1603,31 +1699,38 @@ satisfied by a request at runtime</description>
    For example:</p>

    <example>
        &lt;If "$req{Host} = ''"&gt;
        &lt;If "-z req('Host')"&gt;
    </example>

    <p>would match HTTP/1.0 requests without a <var>Host:</var> header.</p>

    <p>You may compare the value of any variable in the request headers
    ($req), response headers ($resp) or environment ($env) in your
    expression.</p>

    <p>Apart from <code>=</code>, <code>If</code> can use the <code>IN</code>
    operator to compare if the expression is in a given range:</p>
    <p>would match HTTP/1.0 requests without a <var>Host:</var> header.
    Expressions may contain various shell-like operators for string
    comparison (<code>=</code>, <code>!=</code>, <code>&lt;</code>, ...),
    integer comparison (<code>-eq</code>, <code>-ne</code>, ...),
    and others (<code>-n</code>, <code>-z</code>, <code>-f</code>, ...).
    It is also possible to use regular expressions, </p>

    <example>
        &lt;If %{REQUEST_METHOD} IN GET,HEAD,OPTIONS&gt;
        &lt;If "%{QUERY_STRING =~ /(delete|commit)=.*?elem/"&gt;
    </example>

    <p>shell-like pattern matches and many other operations. These operations
    can be done on request headers (<code>req</code>), environment variables
    (<code>env</code>), and a large number of other properties. The full
    documentation is available in <a href="../expr.html">Expressions in
    Apache HTTP Server</a>.</p>

</usage>

<seealso><a href="../expr.html">Expressions in Apache HTTP Server</a>,
for a complete reference and more examples.</seealso>
<seealso><directive type="section" module="core">ElseIf</directive></seealso>
<seealso><directive type="section" module="core">Else</directive></seealso>
<seealso><a href="../sections.html">How &lt;Directory&gt;, &lt;Location&gt;,
    &lt;Files&gt; sections work</a> for an explanation of how these
    different sections are combined when a request is received.
    <directive type="section">If</directive> has the same precedence
    and usage as <directive type="section">Files</directive></seealso>
    <directive type="section">If</directive>,
    <directive type="section">ElseIf</directive>, and
    <directive type="section">Else</directive> are applied last.</seealso>
</directivesynopsis>

<directivesynopsis type="section">
+3 −1
Changes for include/ap_mmn.h: 3 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -326,12 +326,14 @@
 * 20110329.6 (2.3.13-dev) Add AP_EXPR_FLAGS_RESTRICTED, ap_expr_eval_ctx_t->data,
 *                         ap_expr_exec_ctx()
 * 20110604.0 (2.3.13-dev) Make ap_rputs() inline
 * 20110605.0 (2.3.13-dev) add core_dir_config->condition_ifelse, change return
 *                         type of ap_add_if_conf()
 */

#define MODULE_MAGIC_COOKIE 0x41503234UL /* "AP24" */

#ifndef MODULE_MAGIC_NUMBER_MAJOR
#define MODULE_MAGIC_NUMBER_MAJOR 20110604
#define MODULE_MAGIC_NUMBER_MAJOR 20110605
#endif
#define MODULE_MAGIC_NUMBER_MINOR 0                    /* 0...n */

+6 −1
Changes for include/http_core.h: 6 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -538,6 +538,11 @@ typedef struct {
                                             * pitched indiscriminately */
    unsigned int decode_encoded_slashes : 1; /* whether to decode encoded slashes in URLs */

#define AP_CONDITION_IF        1
#define AP_CONDITION_ELSE      2
#define AP_CONDITION_ELSEIF    (AP_CONDITION_ELSE|AP_CONDITION_IF)
    unsigned int condition_ifelse : 2; /* is this an <If>, <ElseIf>, or <Else> */

    ap_expr_info_t *condition;   /* Conditionally merge <If> sections */

    /** per-dir log config */
@@ -602,7 +607,7 @@ void ap_core_reorder_directories(apr_pool_t *, server_rec *);
AP_CORE_DECLARE(void) ap_add_per_dir_conf(server_rec *s, void *dir_config);
AP_CORE_DECLARE(void) ap_add_per_url_conf(server_rec *s, void *url_config);
AP_CORE_DECLARE(void) ap_add_file_conf(apr_pool_t *p, core_dir_config *conf, void *url_config);
AP_CORE_DECLARE(void) ap_add_if_conf(apr_pool_t *p, core_dir_config *conf, void *url_config);
AP_CORE_DECLARE(const char *) ap_add_if_conf(apr_pool_t *p, core_dir_config *conf, void *url_config);
AP_CORE_DECLARE_NONSTD(const char *) ap_limit_section(cmd_parms *cmd, void *dummy, const char *arg);

/* Core filters; not exported. */
Loading