]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
Yet another backport proposal
authorNick Kew <niq@apache.org>
Mon, 5 Jul 2010 19:51:56 +0000 (19:51 +0000)
committerNick Kew <niq@apache.org>
Mon, 5 Jul 2010 19:51:56 +0000 (19:51 +0000)
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.2.x@960674 13f79535-47bb-0310-9956-ffa450edef68

STATUS
modules/metadata/mod_headers.c

diff --git a/STATUS b/STATUS
index 17a8b8cdc682588a64a1ae821ce5286394d9f808..41695738c454cfd3d992e611c8e5c40f6b03d39e 100644 (file)
--- a/STATUS
+++ b/STATUS
@@ -248,6 +248,12 @@ PATCHES PROPOSED TO BACKPORT FROM TRUNK:
      http://svn.apache.org/viewvc?view=revision&revision=894041
      +1: niq
 
+  *) mod_headers: support global replace in Header Edit
+     PR 46594 (not 47066 as incorrectly recorded in change log)
+     trunk: http://svn.eu.apache.org/viewvc?view=revision&revision=894036
+     2.2.x: http://people.apache.org/~niq/patches/46594.patch
+     +1: niq
+
 PATCHES/ISSUES THAT ARE STALLED
 
   * core: Support wildcards in both the directory and file components of
index b65fbfd07716c07aca038b1f195db5199b0bef0f..4836cd0e4e79f60a791f62ace8b346de5e2182b4 100644 (file)
@@ -94,7 +94,8 @@ typedef enum {
     hdr_merge = 'g',            /* merge (merge, but avoid duplicates) */
     hdr_unset = 'u',            /* unset header */
     hdr_echo = 'e',             /* echo headers from request to response */
-    hdr_edit = 'r'              /* change value by regexp */
+    hdr_edit = 'r',             /* change value by regexp, match once */
+    hdr_edit_r = 'R'            /* change value by regexp, everymatch */
 } hdr_actions;
 
 /*
@@ -364,6 +365,7 @@ static char *parse_format_string(apr_pool_t *p, header_entry *hdr, const char *s
     /* No string to parse with unset and echo commands */
     if (hdr->action == hdr_unset ||
         hdr->action == hdr_edit ||
+        hdr->action == hdr_edit_r ||
         hdr->action == hdr_echo) {
         return NULL;
     }
@@ -413,11 +415,13 @@ static APR_INLINE const char *header_inout_cmd(cmd_parms *cmd,
         new->action = hdr_echo;
     else if (!strcasecmp(action, "edit"))
         new->action = hdr_edit;
+    else if (!strcasecmp(action, "edit*"))
+        new->action = hdr_edit_r;
     else
         return "first argument must be 'add', 'set', 'append', 'merge', "
-               "'unset', 'echo', or 'edit'.";
+               "'unset', 'echo', 'edit', or 'edit*'.";
 
-    if (new->action == hdr_edit) {
+    if (new->action == hdr_edit || new->action == hdr_edit_r) {
         if (subs == NULL) {
             return "Header edit requires a match and a substitution";
         }
@@ -558,6 +562,7 @@ static const char *process_regexp(header_entry *hdr, const char *value,
     unsigned int nmatch = 10;
     ap_regmatch_t pmatch[10];
     const char *subs;
+    const char *remainder;
     char *ret;
     int diffsz;
     if (ap_regexec(hdr->regex, value, nmatch, pmatch, 0)) {
@@ -566,6 +571,13 @@ static const char *process_regexp(header_entry *hdr, const char *value,
     }
     subs = ap_pregsub(pool, hdr->subs, value, nmatch, pmatch);
     diffsz = strlen(subs) - (pmatch[0].rm_eo - pmatch[0].rm_so);
+    if (hdr->action == hdr_edit) {
+        remainder = value + pmatch[0].rm_eo;
+    }
+    else { /* recurse to edit multiple matches if applicable */
+        remainder = process_regexp(hdr, value + pmatch[0].rm_eo, pool);
+        diffsz += strlen(remainder) - strlen(value + pmatch[0].rm_eo);
+    }
     ret = apr_palloc(pool, strlen(value) + 1 + diffsz);
     memcpy(ret, value, pmatch[0].rm_so);
     strcpy(ret + pmatch[0].rm_so, subs);
@@ -695,6 +707,7 @@ static void do_headers_fixup(request_rec *r, apr_table_t *headers,
                          echo_header, (void *) &v, r->headers_in, NULL);
             break;
         case hdr_edit:
+        case hdr_edit_r:
             if (apr_table_get(headers, hdr->header)) {
                 edit_do ed;