From: Jim Jagielski Date: Thu, 17 Apr 2008 14:09:29 +0000 (+0000) Subject: Merge r627764, r628864 from trunk: X-Git-Tag: 2.2.9~241 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1a5fd967cfe9f51b4607932feeebf2a404b6133c;p=thirdparty%2Fapache%2Fhttpd.git Merge r627764, r628864 from trunk: Change default of mod_substitute to flattening... Via current discussion on dev@httpd In the case where we have only 1 pattern, then we can safely be quick, no matter what. Reviewed by: jim git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.2.x@649118 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index 2963c47bb57..7526a1a3935 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,11 @@ -*- coding: utf-8 -*- Changes with Apache 2.2.9 + *) mod_substitute: The default is now flattening the buckets after + each substitution. The newly added 'q' flag allows for the + quicker, more efficient bucket-splitting if the user so + desires. [Jim Jagielski] + *) http_filters: Don't spin if get an error when reading the next chunk. PR 44381 [Ruediger Pluem] diff --git a/STATUS b/STATUS index 2d4affcf8d2..9a71521944f 100644 --- a/STATUS +++ b/STATUS @@ -88,15 +88,6 @@ RELEASE SHOWSTOPPERS: PATCHES ACCEPTED TO BACKPORT FROM TRUNK: [ start all new proposals below, under PATCHES PROPOSED. ] - * mod_substitute: Make default behavior flattening of buckets. Allow - for people to specifically set "quick" mode. - Trunk version of patch: - http://svn.apache.org/viewvc?view=rev&revision=627764 - http://svn.apache.org/viewvc?view=rev&revision=628864 - Backport version for 2.2.x of patch: - Trunk version works (minus CHANGES conflict) - +1: jim, covener, wrowe - * mod_speling: remove regression from 1.3/2.0 behavior and drop dependency between mod_speling and AcceptPathInfo. PR: 43562 diff --git a/docs/manual/mod/mod_substitute.xml b/docs/manual/mod/mod_substitute.xml index ce5f455a331..d4ffa5312d3 100644 --- a/docs/manual/mod/mod_substitute.xml +++ b/docs/manual/mod/mod_substitute.xml @@ -37,7 +37,7 @@ Substitute Pattern to filter the response content -Substitute s/pattern/substitution/[inf] +Substitute s/pattern/substitution/[infq] directory .htaccess FileInfo @@ -59,7 +59,14 @@
f
The f flag causes mod_substitute to flatten the result of a substitution allowing for later substitutions to - take place on the boundary of this one.
+ take place on the boundary of this one. This is the default. +
q
+
The q flag causes mod_substitute to not + flatten the buckets after each substitution. This can + result in much faster response and a decrease in memory + utilization, but should only be used if there is no possibility + that the result of one substitution will ever match a pattern + or regex of a subsequent one.
Example diff --git a/modules/filters/mod_substitute.c b/modules/filters/mod_substitute.c index 592d1404911..ebe860d66bf 100644 --- a/modules/filters/mod_substitute.c +++ b/modules/filters/mod_substitute.c @@ -103,6 +103,7 @@ static void do_pattmatch(ap_filter_t *f, apr_bucket *inb, apr_pool_t *tmp_pool) { int i; + int force_quick = 0; ap_regmatch_t regm[AP_MAX_REG_MATCH]; apr_size_t bytes; apr_size_t len; @@ -128,6 +129,13 @@ static void do_pattmatch(ap_filter_t *f, apr_bucket *inb, apr_pool_create(&tpool, tmp_pool); scratch = NULL; fbytes = 0; + /* + * Simple optimization. If we only have one pattern, then + * we can safely avoid the overhead of flattening + */ + if (cfg->patterns->nelts == 1) { + force_quick = 1; + } for (i = 0; i < cfg->patterns->nelts; i++) { for (b = APR_BRIGADE_FIRST(mybb); b != APR_BRIGADE_SENTINEL(mybb); @@ -147,7 +155,7 @@ static void do_pattmatch(ap_filter_t *f, apr_bucket *inb, { /* get offset into buff for pattern */ len = (apr_size_t) (repl - buff); - if (script->flatten) { + if (script->flatten && !force_quick) { /* * We are flattening the buckets here, meaning * that we don't do the fast bucket splits. @@ -181,7 +189,7 @@ static void do_pattmatch(ap_filter_t *f, apr_bucket *inb, bytes -= len; buff += len; } - if (script->flatten && s1) { + if (script->flatten && s1 && !force_quick) { /* * we've finished looking at the bucket, so remove the * old one and add in our new one @@ -219,7 +227,7 @@ static void do_pattmatch(ap_filter_t *f, apr_bucket *inb, /* first, grab the replacement string */ repl = ap_pregsub(tmp_pool, script->replacement, p, AP_MAX_REG_MATCH, regm); - if (script->flatten) { + if (script->flatten && !force_quick) { SEDSCAT(s1, s2, tmp_pool, p, regm[0].rm_so, repl); } else { @@ -236,7 +244,7 @@ static void do_pattmatch(ap_filter_t *f, apr_bucket *inb, */ p += regm[0].rm_eo; } - if (script->flatten && s1) { + if (script->flatten && s1 && !force_quick) { s1 = apr_pstrcat(tmp_pool, s1, p, NULL); tmp_b = apr_bucket_transient_create(s1, strlen(s1), f->r->connection->bucket_alloc); @@ -488,7 +496,7 @@ static const char *set_pattern(cmd_parms *cmd, void *cfg, const char *line) subst_pattern_t *nscript; int is_pattern = 0; int ignore_case = 0; - int flatten = 0; + int flatten = 1; ap_regex_t *r = NULL; if (apr_tolower(*line) != 's') { @@ -525,8 +533,10 @@ static const char *set_pattern(cmd_parms *cmd, void *cfg, const char *line) is_pattern = 1; else if (delim == 'f') flatten = 1; + else if (delim == 'q') + flatten = 0; else - return "Bad Substitute flag, only s///[inf] are supported"; + return "Bad Substitute flag, only s///[infq] are supported"; flags++; }