#endif
#include "filter_cql_to_rpn.hpp"
#include "filter_frontend_net.hpp"
+#include "filter_http_client.hpp"
#include "filter_http_file.hpp"
#include "filter_limit.hpp"
#include "filter_load_balance.hpp"
#endif
&metaproxy_1_filter_cql_to_rpn,
&metaproxy_1_filter_frontend_net,
+ &metaproxy_1_filter_http_client,
&metaproxy_1_filter_http_file,
&metaproxy_1_filter_limit,
&metaproxy_1_filter_load_balance,
--- /dev/null
+/* This file is part of Metaproxy.
+ Copyright (C) 2005-2013 Index Data
+
+Metaproxy is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 2, or (at your option) any later
+version.
+
+Metaproxy is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#include "config.hpp"
+#include <metaproxy/filter.hpp>
+#include <metaproxy/package.hpp>
+#include <metaproxy/util.hpp>
+#include <yaz/url.h>
+#include "filter_http_client.hpp"
+
+#include <yaz/zgdu.h>
+#include <yaz/log.h>
+
+#include <boost/thread/mutex.hpp>
+
+#include <list>
+#include <map>
+#include <iostream>
+
+#if HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+
+#if HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+
+namespace mp = metaproxy_1;
+namespace yf = mp::filter;
+
+namespace metaproxy_1 {
+ namespace filter {
+ class HTTPClient::Rep {
+ friend class HTTPClient;
+ void proxy(mp::Package &package);
+ std::string proxy_host;
+ };
+ }
+}
+
+yf::HTTPClient::HTTPClient() : m_p(new Rep)
+{
+}
+
+yf::HTTPClient::~HTTPClient()
+{
+}
+
+void yf::HTTPClient::Rep::proxy(mp::Package &package)
+{
+ Z_GDU *req_gdu = package.request().get();
+ if (req_gdu && req_gdu->which == Z_GDU_HTTP_Request)
+ {
+ Z_HTTP_Request *hreq = req_gdu->u.HTTP_Request;
+ Z_GDU *res_gdu = 0;
+ mp::odr o;
+ yaz_url_t yaz_url = yaz_url_create();
+
+ 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,
+ hreq->headers, hreq->content_buf,
+ hreq->content_len);
+ if (http_response)
+ {
+ res_gdu = o.create_HTTP_Response(package.session(), hreq, 200);
+ res_gdu->u.HTTP_Response = http_response;
+ }
+ else
+ {
+ res_gdu = o.create_HTTP_Response(package.session(), hreq, 404);
+ }
+ package.response() = res_gdu;
+ yaz_url_destroy(yaz_url);
+ }
+ else
+ package.move();
+}
+
+void yf::HTTPClient::process(mp::Package &package) const
+{
+ Z_GDU *gdu = package.request().get();
+ if (gdu && gdu->which == Z_GDU_HTTP_Request)
+ m_p->proxy(package);
+ else
+ package.move();
+}
+
+void mp::filter::HTTPClient::configure(const xmlNode * ptr, bool test_only,
+ const char *path)
+{
+ for (ptr = ptr->children; ptr; ptr = ptr->next)
+ {
+ if (ptr->type != XML_ELEMENT_NODE)
+ continue;
+ else if (!strcmp((const char *) ptr->name, "proxy"))
+ {
+ m_p->proxy_host = mp::xml::get_text(ptr);
+ }
+ else
+ {
+ throw mp::filter::FilterException
+ ("Bad element "
+ + std::string((const char *) ptr->name)
+ + " in virt_db filter");
+ }
+ }
+}
+
+static mp::filter::Base* filter_creator()
+{
+ return new mp::filter::HTTPClient;
+}
+
+extern "C" {
+ struct metaproxy_1_filter_struct metaproxy_1_filter_http_client = {
+ 0,
+ "http_client",
+ filter_creator
+ };
+}
+
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+
--- /dev/null
+/* This file is part of Metaproxy.
+ Copyright (C) 2005-2013 Index Data
+
+Metaproxy is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 2, or (at your option) any later
+version.
+
+Metaproxy is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#ifndef FILTER_HTTP_CLIENT_HPP
+#define FILTER_HTTP_CLIENT_HPP
+
+#include <boost/scoped_ptr.hpp>
+
+#include <metaproxy/filter.hpp>
+
+namespace metaproxy_1 {
+ namespace filter {
+ class HTTPClient : public Base {
+ class Rep;
+ class Assoc;
+ public:
+ ~HTTPClient();
+ HTTPClient();
+ void process(metaproxy_1::Package & package) const;
+ void configure(const xmlNode * ptr, bool test_only,
+ const char *path);
+ private:
+ boost::scoped_ptr<Rep> m_p;
+ };
+ }
+}
+
+extern "C" {
+ extern struct metaproxy_1_filter_struct metaproxy_1_filter_http_client;
+}
+
+#endif
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+