httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From drugg...@apache.org
Subject svn commit: r1535788 - in /httpd/httpd/trunk: docs/manual/mod/mod_headers.xml modules/metadata/mod_headers.c
Date Fri, 25 Oct 2013 17:16:46 GMT
Author: druggeri
Date: Fri Oct 25 17:16:46 2013
New Revision: 1535788

URL: http://svn.apache.org/r1535788
Log:
Allow for format specifiers to be used in the base substitution string for Header edit

Modified:
    httpd/httpd/trunk/docs/manual/mod/mod_headers.xml
    httpd/httpd/trunk/modules/metadata/mod_headers.c

Modified: httpd/httpd/trunk/docs/manual/mod/mod_headers.xml
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/manual/mod/mod_headers.xml?rev=1535788&r1=1535787&r2=1535788&view=diff
==============================================================================
--- httpd/httpd/trunk/docs/manual/mod/mod_headers.xml (original)
+++ httpd/httpd/trunk/docs/manual/mod/mod_headers.xml Fri Oct 25 17:16:46 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> 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/trunk/modules/metadata/mod_headers.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/metadata/mod_headers.c?rev=1535788&r1=1535787&r2=1535788&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/metadata/mod_headers.c (original)
+++ httpd/httpd/trunk/modules/metadata/mod_headers.c Fri Oct 25 17:16:46 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,



Mime
View raw message