Cache-Control: no-cache, no-cache, no-store
</example>
</li>
+ <li>
+ Set a test cookie if and only if the client didn't send us a cookie
+ <example>
+ Header set Set-Cookie testcookie !$req{Cookie}
+ </example>
+ </li>
</ol>
</section>
replacement string respectively.</p>
<p>The <directive>RequestHeader</directive> directive may be followed by
- an additional argument, which may be used to specify conditions under
- which the action will be taken, or may be the keyword <code>early</code>
- to specify <a href="#early">early processing</a>. If the
- <a href="../env.html">environment
- variable</a> specified in the <code>env=<var>...</var></code> argument
- exists (or if the environment variable does not exist and
- <code>env=!<var>...</var></code> is specified) then the action specified
- by the <directive>RequestHeader</directive> directive will take effect.
- Otherwise, the directive will have no effect on the request.</p>
+ an additional argument, which may be any of:</p>
+ <dl>
+ <dt><code>early</code></dt>
+ <dd>Specifies <a href="#early">early processing</a>.</dd>
+ <dt><code>env=[!]varname</code></dt>
+ <dd>The directive is applied if and only if the <a href="../env.html"
+ >environment variable</a> <code>varname</code> exists.
+ A <code>!</code> in front of <code>varname</code> reverses the test,
+ so the directive applies only if <code>varname</code> is unset.</dd>
+ <dt><code>expr</code></dt>
+ <dd>An string that matches neither of the above is parsed as an
+ expression. Details of expression syntax and evaluation are
+ currently best documented on the <module>mod_filter</module> page.</dd>
+ </dl>
<p>Except in <a href="#early">early</a> mode, the
<directive>RequestHeader</directive> directive is processed
which is a <glossary ref="regex">regular expression</glossary>,
and an additional <var>replacement</var> string.</p>
- <p>The <directive>Header</directive> directive may be followed by an
- an additional argument, which may be used to specify conditions under
- which the action will be taken, or may be the keyword <code>early</code>
- to specify <a href="#early">early processing</a>. If the
- <a href="../env.html">environment variable</a> specified in the
- <code>env=<var>...</var></code> argument exists (or if the environment
- variable does not exist and <code>env=!<var>...</var></code> is specified)
- then the action specified by the <directive>Header</directive> directive
- will take effect. Otherwise, the directive will have no effect
- on the request.</p>
+ <p>The <directive>Header</directive> directive may be followed by
+ an additional argument, which may be any of:</p>
+ <dl>
+ <dt><code>early</code></dt>
+ <dd>Specifies <a href="#early">early processing</a>.</dd>
+ <dt><code>env=[!]varname</code></dt>
+ <dd>The directive is applied if and only if the <a href="../env.html"
+ >environment variable</a> <code>varname</code> exists.
+ A <code>!</code> in front of <code>varname</code> reverses the test,
+ so the directive applies only if <code>varname</code> is unset.</dd>
+ <dt><code>expr</code></dt>
+ <dd>An string that matches neither of the above is parsed as an
+ expression. Details of expression syntax and evaluation are
+ currently best documented on the <module>mod_filter</module> page.</dd>
+ </dl>
<p>Except in <a href="#early">early</a> mode, the
<directive>Header</directive> directives are processed just
#include "http_log.h"
#include "util_filter.h"
#include "http_protocol.h"
+#include "ap_expr.h"
#include "mod_ssl.h" /* for the ssl_var_lookup optional function defn */
ap_regex_t *regex;
const char *condition_var;
const char *subs;
+ ap_parse_node_t *expr;
} header_entry;
/* echo_do is used for Header echo to iterate through the request headers*/
const char *condition_var = NULL;
const char *colon;
header_entry *new;
+ ap_parse_node_t *expr = NULL;
apr_array_header_t *fixup = (cmd->info == &hdr_in)
? dirconf->fixup_in : (cmd->info == &hdr_err)
if (strcasecmp(envclause, "early") == 0) {
condition_var = condition_early;
}
- else {
- if (strncasecmp(envclause, "env=", 4) != 0) {
- return "error: envclause should be in the form env=envar";
- }
+ else if (strncasecmp(envclause, "env=", 4) == 0) {
if ((envclause[4] == '\0')
|| ((envclause[4] == '!') && (envclause[5] == '\0'))) {
return "error: missing environment variable name. "
}
condition_var = envclause + 4;
}
+ else {
+ int err = 0;
+ expr = ap_expr_parse(cmd->pool, envclause, &err);
+ if (err) {
+ return "Can't parse envclause/expression";
+ }
+ }
}
if ((colon = ap_strchr_c(hdr, ':'))) {
new->header = hdr;
new->condition_var = condition_var;
+ new->expr = expr;
return parse_format_string(cmd->pool, new, value);
}
else if (early && (envar != condition_early)) {
continue;
}
+ /* Do we have an expression to evaluate? */
+ else if (hdr->expr != NULL) {
+ int err = 0;
+ int eval = ap_expr_eval(r, hdr->expr, &err, NULL,
+ ap_expr_string, NULL);
+ if (err) {
+ ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
+ "Failed to evaluate expression - ignoring");
+ }
+ else if (!eval) {
+ continue;
+ }
+ }
/* Have any conditional envar-controlled Header processing to do? */
else if (envar && !early) {
if (*envar != '!') {