summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsebastia <sebastia@openbsd.org>2010-09-26 12:11:32 +0000
committersebastia <sebastia@openbsd.org>2010-09-26 12:11:32 +0000
commit6b57d64888624751be79b8c7126fb7dcfe918db3 (patch)
tree262d2a8aa6945c26281375efbcd2a2de3b97db0a
parent- also explain what needs to be done after added MODGHC_BUILD=register (diff)
downloadwireguard-openbsd-6b57d64888624751be79b8c7126fb7dcfe918db3.tar.xz
wireguard-openbsd-6b57d64888624751be79b8c7126fb7dcfe918db3.zip
Allow mod_headers to handle RequestHeader directives known from apache2,
and update documentation accordingly. Patch mostly based on an old patch from Martin Algesten he posted 2002 in apache bugzilla entry: 10772 OK, pyr@
-rw-r--r--usr.sbin/httpd/htdocs/manual/mod/mod_headers.html28
-rw-r--r--usr.sbin/httpd/src/modules/standard/mod_headers.c48
2 files changed, 70 insertions, 6 deletions
diff --git a/usr.sbin/httpd/htdocs/manual/mod/mod_headers.html b/usr.sbin/httpd/htdocs/manual/mod/mod_headers.html
index c2984d99dab..663e3b8eea6 100644
--- a/usr.sbin/httpd/htdocs/manual/mod/mod_headers.html
+++ b/usr.sbin/httpd/htdocs/manual/mod/mod_headers.html
@@ -44,6 +44,7 @@
<ul>
<li><a href="#header">Header</a></li>
<li><a href="#errorheader">ErrorHeader</a></li>
+ <li><a href="#requestheader">RequestHeader</a></li>
</ul>
<hr />
@@ -164,6 +165,33 @@ Header unset Author
more information on the syntax.
</P>
+ <h2><a id="requestheader" name="requestheader">RequestHeader</a> directive</h2>
+ <a href="directive-dict.html#Syntax"
+ rel="Help"><strong>Syntax:</strong></a> RequestHeader set|append|add
+ <em>header</em> <em>value</em><br />
+ <a href="directive-dict.html#Syntax"
+ rel="Help"><strong>Syntax:</strong></a> RequestHeader unset
+ <em>header</em><br />
+ <a href="directive-dict.html#Context"
+ rel="Help"><strong>Context:</strong></a> server config, virtual
+ host, access.conf, .htaccess<br />
+ <a href="directive-dict.html#Override"
+ rel="Help"><strong>Override:</strong></a> FileInfo<br />
+ <a href="directive-dict.html#Status"
+ rel="Help"><strong>Status:</strong></a> Extension<br />
+ <a href="directive-dict.html#Module"
+ rel="Help"><strong>Module:</strong></a> mod_headers
+
+ <p>This directive can replace, merge or remove HTTP request
+ headers. As opposed to the <a href="#header">Header</a> directive,
+ this directive modifies incoming request headers instead of outgoing
+ responses.
+ </p>
+ <p>This directive is identical to the <a href="#header">Header</a>
+ directive in all other respects. Consult this directive for
+ more information on the syntax.
+ </P>
+
<p> <hr />
<h3 align="CENTER">Apache HTTP Server Version 1.3</h3>
diff --git a/usr.sbin/httpd/src/modules/standard/mod_headers.c b/usr.sbin/httpd/src/modules/standard/mod_headers.c
index 093e03ad065..ca2b5e7b1c3 100644
--- a/usr.sbin/httpd/src/modules/standard/mod_headers.c
+++ b/usr.sbin/httpd/src/modules/standard/mod_headers.c
@@ -59,13 +59,19 @@
/*
* mod_headers.c: Add/append/remove HTTP response headers
* Written by Paul Sutton, paul@ukweb.com, 1 Oct 1996
+ * Updated with RequestHeader by Martin Algesten,
+ * puckman@taglab.com, 13 Jul 2002.
*
* New directive, Header, can be used to add/replace/remove HTTP headers.
* Valid in both per-server and per-dir configurations.
+ * In addition directive, RequestHeader, can be used exactly as Header but
+ * with the difference that the header is added to the request headers rather
+ * than the response.
*
* Syntax is:
*
- * Header action header value
+ * Header action header value
+ * RequestHeader action header value
*
* Where action is one of:
* set - set this header, replacing any old value
@@ -77,7 +83,7 @@
* Where action is unset, the third argument (value) should not be given.
* The header name can include the colon, or not.
*
- * The Header directive can only be used where allowed by the FileInfo
+ * The directives can only be used where allowed by the FileInfo
* override.
*
* When the request is processed, the header directives are processed in
@@ -112,7 +118,15 @@ typedef enum {
hdr_unset = 'u' /* unset header */
} hdr_actions;
+
+typedef enum {
+ hdrs_in = 'i', /* Add header to incoming (request) headers */
+ hdrs_out = 'o' /* Add header to outgoing (response) headers */
+} hdrs_inout;
+
+
typedef struct {
+ hdrs_inout inout;
hdr_actions action;
char *header;
char *value;
@@ -154,7 +168,7 @@ static void *merge_headers_config(pool *p, void *basev, void *overridesv)
return a;
}
-static const char *header_cmd(cmd_parms *cmd, headers_conf * dirconf, char *action, char *hdr, char *value)
+static const char *header_cmd(cmd_parms *cmd, headers_conf * dirconf, char *action, char *hdr, char *value, hdrs_inout inout )
{
header_entry *new;
server_rec *s = cmd->server;
@@ -175,6 +189,8 @@ static const char *header_cmd(cmd_parms *cmd, headers_conf * dirconf, char *acti
new->do_err = 0;
}
+ new->inout = inout;
+
if (!strcasecmp(action, "set"))
new->action = hdr_set;
else if (!strcasecmp(action, "add"))
@@ -202,11 +218,23 @@ static const char *header_cmd(cmd_parms *cmd, headers_conf * dirconf, char *acti
return NULL;
}
+static const char *outheader_cmd(cmd_parms *cmd, headers_conf * dirconf, char *action, char *hdr, char *value)
+{
+ header_cmd( cmd, dirconf, action, hdr, value, hdrs_out );
+}
+
+static const char *inheader_cmd(cmd_parms *cmd, headers_conf * dirconf, char *action, char *hdr, char *value)
+{
+ header_cmd( cmd, dirconf, action, hdr, value, hdrs_in );
+}
+
static const command_rec headers_cmds[] =
{
- {"Header", header_cmd, (void *)0, OR_FILEINFO, TAKE23,
+ {"Header", outheader_cmd, NULL, OR_FILEINFO, TAKE23,
+ "an action, header and value"},
+ {"RequestHeader", inheader_cmd, NULL, OR_FILEINFO, TAKE23,
"an action, header and value"},
- {"ErrorHeader", header_cmd, (void *)1, OR_FILEINFO, TAKE23,
+ {"ErrorHeader", outheader_cmd, (void *)1, OR_FILEINFO, TAKE23,
"an action, header and value"},
{NULL}
};
@@ -217,7 +245,15 @@ static void do_headers_fixup(request_rec *r, array_header *headers)
for (i = 0; i < headers->nelts; ++i) {
header_entry *hdr = &((header_entry *) (headers->elts))[i];
- table *tbl = (hdr->do_err ? r->err_headers_out : r->headers_out);
+ table *tbl;
+ switch (hdr->inout) {
+ case hdrs_out:
+ tbl = (hdr->do_err ? r->err_headers_out : r->headers_out);
+ break;
+ case hdrs_in:
+ tbl = r->headers_in;
+ break;
+ }
switch (hdr->action) {
case hdr_add:
ap_table_addn(tbl, hdr->header, hdr->value);