You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by ji...@apache.org on 2013/11/09 15:37:24 UTC

svn commit: r1540313 - in /httpd/httpd/branches/2.4.x: CHANGES STATUS docs/manual/mod/mod_headers.xml modules/metadata/mod_headers.c

Author: jim
Date: Sat Nov  9 14:37:23 2013
New Revision: 1540313

URL: http://svn.apache.org/r1540313
Log:
  * mod_headers: Allow for format specifiers to be used in the base
      substitution string when using Header edit
          trunk patch: http://people.apache.org/~druggeri/patches/HeaderEditENV.trunk.patch
              2.4.x patch: http://people.apache.org/~druggeri/patches/HeaderEditENV.2.4.patch
                  +1: druggeri, covener, jim


Modified:
    httpd/httpd/branches/2.4.x/CHANGES
    httpd/httpd/branches/2.4.x/STATUS
    httpd/httpd/branches/2.4.x/docs/manual/mod/mod_headers.xml
    httpd/httpd/branches/2.4.x/modules/metadata/mod_headers.c

Modified: httpd/httpd/branches/2.4.x/CHANGES
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/CHANGES?rev=1540313&r1=1540312&r2=1540313&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/CHANGES [utf-8] (original)
+++ httpd/httpd/branches/2.4.x/CHANGES [utf-8] Sat Nov  9 14:37:23 2013
@@ -12,6 +12,9 @@ Changes with Apache 2.4.7
      SessionHeader directive, remove the value from the response. PR 55279.
      [Graham Leggett]
 
+  *) mod_headers: Allow for format specifiers in the substitution string
+     when using Header edit. [Daniel Ruggeri]
+
   *) mod_dav: dav_resource->uri is treated as unencoded. This was an
      unnecessary ABI changed introduced in 2.4.6. PR 55397.
 

Modified: httpd/httpd/branches/2.4.x/STATUS
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/STATUS?rev=1540313&r1=1540312&r2=1540313&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/STATUS (original)
+++ httpd/httpd/branches/2.4.x/STATUS Sat Nov  9 14:37:23 2013
@@ -97,12 +97,6 @@ RELEASE SHOWSTOPPERS:
 PATCHES ACCEPTED TO BACKPORT FROM TRUNK:
   [ start all new proposals below, under PATCHES PROPOSED. ]
 
-  * mod_headers: Allow for format specifiers to be used in the base
-    substitution string when using Header edit
-    trunk patch: http://people.apache.org/~druggeri/patches/HeaderEditENV.trunk.patch
-    2.4.x patch: http://people.apache.org/~druggeri/patches/HeaderEditENV.2.4.patch
-    +1: druggeri, covener, jim
-
 
 
 PATCHES PROPOSED TO BACKPORT FROM TRUNK:

Modified: httpd/httpd/branches/2.4.x/docs/manual/mod/mod_headers.xml
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/docs/manual/mod/mod_headers.xml?rev=1540313&r1=1540312&r2=1540313&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/docs/manual/mod/mod_headers.xml (original)
+++ httpd/httpd/branches/2.4.x/docs/manual/mod/mod_headers.xml Sat Nov  9 14:37:23 2013
@@ -229,7 +229,7 @@ Header merge Cache-Control no-store env=
     to a <glossary ref="regex">regular expression</glossary>
     search-and-replace.  The <var>value</var> argument is a <glossary
     ref="regex">regular expression</glossary>, and the <var>replacement</var>
-    is a replacement string, which may contain backreferences.
+    is a replacement string, which may contain backreferences or format specifiers.
     The <code>edit</code> form will match and replace exactly once
     in a header value, whereas the <code>edit*</code> form will replace
     <em>every</em> instance of the search pattern if it appears more
@@ -372,7 +372,7 @@ Header merge Cache-Control no-store env=
     to a <glossary ref="regex">regular expression</glossary>
     search-and-replace.  The <var>value</var> argument is a <glossary
     ref="regex">regular expression</glossary>, and the <var>replacement</var>
-    is a replacement string, which may contain backreferences.
+    is a replacement string, which may contain backreferences or format specifiers.
     The <code>edit</code> form will match and replace exactly once
     in a header value, whereas the <code>edit*</code> form will replace
     <em>every</em> instance of the search pattern if it appears more
@@ -481,7 +481,8 @@ Header merge Cache-Control no-store env=
 
     <p>For <code>edit</code> there is both a <var>value</var> argument
     which is a <glossary ref="regex">regular expression</glossary>,
