Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
re-integrating useForHost method (lost sometime?) to get the noProxy pattern working again. Without using this method all remote urls including the localhost had been accessed through the configured proxy
orbiter1f33c30d7baa
diff --git a/source/net/yacy/cora/protocol/http/HTTPClient.java b/source/net/yacy/cora/protocol/http/HTTPClient.javaindex 4a71c382b..60fe7c94a 100644--- a/source/net/yacy/cora/protocol/http/HTTPClient.java+++ b/source/net/yacy/cora/protocol/http/HTTPClient.java@@ -49,6 +49,7 @@ import net.yacy.cora.protocol.ClientIdentification;import net.yacy.cora.protocol.ConnectionInfo;import net.yacy.cora.protocol.Domains;import net.yacy.cora.protocol.HeaderFramework;+import net.yacy.cora.protocol.http.ProxySettings.Protocol;import org.apache.http.Header;import org.apache.http.HeaderElement;@@ -342,7 +343,7 @@ public class HTTPClient {final String urix = url.toNormalform(true);final HttpGet httpGet = new HttpGet(urix);if (!localhost) setHost(url.getHost()); // overwrite resolved IP, needed for shared web hosting DO NOT REMOVE, see http://en.wikipedia.org/wiki/Shared_web_hosting_service- return getContentBytes(httpGet, maxBytes);+ return getContentBytes(httpGet, url.getHost(), maxBytes);}/**@@ -359,7 +360,7 @@ public class HTTPClient {final HttpGet httpGet = new HttpGet(url.toNormalform(true));setHost(url.getHost()); // overwrite resolved IP, needed for shared web hosting DO NOT REMOVE, see http://en.wikipedia.org/wiki/Shared_web_hosting_servicethis.currentRequest = httpGet;- execute(httpGet);+ execute(httpGet, url.getHost());}/**@@ -373,7 +374,7 @@ public class HTTPClient {final MultiProtocolURI url = new MultiProtocolURI(uri);final HttpHead httpHead = new HttpHead(url.toNormalform(true));setHost(url.getHost()); // overwrite resolved IP, needed for shared web hosting DO NOT REMOVE, see http://en.wikipedia.org/wiki/Shared_web_hosting_service- execute(httpHead);+ execute(httpHead, url.getHost());finish();ConnectionInfo.removeConnection(httpHead.hashCode());return this.httpResponse;@@ -401,7 +402,7 @@ public class HTTPClient {this.upbytes = length;httpPost.setEntity(inputStreamEntity);this.currentRequest = httpPost;- execute(httpPost);+ execute(httpPost, host);}/**@@ -445,7 +446,7 @@ public class HTTPClient {httpPost.setEntity(multipartEntity);}- return getContentBytes(httpPost, Integer.MAX_VALUE);+ return getContentBytes(httpPost, url.getHost(), Integer.MAX_VALUE);}/**@@ -468,7 +469,7 @@ public class HTTPClient {// statisticsthis.upbytes = length;httpPost.setEntity(inputStreamEntity);- return getContentBytes(httpPost, Integer.MAX_VALUE);+ return getContentBytes(httpPost, host, Integer.MAX_VALUE);}/**@@ -557,9 +558,9 @@ public class HTTPClient {}}- private byte[] getContentBytes(final HttpUriRequest httpUriRequest, final int maxBytes) throws IOException {+ private byte[] getContentBytes(final HttpUriRequest httpUriRequest, String host, final int maxBytes) throws IOException {try {- execute(httpUriRequest);+ execute(httpUriRequest, host);if (this.httpResponse == null) return null;// get the response bodyfinal HttpEntity httpEntity = this.httpResponse.getEntity();@@ -579,11 +580,11 @@ public class HTTPClient {}}- private void execute(final HttpUriRequest httpUriRequest) throws IOException {+ private void execute(final HttpUriRequest httpUriRequest, String host) throws IOException {final HttpContext httpContext = new BasicHttpContext();setHeaders(httpUriRequest);setParams(httpUriRequest.getParams());- setProxy(httpUriRequest.getParams());+ setProxy(httpUriRequest.getParams(), host);// statisticsstoreConnectionInfo(httpUriRequest);// execute the method; some asserts confirm that that the request can be send with Content-Length and is therefore not terminated by EOF@@ -656,8 +657,8 @@ public class HTTPClient {httpParams.setParameter(HTTP.TARGET_HOST, this.host);}- private static void setProxy(final HttpParams httpParams) {- if (ProxySettings.use)+ private static void setProxy(final HttpParams httpParams, String host) {+ if (ProxySettings.useForHost(host, Protocol.HTTP))ConnRouteParams.setDefaultProxy(httpParams, ProxySettings.getProxyHost());// TODO find a better way for thisProxySettings.setProxyCreds((DefaultHttpClient) httpClient);diff --git a/source/net/yacy/cora/protocol/http/ProxySettings.java b/source/net/yacy/cora/protocol/http/ProxySettings.javaindex 9ad6c30f6..2c891a32d 100644--- a/source/net/yacy/cora/protocol/http/ProxySettings.java+++ b/source/net/yacy/cora/protocol/http/ProxySettings.java@@ -41,25 +41,26 @@ public final class ProxySettings {// Dummy value to associate with an Object in the backing Mapprivate static final Object PRESENT = new Object();- public static boolean use = false, use4YaCy = false, use4ssl = false;+ public static enum Protocol {+ HTTP, HTTPS, YACY+ }++ private static boolean use = false, use4YaCy = false, use4ssl = false;public static String host = null, user = "", password = "";public static int port = 0;public static String[] noProxy = null;public static final Map<String, Object> allowProxy = new ConcurrentHashMap<String, Object>();public static final Map<String, Object> disallowProxy = new ConcurrentHashMap<String, Object>();--// /**-// * produce a HostConfiguration (apache object) with the proxy access information included-// * @param apacheHttpClient-// * @return a host configuration with proxy config if the proxy shall be used; a cloned configuration otherwise-// */-// public static HostConfiguration getProxyHostConfig(HttpClient apacheHttpClient) {-// final HostConfiguration hostConfig;-// if (!use) return null;-// hostConfig = new HostConfiguration(apacheHttpClient.getHostConfiguration());-// hostConfig.setProxy(host, port);-// return hostConfig;-// }++ public static void setProxyUse4HTTP(boolean use4http0) {+ use = use4http0;+ }+ public static void setProxyUse4HTTPS(boolean use4https0) {+ use4ssl = use4https0;+ }+ public static void setProxyUse4YaCy(boolean use4YaCy0) {+ use4YaCy = use4YaCy0;+ }/***@@ -82,8 +83,11 @@ public final class ProxySettings {* @param host* @return true, if the proxy shall be used for the given host*/- public static boolean useForHost(final String host) {- if (!use) return false;+ public static boolean useForHost(final String host, Protocol protocol) {+ assert protocol != null;+ if (protocol == Protocol.HTTP && !use) return false;+ if (protocol == Protocol.HTTPS && !use4ssl) return false;+ if (protocol == Protocol.YACY && !use4YaCy) return false;if (allowProxy.containsKey(host)) return true;if (disallowProxy.containsKey(host)) return false;for (String pattern: noProxy) {diff --git a/source/net/yacy/search/Switchboard.java b/source/net/yacy/search/Switchboard.javaindex 83a8ccc2d..fdad872c3 100644--- a/source/net/yacy/search/Switchboard.java+++ b/source/net/yacy/search/Switchboard.java@@ -3549,22 +3549,13 @@ public final class Switchboard extends serverSwitch {} catch ( final NumberFormatException e ) {port = 3128;}+// create new config- ProxySettings.use4ssl = true;- ProxySettings.use4YaCy = true;ProxySettings.port = port;ProxySettings.host = host;- ProxySettings.use = ((ProxySettings.host != null) && (ProxySettings.host.length() > 0));-- // determining if remote proxy usage is enabled- ProxySettings.use = getConfigBool("remoteProxyUse", false);-- // determining if remote proxy should be used for yacy -> yacy communication- ProxySettings.use4YaCy = getConfig("remoteProxyUse4Yacy", "true").equalsIgnoreCase("true");-- // determining if remote proxy should be used for ssl connections- ProxySettings.use4ssl = getConfig("remoteProxyUse4SSL", "true").equalsIgnoreCase("true");-+ ProxySettings.setProxyUse4HTTP(ProxySettings.host != null && ProxySettings.host.length() > 0 && getConfigBool("remoteProxyUse", false));+ ProxySettings.setProxyUse4YaCy(getConfig("remoteProxyUse4Yacy", "true").equalsIgnoreCase("true"));+ ProxySettings.setProxyUse4HTTPS(getConfig("remoteProxyUse4SSL", "true").equalsIgnoreCase("true"));ProxySettings.user = getConfig("remoteProxyUser", "").trim();ProxySettings.password = getConfig("remoteProxyPwd", "").trim();diff --git a/source/net/yacy/server/http/HTTPDProxyHandler.java b/source/net/yacy/server/http/HTTPDProxyHandler.javaindex d15143d39..c0cec40e4 100644--- a/source/net/yacy/server/http/HTTPDProxyHandler.java+++ b/source/net/yacy/server/http/HTTPDProxyHandler.java@@ -77,6 +77,7 @@ import net.yacy.cora.protocol.RequestHeader;import net.yacy.cora.protocol.ResponseHeader;import net.yacy.cora.protocol.http.HTTPClient;import net.yacy.cora.protocol.http.ProxySettings;+import net.yacy.cora.protocol.http.ProxySettings.Protocol;import net.yacy.crawler.data.Cache;import net.yacy.crawler.retrieval.Request;import net.yacy.crawler.retrieval.Response;@@ -1245,7 +1246,7 @@ public final class HTTPDProxyHandler {}// possibly branch into PROXY-PROXY connection- if (ProxySettings.use && ProxySettings.use4ssl) {+ if (ProxySettings.useForHost(host, Protocol.HTTPS)) {final HTTPClient remoteProxy = setupHttpClient(requestHeader, host);try {