Ruleset functional MP-469
authorAdam Dickmeiss <adam@indexdata.dk>
Thu, 18 Jul 2013 09:14:26 +0000 (11:14 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Thu, 18 Jul 2013 09:14:26 +0000 (11:14 +0200)
src/filter_http_rewrite.cpp
src/test_filter_rewrite.cpp

index 9ef4de2..def74b1 100644 (file)
@@ -724,17 +724,36 @@ void yf::HttpRewrite::Content::configure(
                     ("Empty rule in '" + values[3] +
                      "' in http_rewrite filter");
             }
-            size_t i;
-            for (i = 0; i < rulenames.size(); i++)
+            else if (rulenames.size() == 1)
             {
                 std::map<std::string,RulePtr>::const_iterator it =
-                    rules.find(rulenames[i]);
+                    rules.find(rulenames[0]);
                 if (it == rules.end())
                     throw mp::filter::FilterException
-                        ("Reference to non-existing rule '" + rulenames[i] +
+                        ("Reference to non-existing rule '" + rulenames[0] +
                          "' in http_rewrite filter");
-                if (i == 0)
-                    w.rule = it->second;
+                w.rule = it->second;
+
+            }
+            else
+            {
+                RulePtr rule(new Rule);
+                size_t i;
+                for (i = 0; i < rulenames.size(); i++)
+                {
+                    std::map<std::string,RulePtr>::const_iterator it =
+                        rules.find(rulenames[i]);
+                    if (it == rules.end())
+                        throw mp::filter::FilterException
+                            ("Reference to non-existing rule '" + rulenames[i] +
+                             "' in http_rewrite filter");
+                    RulePtr subRule = it->second;
+                    std::list<Replace>::iterator rit =
+                        subRule->replace_list.begin();
+                    for (; rit != subRule->replace_list.end(); rit++)
+                        rule->replace_list.push_back(*rit);
+                }
+                w.rule = rule;
             }
             w.reqline = values[4] == "1";
             w.type = values[5];
index 68acc0f..360246a 100644 (file)
@@ -68,9 +68,11 @@ BOOST_AUTO_TEST_CASE( test_filter_rewrite_1 )
             " </request>\n"
             " <response verbose=\"1\">\n"
             "  <rule name=\"null\"/>\n"
+            "  <rule name=\"cx\">\n"
+            "     <rewrite from='^cx' to='cy'/>\n"
+            "  </rule>\n"
             "  <rule name=\"url\">\n"
             "     <rewrite from='foo' to='bar'/>\n"
-            "     <rewrite from='^cx' to='cy'/>\n"
             "     <rewrite from='"
     "(?&lt;proto>https?://)(?&lt;host>[^/?# &quot;&apos;>]+)/(?&lt;path>[^  &quot;&apos;>]+)'\n"
             "            to='${proto}${pxhost}/${pxpath}/${host}/${path}' />\n"
@@ -82,7 +84,7 @@ BOOST_AUTO_TEST_CASE( test_filter_rewrite_1 )
             "    <within tag=\"body\" attr=\"background\" rule=\"null\"/>\n"
             "    <within tag=\"script\" attr=\"#text\" type=\"quoted-literal\" rule=\"url\"/>\n"
             "    <within tag=\"style\" attr=\"#text\" rule=\"url\"/>\n"
-            "    <within attr=\"href|src\" rule=\"url\"/>\n"
+            "    <within attr=\"href|src\" rule=\"url,cx\"/>\n"
             "    <within attr=\"onclick\" type=\"quoted-literal\" rule=\"url\"/>\n"
             "  </content>\n"
             "  <content type=\"quoted-literal\" mime=\".*javascript\">\n"