This patch enables conditionally handling of the Header directive. For example...
SetEnvIf InHeader yadda HAVE_MyHeader
Header add NewHeader "yadda" env=HAVE_MyHeader
will cause
NewHeader: yadda
to be added to the response headers iff header
InHeader: yadda
appears in the request headers.
You can of course evaluate SetEnvIf based on ip addresses of the client, etc.
Bill
cvs diff -u mod_headers.c
Index: mod_headers.c
===================================================================
RCS file: /home/cvs/httpd-2.0/modules/metadata/mod_headers.c,v
retrieving revision 1.30
diff -u -r1.30 mod_headers.c
--- mod_headers.c 2001/06/04 10:43:50 1.30
+++ mod_headers.c 2001/06/04 19:32:53
@@ -153,6 +153,7 @@
char *header;
apr_array_header_t *ta; /* Array of format_tag structs */
regex_t *regex;
+ const char *condition_var;
} header_entry;
/* echo_do is used for Header echo to iterate through the request headers*/
@@ -338,7 +339,7 @@
/* handle RequestHeader and Header directive */
static const char *header_inout_cmd(hdr_inout inout, cmd_parms *cmd, void *indirconf,
const char *action, const char *inhdr,
- const char *value)
+ const char *value, const char* condition_var)
{
headers_conf *dirconf = indirconf;
char *hdr = apr_pstrdup(cmd->pool, inhdr);
@@ -393,16 +394,40 @@
*colon = '\0';
new->header = hdr;
+ new->condition_var = condition_var;
return parse_format_string(cmd->pool, new, value);
}
/* Handle Header directive */
static const char *header_cmd(cmd_parms *cmd, void *indirconf,
- const char *action, const char *inhdr,
- const char *value)
+ const char *args)
{
- return header_inout_cmd(hdr_out, cmd, indirconf, action, inhdr, value);
+ char *s;
+ const char *action;
+ const char *hdr;
+ const char *val;
+ const char *envclause;
+ const char *condition_var;
+
+ s = apr_pstrdup(cmd->pool, args);
+ action = ap_getword_conf(cmd->pool, &s);
+ hdr = ap_getword_conf(cmd->pool, &s);
+ val = *s ? ap_getword_conf(cmd->pool, &s) : NULL;
+ envclause = *s ? ap_getword_conf(cmd->pool, &s) : NULL;
+
+ if (envclause != NULL) {
+ if (strncasecmp(envclause, "env=", 4) != 0) {
+ return "error in condition clause";
+ }
+ if ((envclause[4] == '\0')
+ || ((envclause[4] == '!') && (envclause[5] == '\0'))) {
+ return "missing environment variable name";
+ }
+ condition_var = apr_pstrdup(cmd->pool, &envclause[4]);
+ }
+
+ return header_inout_cmd(hdr_out, cmd, indirconf, action, hdr, val, condition_var);
}
/* handle RequestHeader directive */
@@ -410,7 +435,7 @@
const char *action, const char *inhdr,
const char *value)
{
- return header_inout_cmd(hdr_in, cmd, indirconf, action, inhdr, value);
+ return header_inout_cmd(hdr_in, cmd, indirconf, action, inhdr, value, NULL);
}
/*
@@ -458,6 +483,20 @@
for (i = 0; i < fixup->nelts; ++i) {
header_entry *hdr = &((header_entry *) (fixup->elts))[i];
+
+ /* Have any conditional envar-controlled Header processing to do? */
+ if (hdr->condition_var) {
+ char *envar = hdr->condition_var;
+ if (*envar != '!') {
+ if (apr_table_get(r->subprocess_env, envar) == NULL)
+ continue;
+ }
+ else {
+ if (apr_table_get(r->subprocess_env, &envar[1]) != NULL)
+ continue;
+ }
+ }
+
switch (hdr->action) {
case hdr_add:
apr_table_addn(headers, hdr->header, process_tags(hdr, r));
@@ -536,8 +575,8 @@
static const command_rec headers_cmds[] =
{
- AP_INIT_TAKE23("Header", header_cmd, NULL, OR_FILEINFO,
- "an action, header and value"),
+ AP_INIT_RAW_ARGS("Header", header_cmd, NULL, OR_FILEINFO,
+ "an action, header and value followed by optional env clause"),
AP_INIT_TAKE23("RequestHeader", request_header_cmd, NULL, OR_FILEINFO,
"an action, header and value"),
{NULL}