summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGES3
-rw-r--r--docs/manual/mod/mod_headers.xml8
-rw-r--r--modules/metadata/mod_headers.c15
3 files changed, 24 insertions, 2 deletions
diff --git a/CHANGES b/CHANGES
index bff69119d1..6016a7bb14 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,9 @@
-*- coding: utf-8 -*-
Changes with Apache 2.5.0
+ *) mod_headers: Add 'setifempty' command to Header and RequestHeader.
+ [Eric Covener]
+
*) AIX: Install DSO's with "cp" instead of "install" in instdso.sh
[Eric Covener]
diff --git a/docs/manual/mod/mod_headers.xml b/docs/manual/mod/mod_headers.xml
index 528e7f2d0d..774cadc4f6 100644
--- a/docs/manual/mod/mod_headers.xml
+++ b/docs/manual/mod/mod_headers.xml
@@ -248,6 +248,10 @@ Header merge Cache-Control no-store env=NO_STORE
<dt><code>set</code></dt>
<dd>The request header is set, replacing any previous header
with this name</dd>
+
+ <dt><code>setifempty</code></dt>
+ <dd>The request header is set, but only if there is no previous header
+ with this name</dd>
<dt><code>unset</code></dt>
<dd>The request header of this name is removed, if it exists. If
@@ -388,6 +392,10 @@ Header merge Cache-Control no-store env=NO_STORE
<dd>The response header is set, replacing any previous header
with this name. The <var>value</var> may be a format string.</dd>
+ <dt><code>setifempty</code></dt>
+ <dd>The request header is set, but only if there is no previous header
+ with this name</dd>
+
<dt><code>unset</code></dt>
<dd>The response header of this name is removed, if it exists.
If there are multiple headers of the same name, all will be
diff --git a/modules/metadata/mod_headers.c b/modules/metadata/mod_headers.c
index 9ce2fdec67..6c03e71839 100644
--- a/modules/metadata/mod_headers.c
+++ b/modules/metadata/mod_headers.c
@@ -96,7 +96,8 @@ typedef enum {
hdr_unset = 'u', /* unset header */
hdr_echo = 'e', /* echo headers from request to response */
hdr_edit = 'r', /* change value by regexp, match once */
- hdr_edit_r = 'R' /* change value by regexp, everymatch */
+ hdr_edit_r = 'R', /* change value by regexp, everymatch */
+ hdr_setifempty = 'i' /* set value if header not already present*/
} hdr_actions;
/*
@@ -431,6 +432,8 @@ static APR_INLINE const char *header_inout_cmd(cmd_parms *cmd,
if (!strcasecmp(action, "set"))
new->action = hdr_set;
+ else if (!strcasecmp(action, "setifempty"))
+ new->action = hdr_setifempty;
else if (!strcasecmp(action, "add"))
new->action = hdr_add;
else if (!strcasecmp(action, "append"))
@@ -446,7 +449,7 @@ static APR_INLINE const char *header_inout_cmd(cmd_parms *cmd,
else if (!strcasecmp(action, "edit*"))
new->action = hdr_edit_r;
else
- return "first argument must be 'add', 'set', 'append', 'merge', "
+ return "first argument must be 'add', 'set', 'setifempty', 'append', 'merge', "
"'unset', 'echo', 'edit', or 'edit*'.";
if (new->action == hdr_edit || new->action == hdr_edit_r) {
@@ -755,6 +758,14 @@ static int do_headers_fixup(request_rec *r, apr_table_t *headers,
}
apr_table_setn(headers, hdr->header, process_tags(hdr, r));
break;
+ case hdr_setifempty:
+ if (NULL == apr_table_get(headers, hdr->header)) {
+ if (!strcasecmp(hdr->header, "Content-Type")) {
+ ap_set_content_type(r, process_tags(hdr, r));
+ }
+ apr_table_setn(headers, hdr->header, process_tags(hdr, r));
+ }
+ break;
case hdr_unset:
apr_table_unset(headers, hdr->header);
break;