From: Heikki Levanto Date: Wed, 29 May 2013 11:12:49 +0000 (+0200) Subject: Merge remote-tracking branch 'origin/master' into rewrite-filter X-Git-Tag: v1.3.59~57^2~11 X-Git-Url: http://git.indexdata.com/?a=commitdiff_plain;h=2c08da821832998446e5fe92acf4d1e87fe531d4;p=metaproxy-moved-to-github.git Merge remote-tracking branch 'origin/master' into rewrite-filter Conflicts: src/Makefile.am Signed-off-by: Heikki Levanto --- 2c08da821832998446e5fe92acf4d1e87fe531d4 diff --cc src/Makefile.am index e5c40aa,f3b0500..42bb6b3 --- a/src/Makefile.am +++ b/src/Makefile.am @@@ -59,24 -57,27 +58,28 @@@ libmetaproxy_la_SOURCES = torus.cpp torus.hpp \ url_recipe.cpp \ util.cpp \ + html_parser.hpp html_parser.cpp \ - xmlutil.cpp + router_chain.cpp \ + xmlutil.cpp + libmetaproxy_la_LIBADD = $(YAZPPLALIB) \ + $(BOOST_LIB) $(BOOST_SYSTEM_LIB) $(BOOST_THREAD_LIB) \ + $(BOOST_REGEX_LIB) - libmetaproxy_la_LIBADD = $(YAZPPLALIB) $(BOOST_LIB) $(BOOST_THREAD_LIB) $(BOOST_REGEX_LIB) + metaproxy_LDADD = libmetaproxy.la $(YAZPPLALIB) \ + $(BOOST_LIB) $(BOOST_SYSTEM_LIB) $(BOOST_THREAD_LIB) \ + $(BOOST_REGEX_LIB) $(USEMARCONLALIB) - # Rules for lib + tstdl_LDADD = $(metaproxy_LDADD) - LDADD = libmetaproxy.la $(YAZPPLALIB) $(BOOST_LIB) $(BOOST_THREAD_LIB) \ - $(BOOST_REGEX_LIB) $(USEMARCONLALIB) + LDADD = $(metaproxy_LDADD) $(BOOST_TEST_LIB) + AM_LDFLAGS = -export-dynamic bin_PROGRAMS = metaproxy - noinst_PROGRAMS = ex_filter_frontend_net ex_router_flexml tstdl + noinst_PROGRAMS = tstdl - ex_filter_frontend_net_SOURCES = ex_filter_frontend_net.cpp - ex_router_flexml_SOURCES = ex_router_flexml.cpp tstdl_SOURCES = tstdl.cpp - metaproxy_SOURCES = metaproxy_prog.cpp + metaproxy_SOURCES = metaproxy_prog.cpp $(filter_src) # Rules for dl programs pkglib_LTLIBRARIES = metaproxy_filter_dl.la @@@ -122,52 -121,23 +125,26 @@@ test_session1_SOURCES=test_session1.cp test_session2_SOURCES=test_session2.cpp test_boost_threads_SOURCES=test_boost_threads.cpp test_thread_pool_observer_SOURCES = test_thread_pool_observer.cpp - test_filter_auth_simple_SOURCES = test_filter_auth_simple.cpp - test_filter_factory_SOURCES = test_filter_factory.cpp - test_filter_frontend_net_SOURCES = test_filter_frontend_net.cpp - test_filter_log_SOURCES = test_filter_log.cpp - test_filter_multi_SOURCES = test_filter_multi.cpp - test_filter_query_rewrite_SOURCES = test_filter_query_rewrite.cpp - test_filter_z3950_client_SOURCES = test_filter_z3950_client.cpp - test_filter_backend_test_SOURCES = test_filter_backend_test.cpp - test_filter_bounce_SOURCES = test_filter_bounce.cpp - test_filter_record_transform_SOURCES = test_filter_record_transform.cpp - test_filter_sru_to_z3950_SOURCES = test_filter_sru_to_z3950.cpp - test_filter_virt_db_SOURCES = test_filter_virt_db.cpp - test_filter_rewrite_SOURCES = test_filter_rewrite.cpp + test_filter_auth_simple_SOURCES = test_filter_auth_simple.cpp $(filter_src) + test_filter_factory_SOURCES = test_filter_factory.cpp $(filter_src) + test_filter_frontend_net_SOURCES = test_filter_frontend_net.cpp $(filter_src) + test_filter_log_SOURCES = test_filter_log.cpp $(filter_src) + test_filter_multi_SOURCES = test_filter_multi.cpp $(filter_src) + test_filter_query_rewrite_SOURCES = test_filter_query_rewrite.cpp $(filter_src) + test_filter_z3950_client_SOURCES = test_filter_z3950_client.cpp $(filter_src) + test_filter_backend_test_SOURCES = test_filter_backend_test.cpp $(filter_src) + test_filter_bounce_SOURCES = test_filter_bounce.cpp $(filter_src) + test_filter_record_transform_SOURCES = test_filter_record_transform.cpp \ + $(filter_src) + test_filter_sru_to_z3950_SOURCES = test_filter_sru_to_z3950.cpp $(filter_src) + test_filter_virt_db_SOURCES = test_filter_virt_db.cpp $(filter_src) test_ses_map_SOURCES = test_ses_map.cpp - test_router_flexml_SOURCES = test_router_flexml.cpp - test_html_parser_SOURCES = test_html_parser.cpp + test_router_flexml_SOURCES = test_router_flexml.cpp $(filter_src) test_xmlutil_SOURCES = test_xmlutil.cpp - TESTLDADD = $(LDADD) $(BOOST_TEST_LIB) - - test_package1_LDADD = $(TESTLDADD) - test_pipe_LDADD = $(TESTLDADD) - test_filter1_LDADD = $(TESTLDADD) - test_filter2_LDADD = $(TESTLDADD) - test_session1_LDADD = $(TESTLDADD) - test_session2_LDADD = $(TESTLDADD) - test_boost_threads_LDADD = $(TESTLDADD) - test_filter_auth_simple_LDADD = $(TESTLDADD) - test_filter_factory_LDADD = $(TESTLDADD) - test_filter_frontend_net_LDADD = $(TESTLDADD) - test_filter_log_LDADD = $(TESTLDADD) - test_filter_multi_LDADD = $(TESTLDADD) - test_filter_query_rewrite_LDADD = $(TESTLDADD) - test_filter_z3950_client_LDADD = $(TESTLDADD) - test_filter_backend_test_LDADD = $(TESTLDADD) - test_filter_bounce_LDADD = $(TESTLDADD) - test_filter_record_transform_LDADD = $(TESTLDADD) - test_filter_sru_to_z3950_LDADD = $(TESTLDADD) - test_filter_virt_db_LDADD = $(TESTLDADD) - test_filter_rewrite_LDADD = $(TESTLDADD) - test_router_flexml_LDADD = $(TESTLDADD) - test_ses_map_LDADD = $(TESTLDADD) - test_thread_pool_observer_LDADD = $(TESTLDADD) - test_html_parser_LDADD = $(TESTLDADD) - test_xmlutil_LDADD = $(TESTLDADD) ++test_html_parser_SOURCES = test_html_parser.cpp $(filter_src) ++test_filter_rewrite_SOURCES = test_filter_rewrite.cpp $(filter_src) + # doxygen target dox: (cd $(top_srcdir) ; make dox) diff --cc src/test_filter_rewrite.cpp index 430e784,0000000..d266274 mode 100644,000000..100644 --- a/src/test_filter_rewrite.cpp +++ b/src/test_filter_rewrite.cpp @@@ -1,346 -1,0 +1,346 @@@ +/* This file is part of Metaproxy. + Copyright (C) 2005-2013 Index Data + +Metaproxy is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 2, or (at your option) any later +version. + +Metaproxy is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "config.hpp" +#include +#include + +#include "filter_http_client.hpp" +#include "filter_http_rewrite.hpp" +#include - #include "router_chain.hpp" ++#include +#include + +#include +#include + +#include + +#define BOOST_AUTO_TEST_MAIN +#define BOOST_TEST_DYN_LINK + +#include + +using namespace boost::unit_test; +namespace mp = metaproxy_1; + +struct TestConfig { + TestConfig() + { + std::cout << "global setup\n"; + yaz_log_init_level(YLOG_ALL); + } + ~TestConfig() + { + std::cout << "global teardown\n"; + } +}; + +BOOST_GLOBAL_FIXTURE( TestConfig ); + +BOOST_AUTO_TEST_CASE( test_filter_rewrite_1 ) +{ + try + { + std::cout << "Running non-xml config test case" << std::endl; + mp::RouterChain router; + mp::filter::HttpRewrite fhr; + + //configure the filter + mp::filter::HttpRewrite::spair_vec vec_req; + vec_req.push_back(std::make_pair( + "(?http\\:\\/\\/s?)(?[^\\/?#]+)\\/(?[^\\/]+)" + "\\/(?[^\\/]+)(?.*)", + "${proto}${host}${path}" + )); + vec_req.push_back(std::make_pair( + "(?:Host\\: )(.*)", + "Host: ${host}" + )); + + mp::filter::HttpRewrite::spair_vec vec_res; + vec_res.push_back(std::make_pair( + "(?http\\:\\/\\/s?)(?[^\\/?# \"'>]+)\\/(?[^ \"'>]+)", + "${proto}${pxhost}/${pxpath}/${host}/${path}" + )); + + fhr.configure(vec_req, vec_res); + + router.append(fhr); + + // create an http request + mp::Package pack; + + mp::odr odr; + Z_GDU *gdu_req = z_get_HTTP_Request_uri(odr, + "http://proxyhost/proxypath/targetsite/page1.html", 0, 1); + + pack.request() = gdu_req; + + //create the http response + + const char *resp_buf = + "HTTP/1.1 200 OK\r\n" + "Content-Length: 441\r\n" + "Content-Type: text/html\r\n" + "Link: ; rel=absolute\r\n" + "Link: ; rel=relative\r\n" + "\r\n" + "Hello proxy!" + "" + "" + "" + "" + "

