X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Ffilter_http_client.cpp;h=9e9512a4a6992db55c5c0d38228d10460e60d979;hb=b54a57c7af29c89371aa65dc766adac9ed61f58c;hp=2e6a38f43a0d9b838414274eb6184de75dd468da;hpb=55e06106b63485b77b5b3c114c39b79e4f23168a;p=metaproxy-moved-to-github.git diff --git a/src/filter_http_client.cpp b/src/filter_http_client.cpp index 2e6a38f..9e9512a 100644 --- a/src/filter_http_client.cpp +++ b/src/filter_http_client.cpp @@ -1,5 +1,5 @@ /* This file is part of Metaproxy. - Copyright (C) 2005-2013 Index Data + Copyright (C) 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 @@ -51,6 +51,7 @@ namespace metaproxy_1 { std::string proxy_host; std::string default_host; int max_redirects; + bool x_forwarded_for; Rep(); }; } @@ -58,7 +59,8 @@ namespace metaproxy_1 { yf::HTTPClient::Rep::Rep() { - max_redirects = -0; + max_redirects = 0; + x_forwarded_for = false; } yf::HTTPClient::HTTPClient() : m_p(new Rep) @@ -89,6 +91,21 @@ void yf::HTTPClient::Rep::proxy(mp::Package &package) yaz_url_set_max_redirects(yaz_url, max_redirects); + if (x_forwarded_for) + { + std::string peer_name2 = package.origin().get_address(); + const char *peer_name1 = + z_HTTP_header_lookup(hreq->headers, "X-Forwarded-For"); + std::string pcomb; + if (peer_name1) + { + pcomb.append(peer_name1); + pcomb.append(", "); + } + pcomb.append(peer_name2); + z_HTTP_header_set(o, &hreq->headers, "X-Forwarded-For", + pcomb.c_str()); + } std::string uri; if (hreq->path[0] == '/') { @@ -157,6 +174,10 @@ void mp::filter::HTTPClient::configure(const xmlNode * ptr, bool test_only, " in http_client filter"); } } + else if (!strcmp((const char *) ptr->name, "x-forwarded-for")) + { + m_p->x_forwarded_for = mp::xml::get_bool(ptr, 0); + } else { throw mp::filter::FilterException