X-Git-Url: http://lists.indexdata.com/cgi-bin?a=blobdiff_plain;f=src%2Ffilter_http_client.cpp;h=6a268c35361592464fe07f2f490d6ae95dfeb2ca;hb=1751c7afd96e1984f5710284cdcb245a93d9ce6c;hp=fd6945b6b8e25a705a67004a16ee125ced441c08;hpb=409c020044df74e1883710cbc1f2860dee8c5ac4;p=metaproxy-moved-to-github.git diff --git a/src/filter_http_client.cpp b/src/filter_http_client.cpp index fd6945b..6a268c3 100644 --- a/src/filter_http_client.cpp +++ b/src/filter_http_client.cpp @@ -49,10 +49,18 @@ namespace metaproxy_1 { friend class HTTPClient; void proxy(mp::Package &package); std::string proxy_host; + std::string default_host; + int max_redirects; + Rep(); }; } } +yf::HTTPClient::Rep::Rep() +{ + max_redirects = -0; +} + yf::HTTPClient::HTTPClient() : m_p(new Rep) { } @@ -70,16 +78,35 @@ void yf::HTTPClient::Rep::proxy(mp::Package &package) Z_GDU *res_gdu = 0; mp::odr o; yaz_url_t yaz_url = yaz_url_create(); + const char *http_proxy = + z_HTTP_header_remove(&hreq->headers, "X-Metaproxy-Proxy"); + + if (!http_proxy) + http_proxy = proxy_host.c_str(); - if (proxy_host.length()) - yaz_url_set_proxy(yaz_url, proxy_host.c_str()); - Z_HTTP_Response *http_response = - yaz_url_exec(yaz_url, hreq->path, hreq->method, + if (*http_proxy) + yaz_url_set_proxy(yaz_url, http_proxy); + + yaz_url_set_max_redirects(yaz_url, max_redirects); + + std::string uri; + if (hreq->path[0] == '/') + { + if (default_host.length()) + uri = default_host + hreq->path; + } + else + uri = hreq->path; + Z_HTTP_Response *http_response = 0; + if (uri.length()) + http_response = + yaz_url_exec(yaz_url, uri.c_str(), hreq->method, hreq->headers, hreq->content_buf, hreq->content_len); if (http_response) { res_gdu = o.create_HTTP_Response(package.session(), hreq, 200); + z_HTTP_header_remove(&http_response->headers, "Transfer-Encoding"); res_gdu->u.HTTP_Response = http_response; } else @@ -113,12 +140,26 @@ void mp::filter::HTTPClient::configure(const xmlNode * ptr, bool test_only, { m_p->proxy_host = mp::xml::get_text(ptr); } + else if (!strcmp((const char *) ptr->name, "max-redirects")) + { + m_p->max_redirects = mp::xml::get_int(ptr, 0); + } + else if (!strcmp((const char *) ptr->name, "default-host")) + { + m_p->default_host = mp::xml::get_text(ptr); + if (m_p->default_host.find("://") == std::string::npos) + { + throw mp::filter::FilterException + ("default-host is missing method (such as http://)" + " in http_client filter"); + } + } else { throw mp::filter::FilterException ("Bad element " + std::string((const char *) ptr->name) - + " in virt_db filter"); + + " in http_client filter"); } } }