Again, as I was pointed out the patch was borked, and actually documentation missing, here is a new one, including the documentation.
Sebastian On Monday, September 13, 2010 18:26 CEST, Sebastian Reitenbach <sebas...@l00-bugdead-prods.de> wrote: > Hi, > > attached a new revision of the patch. Please comment, and let me know > whether its OK to add or still sth. wrong. > > thanks, > Sebastian > > Alexander Hall wrote: > > On 09/12/10 18:20, Sebastian Reitenbach wrote: > > > >> - table *tbl = (hdr->do_err ? r->err_headers_out : r->headers_out); > >> + table *tbl; > >> + switch (hdr->inout) { > >> + case hdrs_out: > >> + tbl = r->headers_out; > >> + break; > >> + case hdrs_in: > >> + tbl = r->headers_in; > >> + break; > >> + } > >> + tbl = (hdr->do_err ? r->err_headers_out : r->headers_out); > > > > Err... Set tbl above and then set it again? > > > > Also, what's with the indentation? > > > >> switch (hdr->action) { > >> case hdr_add: > >> ap_table_addn(tbl, hdr->header, hdr->value); > >> > > Index: src/modules/standard/mod_headers.c =================================================================== RCS file: /cvs/src/usr.sbin/httpd/src/modules/standard/mod_headers.c,v retrieving revision 1.8 diff -u -r1.8 mod_headers.c --- src/modules/standard/mod_headers.c 21 Aug 2003 13:11:36 -0000 1.8 +++ src/modules/standard/mod_headers.c 13 Sep 2010 17:45:35 -0000 @@ -59,13 +59,19 @@ /* * mod_headers.c: Add/append/remove HTTP response headers * Written by Paul Sutton, p...@ukweb.com, 1 Oct 1996 + * Updated with RequestHeader by Martin Algesten, + * puck...@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 @@ 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 @@ 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 @@ new->do_err = 0; } + new->inout = inout; + if (!strcasecmp(action, "set")) new->action = hdr_set; else if (!strcasecmp(action, "add")) @@ -202,11 +218,23 @@ 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 @@ 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); Index: htdocs/manual/mod/mod_headers.html =================================================================== RCS file: /cvs/src/usr.sbin/httpd/htdocs/manual/mod/mod_headers.html,v retrieving revision 1.6 diff -u -r1.6 mod_headers.html --- htdocs/manual/mod/mod_headers.html 7 Oct 2002 21:04:44 -0000 1.6 +++ htdocs/manual/mod/mod_headers.html 13 Sep 2010 17:45:35 -0000 @@ -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 /> @@ -158,6 +159,33 @@ <p>This directive can replace, merge or remove HTTP response headers during 3xx, 4xx and 5xx replies. For normal replies use the Header directive. + </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> + + <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