Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
added Connection:close to all http requests in our http client to prevent CLOSE_WAIT states (as seen in lsof)
Michael Peter Christen87e9052081b8
diff --git a/source/net/yacy/cora/protocol/http/HTTPClient.java b/source/net/yacy/cora/protocol/http/HTTPClient.javaindex d1358385c..793c4f4cd 100644--- a/source/net/yacy/cora/protocol/http/HTTPClient.java+++ b/source/net/yacy/cora/protocol/http/HTTPClient.java@@ -86,6 +86,7 @@ import org.apache.http.impl.client.BasicCredentialsProvider;import org.apache.http.impl.client.DefaultHttpClient;import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;import org.apache.http.impl.conn.PoolingClientConnectionManager;+import org.apache.http.message.BasicHeader;import org.apache.http.message.BasicHeaderElementIterator;import org.apache.http.params.BasicHttpParams;import org.apache.http.params.HttpConnectionParams;@@ -344,6 +345,7 @@ public class HTTPClient {final boolean localhost = Domains.isLocalhost(url.getHost());final String urix = url.toNormalform(true);final HttpGet httpGet = new HttpGet(urix);+ httpGet.addHeader(new BasicHeader("Connection", "close")); // don't keep alive, prevent CLOSE_WAIT stateif (!localhost) setHost(url.getHost()); // overwrite resolved IP, needed for shared web hosting DO NOT REMOVE, see http://en.wikipedia.org/wiki/Shared_web_hosting_servicereturn getContentBytes(httpGet, url.getHost(), maxBytes);}@@ -360,6 +362,7 @@ public class HTTPClient {if (this.currentRequest != null) throw new IOException("Client is in use!");final MultiProtocolURI url = new MultiProtocolURI(uri);final HttpGet httpGet = new HttpGet(url.toNormalform(true));+ httpGet.addHeader(new BasicHeader("Connection", "close")); // don't keep alive, prevent CLOSE_WAIT statesetHost(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, url.getHost());@@ -375,6 +378,7 @@ public class HTTPClient {public HttpResponse HEADResponse(final String uri) throws IOException {final MultiProtocolURI url = new MultiProtocolURI(uri);final HttpHead httpHead = new HttpHead(url.toNormalform(true));+ httpHead.addHeader(new BasicHeader("Connection", "close")); // don't keep alive, prevent CLOSE_WAIT statesetHost(url.getHost()); // overwrite resolved IP, needed for shared web hosting DO NOT REMOVE, see http://en.wikipedia.org/wiki/Shared_web_hosting_serviceexecute(httpHead, url.getHost());finish();@@ -396,6 +400,7 @@ public class HTTPClient {if (this.currentRequest != null) throw new IOException("Client is in use!");final MultiProtocolURI url = new MultiProtocolURI(uri);final HttpPost httpPost = new HttpPost(url.toNormalform(true));+ httpPost.addHeader(new BasicHeader("Connection", "close")); // don't keep alive, prevent CLOSE_WAIT stateString host = url.getHost();if (host == null) host = Domains.LOCALHOST;setHost(host); // overwrite resolved IP, needed for shared web hosting DO NOT REMOVE, see http://en.wikipedia.org/wiki/Shared_web_hosting_service@@ -432,6 +437,7 @@ public class HTTPClient {*/public byte[] POSTbytes(final MultiProtocolURI url, final String vhost, final Map<String, ContentBody> post, final boolean usegzip) throws IOException {final HttpPost httpPost = new HttpPost(url.toNormalform(true));+ httpPost.addHeader(new BasicHeader("Connection", "close")); // don't keep alive, prevent CLOSE_WAIT statesetHost(vhost); // overwrite resolved IP, needed for shared web hosting DO NOT REMOVE, see http://en.wikipedia.org/wiki/Shared_web_hosting_serviceif (vhost == null) setHost(Domains.LOCALHOST);@@ -463,6 +469,7 @@ public class HTTPClient {public byte[] POSTbytes(final String uri, final InputStream instream, final long length) throws IOException {final MultiProtocolURI url = new MultiProtocolURI(uri);final HttpPost httpPost = new HttpPost(url.toNormalform(true));+ httpPost.addHeader(new BasicHeader("Connection", "close")); // don't keep alive, prevent CLOSE_WAIT stateString host = url.getHost();if (host == null) host = Domains.LOCALHOST;setHost(host); // overwrite resolved IP, needed for shared web hosting DO NOT REMOVE, see http://en.wikipedia.org/wiki/Shared_web_hosting_service