Hi,

my first time I submit a patch which not goes to the ports.

I have a web based groupware port in the queue, that would benefit from the patch below. The patch is against mod_headers.c and adds handling of RequestHeader directive in the apache configuration, in order to manipulate the request header instead of the header.

The patch is based one the one I found here:
http://mail-archives.apache.org/mod_mbox/httpd-bugs/200207.mbox/%3c20020713122353.23227.qm...@nagoya.betaversion.org%3e
There are only some style changes, and at the end some small tweaks, since the original patch was against a mod_headers.c file unaware of ErrorHeader.

Without this patch, it would be necessary to use apache2 from ports.
Patch tested to compile and works for me as expected on i386.

Is this sth. that can go in, needs some tweaks, more testing, or is a stupid idea? Any comment welcome.


cheers,
Sebastian

? mod_headers.c.save
Index: 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
--- mod_headers.c       21 Aug 2003 13:11:36 -0000      1.8
+++ mod_headers.c       12 Sep 2010 15:36:01 -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,9 +218,21 @@
     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,
      "an action, header and value"},
@@ -217,7 +245,16 @@

     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 = r->headers_out;
+         break;
+       case hdrs_in:
+         tbl = r->headers_in;
+         break;
+       }
+       tbl = (hdr->do_err ? r->err_headers_out : r->headers_out);
         switch (hdr->action) {
         case hdr_add:
             ap_table_addn(tbl, hdr->header, hdr->value);

Reply via email to