-class FilterHeaderRewrite: public mp::filter::Base {
-public:
- void process(mp::Package & package) const {
- Z_GDU *gdu = package.request().get();
- //we have an http req
- if (gdu && gdu->which == Z_GDU_HTTP_Request)
- {
- std::cout << "Request headers" << std::endl;
- Z_HTTP_Request *hreq = gdu->u.HTTP_Request;
- //dump req headers
- for (Z_HTTP_Header *header = hreq->headers;
- header != 0;
- header = header->next)
- {
- std::cout << header->name << ": " << header->value << std::endl;
- rewrite_req_header(header);
- }
- }
- package.move();
- gdu = package.response().get();
- if (gdu && gdu->which == Z_GDU_HTTP_Response)
- {
- std::cout << "Respose headers" << std::endl;
- Z_HTTP_Response *hr = gdu->u.HTTP_Response;
- //dump resp headers
- for (Z_HTTP_Header *header = hr->headers;
- header != 0;
- header = header->next)
- {
- std::cout << header->name << ": " << header->value << std::endl;
- }
- }
-
- };
- void configure(const xmlNode* ptr, bool test_only, const char *path) {};
-
- void rewrite_req_header(Z_HTTP_Header *header) const
- {
- //exec regex against value
- boost::regex e(req_uri_pat, boost::regex::perl);
- boost::smatch what;
- std::string hvalue(header->value);
- if(boost::regex_match(hvalue, what, e, boost::match_extra))
- {
- unsigned i, j;
- std::cout << "** Match found **\n Sub-Expressions:\n";
- for(i = 0; i < what.size(); ++i)
- std::cout << " $" << i << " = \"" << what[i] << "\"\n";
- std::cout << " Captures:\n";
- for(i = 0; i < what.size(); ++i)
- {
- std::cout << " $" << i << " = {";
- for(j = 0; j < what.captures(i).size(); ++j)
- {
- if(j)
- std::cout << ", ";
- else
- std::cout << " ";
- std::cout << "\"" << what.captures(i)[j] << "\"";
- }
- std::cout << " }\n";
- }
- }
- else
- {
- std::cout << "** No Match found **\n";
- }
- //iteratate over named groups
- //set the captured values in the map
- //rewrite the header according to the hardcoded recipe
- };
-
- void configure(const std::string & req_uri_pat,
- const std::string & resp_uri_pat)