added nonProxyHosts to ProxyConfig to allow bypassing proxy for certain hosts

This commit is contained in:
Guenter Obiltschnig
2014-11-11 22:54:44 +01:00
parent b576a66c4b
commit 781acfa0bd
6 changed files with 63 additions and 16 deletions

View File

@@ -1,7 +1,7 @@
//
// HTTPClientSession.cpp
//
// $Id: //poco/1.4/Net/src/HTTPClientSession.cpp#11 $
// $Id: //poco/1.4/Net/src/HTTPClientSession.cpp#14 $
//
// Library: Net
// Package: HTTPClient
@@ -25,7 +25,7 @@
#include "Poco/Net/NetException.h"
#include "Poco/NumberFormatter.h"
#include "Poco/CountingStream.h"
#include "Poco/Base64Encoder.h"
#include "Poco/RegularExpression.h"
#include <sstream>
@@ -195,7 +195,7 @@ std::ostream& HTTPClientSession::sendRequest(HTTPRequest& request)
request.setKeepAlive(false);
if (!request.has(HTTPRequest::HOST))
request.setHost(_host, _port);
if (!_proxyConfig.host.empty())
if (!_proxyConfig.host.empty() && !bypassProxy())
{
request.setURI(proxyRequestPrefix() + request.getURI());
proxyAuthenticate(request);
@@ -327,7 +327,7 @@ int HTTPClientSession::write(const char* buffer, std::streamsize length)
void HTTPClientSession::reconnect()
{
if (_proxyConfig.host.empty())
if (_proxyConfig.host.empty() || bypassProxy())
{
SocketAddress addr(_host, _port);
connect(addr);
@@ -405,4 +405,14 @@ void HTTPClientSession::proxyTunnel()
}
bool HTTPClientSession::bypassProxy() const
{
if (!_proxyConfig.nonProxyHosts.empty())
{
return RegularExpression::match(_host, _proxyConfig.nonProxyHosts, RegularExpression::RE_CASELESS | RegularExpression::RE_ANCHORED);
}
else return false;
}
} } // namespace Poco::Net