From: Jakub Skoczen Date: Mon, 6 May 2013 10:45:46 +0000 (+0200) Subject: Rewrite body too X-Git-Tag: v1.3.59~57^2~28 X-Git-Url: http://jsfdemo.indexdata.com/cgi-bin?a=commitdiff_plain;h=c106731ba24ab8570ca249809c7aab46364c303a;p=metaproxy-moved-to-github.git Rewrite body too --- diff --git a/src/test_filter_rewrite.cpp b/src/test_filter_rewrite.cpp index 6864033..eee048d 100644 --- a/src/test_filter_rewrite.cpp +++ b/src/test_filter_rewrite.cpp @@ -55,17 +55,19 @@ public: std::cout << ">> Request headers" << std::endl; rewrite_reqline(o, hreq, vars); rewrite_headers(o, hreq->headers, vars); + rewrite_body(o, &hreq->content_buf, &hreq->content_len, vars); package.request() = gdu; } package.move(); gdu = package.response().get(); if (gdu && gdu->which == Z_GDU_HTTP_Response) { - Z_HTTP_Response *hr = gdu->u.HTTP_Response; - std::cout << "Response " << hr->code; + Z_HTTP_Response *hres = gdu->u.HTTP_Response; + std::cout << "Response " << hres->code; std::cout << "<< Respose headers" << std::endl; mp::odr o; - rewrite_headers(o, hr->headers, vars); + rewrite_headers(o, hres->headers, vars); + rewrite_body(o, &hres->content_buf, &hres->content_len, vars); package.response() = gdu; } } @@ -124,6 +126,23 @@ public: } } + void rewrite_body (mp::odr & o, char **content_buf, int *content_len, + std::map & vars) const + { + if (*content_buf) + { + std::string body(*content_buf); + std::string nbody = + test_patterns(vars, body, req_uri_pats, req_groups_bynum); + if (!nbody.empty()) + { + *content_buf = odr_strdup(o, nbody.c_str()); + *content_len = nbody.size(); + } + } + } + + void configure(const xmlNode* ptr, bool test_only, const char *path) {}; /**