From 519cf04ede8ce910b4048b98c8150adb8d983204 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Thu, 2 May 2013 13:57:26 +0200 Subject: [PATCH] http_client: new setting default-host Which serves as default host URI prefix. HTTP requests received without a host in the HTTP method line will use default-host. --- etc/config4.xml | 2 +- src/filter_http_client.cpp | 29 ++++++++++++++++++++++++++--- xml/schema/filter_http_client.rnc | 1 + 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/etc/config4.xml b/etc/config4.xml index 26124e5..d01f8d0 100644 --- a/etc/config4.xml +++ b/etc/config4.xml @@ -22,7 +22,7 @@ - localhost:9999 + http://localhost:9999 diff --git a/src/filter_http_client.cpp b/src/filter_http_client.cpp index fd6945b..cba6f48 100644 --- a/src/filter_http_client.cpp +++ b/src/filter_http_client.cpp @@ -49,6 +49,7 @@ namespace metaproxy_1 { friend class HTTPClient; void proxy(mp::Package &package); std::string proxy_host; + std::string default_host; }; } } @@ -70,11 +71,23 @@ 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 *h = strchr(hreq->path, '/'); + std::string uri; 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 (h > hreq->path+1 && !memcmp(h-1, "://", 3)) + uri = hreq->path; /* we have a host already */ + else + { + if (default_host.length()) + uri = default_host + 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) @@ -113,12 +126,22 @@ 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, "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"); } } } diff --git a/xml/schema/filter_http_client.rnc b/xml/schema/filter_http_client.rnc index d4c1881..9335290 100644 --- a/xml/schema/filter_http_client.rnc +++ b/xml/schema/filter_http_client.rnc @@ -6,5 +6,6 @@ filter_http_client = attribute type { "http_client" }, attribute id { xsd:NCName }?, attribute name { xsd:NCName }?, + element mp:default-host { xsd:string }?, element mp:proxy { xsd:string }? -- 1.7.10.4