Only do CDATA for attr="#text", verbose flag
authorAdam Dickmeiss <adam@indexdata.dk>
Thu, 27 Jun 2013 09:50:23 +0000 (11:50 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Thu, 27 Jun 2013 09:50:49 +0000 (11:50 +0200)
src/filter_http_rewrite.cpp
src/test_filter_rewrite.cpp

index e69aba6..90e3152 100644 (file)
@@ -68,7 +68,9 @@ namespace metaproxy_1 {
 
         class HttpRewrite::Phase {
         public:
+            Phase();
             std::list<Within> within_list;
+            int m_verbose;
             void rewrite_reqline(mp::odr & o, Z_HTTP_Request *hreq,
                 std::map<std::string, std::string> & vars) const;
             void rewrite_headers(mp::odr & o, Z_HTTP_Header *headers,
@@ -225,6 +227,9 @@ void yf::HttpRewrite::Phase::rewrite_body(mp::odr & o,
 
         HTMLParser parser;
         Event ev(this, vars);
+
+        parser.set_verbose(m_verbose);
+
         std::string buf(*content_buf, *content_len);
 
         parser.parse(ev, buf.c_str());
@@ -265,7 +270,17 @@ void yf::HttpRewrite::Event::openTagStart(const char *tag, int tag_len)
             if (it->tag.length() > 0 && yaz_strcasecmp(it->tag.c_str(),
                                                        t.c_str()) == 0)
             {
-                enabled_within = it;
+                std::vector<std::string> attr;
+                boost::split(attr, it->attr, boost::is_any_of(","));
+                size_t i;
+                for (i = 0; i < attr.size(); i++)
+                {
+                    if (attr[i].compare("#text") == 0)
+                    {
+                        enabled_within = it;
+                        break;
+                    }
+                }
             }
         }
     }
@@ -560,9 +575,19 @@ std::string yf::HttpRewrite::Replace::sub_vars (
     return out;
 }
 
+yf::HttpRewrite::Phase::Phase() : m_verbose(0)
+{
+}
 
 void yf::HttpRewrite::configure_phase(const xmlNode *ptr, Phase &phase)
 {
+    static const char *names[2] = { "verbose", 0 };
+    std::string values[1];
+    values[0] = "0";
+    mp::xml::parse_attr(ptr, names, values);
+
+    phase.m_verbose = atoi(values[0].c_str());
+
     std::map<std::string, RulePtr > rules;
     for (ptr = ptr->children; ptr; ptr = ptr->next)
     {
index 65cb4c0..2e4ae54 100644 (file)
@@ -68,7 +68,7 @@ BOOST_AUTO_TEST_CASE( test_filter_rewrite_1 )
             "<?xml version='1.0'?>\n"
             "<filter xmlns='http://indexdata.com/metaproxy'\n"
             "        id='rewrite1' type='http_rewrite'>\n"
-            " <request>\n"
+            " <request verbose=\"1\">\n"
             "   <rule name=\"null\"/>\n"
             "   <rule name=\"url\">\n"
             "     <rewrite from='"
@@ -81,7 +81,7 @@ BOOST_AUTO_TEST_CASE( test_filter_rewrite_1 )
             "  <within header=\"link\" rule=\"null\"/>\n"
             "  <within reqline=\"1\" rule=\"url\"/>\n"
             " </request>\n"
-            " <response>\n"
+            " <response verbose=\"1\">\n"
             "   <rule name=\"null\"/>\n"
             "   <rule name=\"url\">\n"
             "     <rewrite from='"
@@ -89,8 +89,9 @@ BOOST_AUTO_TEST_CASE( test_filter_rewrite_1 )
             "            to='${proto}${pxhost}/${pxpath}/${host}/${path}' />\n"
             "  </rule>\n"
             "  <within header=\"link\" rule=\"url\"/>\n"
-            "  <within tag=\"script\" attr=\"src,#text\" rule=\"url\"/>\n"
-            "  <within tag=\"style\" rule=\"url\"/>\n"
+            "  <within tag=\"body\" attr=\"background\" rule=\"null\"/>\n"
+            "  <within tag=\"script\" attr=\"#text\" rule=\"url\"/>\n"
+            "  <within tag=\"style\" attr=\"#text\" rule=\"url\"/>\n"
             "  <within attr=\"href,src\" rule=\"url\"/>\n"
             " </response>\n"
             "</filter>\n"