]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
mod_substitute: Allow to configure the patterns merge order with the new
authorWilliam A. Rowe Jr <wrowe@apache.org>
Thu, 30 Jun 2016 16:59:58 +0000 (16:59 +0000)
committerWilliam A. Rowe Jr <wrowe@apache.org>
Thu, 30 Jun 2016 16:59:58 +0000 (16:59 +0000)
SubstituteInheritBefore on|off directive (with default in 2.2 of 'off)

Backports: r1684900, r1687539, r1687680, r1688331, r1688339, r1688340, r1688343,
           r1697013, r1697015
PR: 57641
Submitted by:
     [Marc.Stern <Marc.Stern approach.be>, Yann Ylavic, William Rowe]

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.2.x@1750835 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
STATUS
docs/manual/mod/mod_substitute.xml
modules/filters/mod_substitute.c

diff --git a/CHANGES b/CHANGES
index 201260085fb639ba06596a7586de7546ddf8c3f4..8e4f62b1a24c2731c354f3b81f34d019aef6a455 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,10 @@
                                                          -*- coding: utf-8 -*-
 Changes with Apache 2.2.32
 
+  *) mod_substitute: Allow to configure the patterns merge order with the new
+     SubstituteInheritBefore on|off directive.  PR 57641
+     [Marc.Stern <Marc.Stern approach.be>, Yann Ylavic, William Rowe]
+
   *) abs: Include OPENSSL_Applink when compiling on Windows, to resolve
      failures under Visual Studio 2015 and other mismatched MSVCRT flavors.
      PR59630 [Jan Ehrhardt <phpdev ehrhardt.nl>]
diff --git a/STATUS b/STATUS
index a92cf1d43f669398a4e2fa0b550cb9aadc77f142..0648b7bbc36c327429b48049adceb4f10bfdd1a0 100644 (file)
--- a/STATUS
+++ b/STATUS
@@ -149,23 +149,6 @@ PATCHES ACCEPTED TO BACKPORT FROM TRUNK:
      ylavic: while at it, I also included r1678763 which is only an
              optimization, but allows to keep code in sync with 2.4/trunk.
 
-  *) mod_substitute: Configure patterns merge order. PR 57641
-     trunk patch: http://svn.apache.org/r1684900
-                  http://svn.apache.org/r1687539 
-                  http://svn.apache.org/r1687680
-                  http://svn.apache.org/r1688331
-                  http://svn.apache.org/r1688339
-                  http://svn.apache.org/r1688340
-                  http://svn.apache.org/r1688343
-                  http://svn.apache.org/r1697013
-                  http://svn.apache.org/r1697015
-     2.2.x patch: http://home.apache.org/~ylavic/patches/httpd-2.2.x-SubstituteInheritBefore-v5.patch
-     +1: ylavic, rpluem, wrowe
-     rpluem: Doesn't that change the previous behaviour if SubstituteInheritBefore is not set?
-     ylavic: yes thanks, updated to v5 including r1697013 and r1697015,
-             the diff to v4 is:
-             http://home.apache.org/~ylavic/patches/httpd-2.2.x-SubstituteInheritBefore-v4_vs_v5.diff
-
 
 PATCHES PROPOSED TO BACKPORT FROM TRUNK:
   [ New proposals should be added at the end of the list ]
index 905e25ac742e922f089b69af5a93067635c223f4..de7b4124f73a4992f3455701edf88af8f59f757c 100644 (file)
 </usage>
 </directivesynopsis>
 
+<directivesynopsis>
+<name>SubstituteInheritBefore</name>
+<description>Change the merge order of inherited patterns</description>
+<syntax>SubstituteInheritBefore on|off</syntax>
+<default>SubstituteInheritBefore off</default>
+<contextlist><context>directory</context>
+<context>.htaccess</context></contextlist>
+<override>FileInfo</override>
+<compatibility>Available in httpd 2.2.32 and later</compatibility>
+
+<usage>
+    <p>Whether to apply the inherited <directive>Substitute</directive>
+    patterns first (<code>on</code>), or after the ones of the current
+    context (<code>off</code>).
+    <directive>SubstituteInheritBefore</directive> is itself inherited,
+    hence contexts that inherit it (those that don't specify their own
+    <directive>SubstituteInheritBefore</directive> value) will apply the
+    closest defined merge order.
+</usage>
+</directivesynopsis>
+
 </modulesynopsis>
index faa86ad0b67bba0e54c8ef7d842ada0956e109b8..fdb90594cd5aad65aee970c192c30b09bbd360aa 100644 (file)
@@ -46,6 +46,7 @@ typedef struct subst_pattern_t {
 
 typedef struct {
     apr_array_header_t *patterns;
+    int inherit_before;
 } subst_dir_conf;
 
 typedef struct {
@@ -59,21 +60,37 @@ typedef struct {
 static void *create_substitute_dcfg(apr_pool_t *p, char *d)
 {
     subst_dir_conf *dcfg =
-    (subst_dir_conf *) apr_pcalloc(p, sizeof(subst_dir_conf));
+        (subst_dir_conf *) apr_palloc(p, sizeof(subst_dir_conf));
 
     dcfg->patterns = apr_array_make(p, 10, sizeof(subst_pattern_t));
+    dcfg->inherit_before = -1;
     return dcfg;
 }
 
 static void *merge_substitute_dcfg(apr_pool_t *p, void *basev, void *overv)
 {
     subst_dir_conf *a =
-    (subst_dir_conf *) apr_pcalloc(p, sizeof(subst_dir_conf));
+        (subst_dir_conf *) apr_palloc(p, sizeof(subst_dir_conf));
     subst_dir_conf *base = (subst_dir_conf *) basev;
     subst_dir_conf *over = (subst_dir_conf *) overv;
 
-    a->patterns = apr_array_append(p, over->patterns,
-                                                  base->patterns);
+    a->inherit_before = (over->inherit_before != -1)
+                            ? over->inherit_before
+                            : base->inherit_before;
+    /* SubstituteInheritBefore wasn't the default behavior until 2.5.x,
+     * and may be re-disabled as desired; the original default behavior
+     * was to apply inherited subst patterns after locally scoped patterns.
+     * In later 2.2 and 2.4 versions, SubstituteInheritBefore may be toggled
+     * 'on' to follow the corrected/expected behavior, without violating POLS.
+     */
+    if (a->inherit_before == 1) {
+        a->patterns = apr_array_append(p, base->patterns,
+                                          over->patterns);
+    }
+    else {
+        a->patterns = apr_array_append(p, over->patterns,
+                                          base->patterns);
+    }
     return a;
 }
 
@@ -584,6 +601,9 @@ static void register_hooks(apr_pool_t *pool)
 static const command_rec substitute_cmds[] = {
     AP_INIT_TAKE1("Substitute", set_pattern, NULL, OR_ALL,
                   "Pattern to filter the response content (s/foo/bar/[inf])"),
+    AP_INIT_FLAG("SubstituteInheritBefore", ap_set_flag_slot,
+                 (void *)APR_OFFSETOF(subst_dir_conf, inherit_before), OR_FILEINFO,
+                 "Apply inherited patterns before those of the current context"),
     {NULL}
 };