-    and an additional <var>replacement</var> string.</p>
+    and an additional <var>replacement</var> string.</p> As of version 2.4.7
+    the replacement string may also contain format specifiers.
 
     <p>The <directive>Header</directive> directive may be followed by
     an additional argument, which may be any of:</p>

Modified: httpd/httpd/branches/2.4.x/modules/metadata/mod_headers.c
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/modules/metadata/mod_headers.c?rev=1540313&r1=1540312&r2=1540313&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/modules/metadata/mod_headers.c (original)
+++ httpd/httpd/branches/2.4.x/modules/metadata/mod_headers.c Sat Nov  9 14:37:23 2013
@@ -143,7 +143,7 @@ typedef struct {
 
 /* edit_do is used for Header edit to iterate through the request headers */
 typedef struct {
-    apr_pool_t *p;
+    request_rec *r;
     header_entry *hdr;
     apr_table_t *t;
 } edit_do;
@@ -392,12 +392,13 @@ static char *parse_format_string(apr_poo
     char *res;
 
     /* 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) {
+    if (hdr->action == hdr_unset || hdr->action == hdr_echo) {
         return NULL;
     }
+    /* Tags are in the replacement value for edit */
+    else if (hdr->action == hdr_edit || hdr->action == hdr_edit_r ) {
+        s = hdr->subs;
+    }
 
     hdr->ta = apr_array_make(p, 10, sizeof(format_tag));
 
@@ -602,7 +603,7 @@ static char* process_tags(header_entry *
     return str ? str : "";
 }
 static const char *process_regexp(header_entry *hdr, const char *value,
-                                  apr_pool_t *pool)
+                                  request_rec *r)
 {
     ap_regmatch_t pmatch[AP_MAX_REG_MATCH];
     const char *subs;
@@ -613,7 +614,10 @@ static const char *process_regexp(header
         /* no match, nothing to do */
         return value;
     }
-    subs = ap_pregsub(pool, hdr->subs, value, AP_MAX_REG_MATCH, pmatch);
+    /* Process tags in the input string rather than the resulting
+       * substitution to avoid surprises
+       */
+    subs = ap_pregsub(r->pool, process_tags(hdr, r), value, AP_MAX_REG_MATCH, pmatch);
     if (subs == NULL)
         return NULL;
     diffsz = strlen(subs) - (pmatch[0].rm_eo - pmatch[0].rm_so);
@@ -621,12 +625,12 @@ static const char *process_regexp(header
         remainder = value + pmatch[0].rm_eo;
     }
     else { /* recurse to edit multiple matches if applicable */
-        remainder = process_regexp(hdr, value + pmatch[0].rm_eo, pool);
+        remainder = process_regexp(hdr, value + pmatch[0].rm_eo, r);
         if (remainder == NULL)
             return NULL;
         diffsz += strlen(remainder) - strlen(value + pmatch[0].rm_eo);
     }
-    ret = apr_palloc(pool, strlen(value) + 1 + diffsz);
+    ret = apr_palloc(r->pool, strlen(value) + 1 + diffsz);
     memcpy(ret, value, pmatch[0].rm_so);
     strcpy(ret + pmatch[0].rm_so, subs);
     strcat(ret, remainder);
@@ -648,7 +652,7 @@ static int echo_header(echo_do *v, const
 static int edit_header(void *v, const char *key, const char *val)
 {
     edit_do *ed = (edit_do *)v;
-    const char *repl = process_regexp(ed->hdr, val, ed->p);
+    const char *repl = process_regexp(ed->hdr, val, ed->r);
     if (repl == NULL)
         return 0;
 
@@ -781,7 +785,7 @@ static int do_headers_fixup(request_rec 
         case hdr_edit:
         case hdr_edit_r:
             if (!strcasecmp(hdr->header, "Content-Type") && r->content_type) {
-                const char *repl = process_regexp(hdr, r->content_type, r->pool);
+                const char *repl = process_regexp(hdr, r->content_type, r);
                 if (repl == NULL)
                     return 0;
                 ap_set_content_type(r, repl);
@@ -789,7 +793,7 @@ static int do_headers_fixup(request_rec 
             if (apr_table_get(headers, hdr->header)) {
                 edit_do ed;
 
-                ed.p = r->pool;
+                ed.r = r;
                 ed.hdr = hdr;
                 ed.t = apr_table_make(r->pool, 5);
                 if (!apr_table_do(edit_header, (void *) &ed, headers,