Welcome to our website. It doesn't make it easy to get pro" + "xified" + "" + " An absolute link" + "" + "" + "" + "" + "

Welcome to our website. It doesn't make it easy to get pro" + "xified" + "" + " An absolute link" + "\n" + "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + "\n" + ; + + std::cout << xmlconf; + + // reading and parsing XML conf + xmlDocPtr doc = xmlParseMemory(xmlconf.c_str(), xmlconf.size()); + BOOST_CHECK(doc); + xmlNode *root_element = xmlDocGetRootElement(doc); + fhr.configure(root_element, true, ""); + xmlFreeDoc(doc); + + router.append(fhr); + + // create an http request + mp::Package pack; + + mp::odr odr; + Z_GDU *gdu_req = z_get_HTTP_Request_uri(odr, + "http://proxyhost/proxypath/targetsite/page1.html", 0, 1); + + pack.request() = gdu_req; + + //create the http response + + const char *resp_buf = + "HTTP/1.1 200 OK\r\n" + "Content-Length: 50\r\n" + "Content-Type: text/html\r\n" + "Link: ; rel=absolute\r\n" + "Link: ; rel=relative\r\n" + "\r\n" + "Hello proxy!" + "" + "" + "" + "" + "

Welcome to our website. It doesn't make it easy to get pro" + "xified" + "" + " An absolute link" + "" + "" + "" + "" + "

Welcome to our website. It doesn't make it easy to get pro" + "xified" + "" + " An absolute link" + "