+ path += hreq->path;
+ }
+
+
+ std::list<Within>::const_iterator it = within_list.begin();
+ for (; it != within_list.end(); it++)
+ if (it->reqline)
+ {
+ RulePtr rule = it->rule;
+ yaz_log(YLOG_LOG, "Proxy request URL is %s", path.c_str());
+ std::string npath = rule->test_patterns(vars, path);
+ if (!npath.empty())
+ {
+ yaz_log(YLOG_LOG, "Rewritten request URL is %s", npath.c_str());
+ hreq->path = odr_strdup(o, npath.c_str());
+ }
+ }
+}
+
+void yf::HttpRewrite::Phase::rewrite_headers(mp::odr & o,
+ Z_HTTP_Header *headers,
+ std::map<std::string, std::string> & vars) const
+{
+ for (Z_HTTP_Header *header = headers; header; header = header->next)
+ {
+ std::list<Within>::const_iterator it = within_list.begin();
+ for (; it != within_list.end(); it++)
+ {
+ if (it->header.length() > 0 &&
+ yaz_strcasecmp(it->header.c_str(), header->name) == 0)
+ {
+ std::string sheader(header->name);
+ sheader += ": ";
+ sheader += header->value;
+
+ RulePtr rule = it->rule;
+ std::string out = rule->test_patterns(vars, sheader);
+ if (!out.empty())
+ {
+ size_t pos = out.find(": ");
+ if (pos == std::string::npos)
+ {
+ yaz_log(YLOG_LOG, "Header malformed during rewrite, ignoring");
+ continue;
+ }
+ header->name = odr_strdup(o, out.substr(0, pos).c_str());
+ header->value = odr_strdup(o,
+ out.substr(pos + 2,
+ std::string::npos).c_str());
+ }
+ }
+ }
+ }
+}
+
+void yf::HttpRewrite::Phase::rewrite_body(mp::odr & o,
+ char **content_buf,
+ int *content_len,
+ std::map<std::string, std::string> & vars) const
+{
+ if (*content_buf)
+ {
+ int i;
+ for (i = 0; i < *content_len; i++)
+ if ((*content_buf)[i] == 0)
+ return; // binary content. skip
+
+ HTMLParser parser;
+ Event ev(this, vars);
+ std::string buf(*content_buf, *content_len);
+
+ parser.parse(ev, buf.c_str());
+ const char *res = ev.result();
+ *content_buf = odr_strdup(o, res);
+ *content_len = strlen(res);