* so need to ensure that any items used in its equals/hashcode methods are
* not changed after use, i.e.:
* host, port, protocol, localAddress, proxy
*
*/
HostConfiguration hc = new HostConfiguration();
hc.setHost(host, port, protocol); // All needed to ensure re-usablility
// Set up the local address if one exists
final InetAddress inetAddr = getIpSourceAddress();
if (inetAddr != null) {// Use special field ip source address (for pseudo 'ip spoofing')
hc.setLocalAddress(inetAddr);
} else {
hc.setLocalAddress(localAddress); // null means use the default
}
final String proxyHost = getProxyHost();
final int proxyPort = getProxyPortInt();
boolean useStaticProxy = isStaticProxy(host);
boolean useDynamicProxy = isDynamicProxy(proxyHost, proxyPort);
if (useDynamicProxy){
hc.setProxy(proxyHost, proxyPort);
useStaticProxy = false; // Dynamic proxy overrules static proxy
} else if (useStaticProxy) {
if (log.isDebugEnabled()){
log.debug("Setting proxy: "+PROXY_HOST+":"+PROXY_PORT);
}
hc.setProxy(PROXY_HOST, PROXY_PORT);
}
Map<HostConfiguration, HttpClient> map = httpClients.get();
// N.B. HostConfiguration.equals() includes proxy settings in the compare.
HttpClient httpClient = map.get(hc);