summaryrefslogtreecommitdiffstats
path: root/modules/metadata/mod_headers.c
diff options
context:
space:
mode:
authorEric Covener <covener@apache.org>2013-06-25 04:20:36 +0200
committerEric Covener <covener@apache.org>2013-06-25 04:20:36 +0200
commit1c3427493eb6f89fe8e7924f714e6a6f91bf1d47 (patch)
treee1172ddb6327bf617748c5c78d1328088a6744f1 /modules/metadata/mod_headers.c
parentUse cp on AIX too. /usr/bin/install isn't compatible on recent systems (diff)
downloadapache2-1c3427493eb6f89fe8e7924f714e6a6f91bf1d47.tar.xz
apache2-1c3427493eb6f89fe8e7924f714e6a6f91bf1d47.zip
provide a simple (no <If>) way to set a header only if it's not already there.
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1496338 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'modules/metadata/mod_headers.c')
-rw-r--r--modules/metadata/mod_headers.c15
1 files changed, 13 insertions, 2 deletions
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;