1 /* This file is part of Metaproxy.
2 Copyright (C) 2005-2013 Index Data
4 Metaproxy is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 Metaproxy is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include "filter_http_client.hpp"
24 #include "filter_http_rewrite.hpp"
25 #include <metaproxy/util.hpp>
26 #include "router_chain.hpp"
27 #include <metaproxy/package.hpp>
29 #include <boost/regex.hpp>
30 #include <boost/lexical_cast.hpp>
32 #define BOOST_AUTO_TEST_MAIN
33 #define BOOST_TEST_DYN_LINK
35 #include <boost/test/auto_unit_test.hpp>
37 using namespace boost::unit_test;
38 namespace mp = metaproxy_1;
41 BOOST_AUTO_TEST_CASE( test_filter_rewrite_1 )
45 mp::filter::HttpRewrite fhr;
52 BOOST_AUTO_TEST_CASE( test_filter_rewrite_2 )
56 mp::RouterChain router;
58 mp::filter::HttpRewrite fhr;
60 mp::filter::HttpRewrite::spair_vec vec_req;
61 vec_req.push_back(std::make_pair(
62 "(?<proto>http\\:\\/\\/s?)(?<pxhost>[^\\/?#]+)\\/(?<pxpath>[^\\/]+)"
63 "\\/(?<host>[^\\/]+)(?<path>.*)",
64 "${proto}${host}${path}"
66 vec_req.push_back(std::make_pair(
71 mp::filter::HttpRewrite::spair_vec vec_res;
72 vec_res.push_back(std::make_pair(
73 "(?<proto>http\\:\\/\\/s?)(?<host>[^\\/?#]+)\\/(?<path>[^ >]+)",
74 "http://${pxhost}/${pxpath}/${host}/${path}"
77 fhr.configure(vec_req, vec_res);
79 mp::filter::HTTPClient hc;
84 // create an http request
88 Z_GDU *gdu_req = z_get_HTTP_Request_uri(odr,
89 "http://proxyhost/proxypath/localhost:80/~jakub/targetsite.php", 0, 1);
91 pack.request() = gdu_req;
94 pack.router(router).move();
96 //analyze the response
97 Z_GDU *gdu_res = pack.response().get();
99 BOOST_CHECK_EQUAL(gdu_res->which, Z_GDU_HTTP_Response);
101 Z_HTTP_Response *hres = gdu_res->u.HTTP_Response;
105 catch (std::exception & e) {
106 std::cout << e.what();
114 * c-file-style: "Stroustrup"
115 * indent-tabs-mode: nil
117 * vim: shiftwidth=4 tabstop=8 expandtab