From 1933e4904a95ec7c430b61a2dcc0e907cbac75de Mon Sep 17 00:00:00 2001 From: Jakub Skoczen Date: Tue, 7 May 2013 15:44:57 +0200 Subject: [PATCH] Fix response rewriting --- src/filter_http_rewrite.cpp | 24 ++++++++++++++---------- src/filter_http_rewrite.hpp | 12 +++++++++--- src/test_filter_rewrite.cpp | 4 ++-- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/filter_http_rewrite.cpp b/src/filter_http_rewrite.cpp index e937a73..ff1a25c 100644 --- a/src/filter_http_rewrite.cpp +++ b/src/filter_http_rewrite.cpp @@ -59,8 +59,9 @@ void yf::HttpRewrite::process(mp::Package & package) const mp::odr o; rewrite_reqline(o, hreq, vars); yaz_log(YLOG_LOG, ">> Request headers"); - rewrite_headers(o, hreq->headers, vars); - rewrite_body(o, &hreq->content_buf, &hreq->content_len, vars); + rewrite_headers(o, hreq->headers, vars, req_uri_pats, req_groups_bynum); + rewrite_body(o, &hreq->content_buf, &hreq->content_len, vars, + req_uri_pats, req_groups_bynum); package.request() = gdu; } package.move(); @@ -71,8 +72,9 @@ void yf::HttpRewrite::process(mp::Package & package) const yaz_log(YLOG_LOG, "Response code %d", hres->code); mp::odr o; yaz_log(YLOG_LOG, "<< Respose headers"); - rewrite_headers(o, hres->headers, vars); - rewrite_body(o, &hres->content_buf, &hres->content_len, vars); + rewrite_headers(o, hres->headers, vars, res_uri_pats, res_groups_bynum); + rewrite_body(o, &hres->content_buf, &hres->content_len, vars, + res_uri_pats, res_groups_bynum); package.response() = gdu; } } @@ -106,7 +108,9 @@ void yf::HttpRewrite::rewrite_reqline (mp::odr & o, Z_HTTP_Request *hreq, } void yf::HttpRewrite::rewrite_headers (mp::odr & o, Z_HTTP_Header *headers, - std::map & vars) const + std::map & vars, + const spair_vec & uri_pats, + const std::vector > & groups_bynum) const { for (Z_HTTP_Header *header = headers; header != 0; @@ -116,9 +120,7 @@ void yf::HttpRewrite::rewrite_headers (mp::odr & o, Z_HTTP_Header *headers, sheader += ": "; sheader += header->value; yaz_log(YLOG_LOG, "%s: %s", header->name, header->value); - std::string out = test_patterns(vars, - sheader, - req_uri_pats, req_groups_bynum); + std::string out = test_patterns(vars, sheader, uri_pats, groups_bynum); if (!out.empty()) { size_t pos = out.find(": "); @@ -135,13 +137,15 @@ void yf::HttpRewrite::rewrite_headers (mp::odr & o, Z_HTTP_Header *headers, } void yf::HttpRewrite::rewrite_body (mp::odr & o, char **content_buf, int *content_len, - std::map & vars) const + std::map & vars, + const spair_vec & uri_pats, + const std::vector > & groups_bynum) const { if (*content_buf) { std::string body(*content_buf); std::string nbody = - test_patterns(vars, body, req_uri_pats, req_groups_bynum); + test_patterns(vars, body, uri_pats, groups_bynum); if (!nbody.empty()) { *content_buf = odr_strdup(o, nbody.c_str()); diff --git a/src/filter_http_rewrite.hpp b/src/filter_http_rewrite.hpp index bcfba00..11b43e6 100644 --- a/src/filter_http_rewrite.hpp +++ b/src/filter_http_rewrite.hpp @@ -48,14 +48,20 @@ namespace metaproxy_1 { void rewrite_reqline (mp::odr & o, Z_HTTP_Request *hreq, std::map & vars) const; void rewrite_headers (mp::odr & o, Z_HTTP_Header *headers, - std::map & vars) const; + std::map & vars, + const spair_vec & uri_pats, + const std::vector > & groups_bynum_vec) const; void rewrite_body (mp::odr & o, char **content_buf, int *content_len, - std::map & vars) const; + std::map & vars, + const spair_vec & uri_pats, + const std::vector > + & groups_bynum) const; const std::string test_patterns( std::map & vars, const std::string & txt, const spair_vec & uri_pats, - const std::vector > & groups_bynum_vec) const; + const std::vector > + & groups_bynum) const; const std::string search_replace( std::map & vars, const std::string & txt, diff --git a/src/test_filter_rewrite.cpp b/src/test_filter_rewrite.cpp index d69d927..7753f0e 100644 --- a/src/test_filter_rewrite.cpp +++ b/src/test_filter_rewrite.cpp @@ -86,7 +86,7 @@ BOOST_AUTO_TEST_CASE( test_filter_rewrite_2 ) mp::filter::HttpRewrite::spair_vec vec_res; vec_res.push_back(std::make_pair( "(?http\\:\\/\\/s?)(?[^\\/?#]+)\\/(?[^ >]+)", - "http://${pxhost}/${pxpath}/${host}/${path}" + "THAT WAS MATCHED" )); fhr.configure(vec_req, vec_res); @@ -143,7 +143,7 @@ BOOST_AUTO_TEST_CASE( test_filter_rewrite_3 ) " \n" " \n" + " to='THAT WAS MATCHED' />\n" " \n" "\n" ; -- 1.7.10.4