Permalink
Browse files

use pre-defined "Connection" header key, replace depreceated

  • Loading branch information...
reger24 committed Mar 4, 2017
1 parent 5b03feb commit cd4d891ea4e03c946fbf10047f49fd012abe0b49
@@ -50,6 +50,7 @@
import org.apache.http.client.AuthCache;
import org.apache.http.client.entity.GzipDecompressingEntity;
import org.apache.http.impl.auth.BasicScheme;
import org.apache.http.protocol.HTTP;
import org.apache.http.protocol.HttpContext;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrClient;
@@ -140,7 +141,7 @@ protected HttpContext createHttpContext() {
BasicScheme basicAuth = new BasicScheme();
HttpHost targetHost = new HttpHost(u.getHost(), u.getPort(), u.getProtocol());
authCache.put(targetHost, basicAuth);
context.setAttribute(org.apache.http.client.protocol.ClientContext.AUTH_CACHE, authCache);
context.setAttribute(org.apache.http.client.protocol.HttpClientContext.AUTH_CACHE, authCache);
this.setHttpRequestRetryHandler(new org.apache.http.impl.client.DefaultHttpRequestRetryHandler(0, false)); // no retries needed; we expect connections to fail; therefore we should not retry
return context;
}
@@ -152,7 +153,7 @@ protected HttpContext createHttpContext() {
@Override
public void process(final HttpRequest request, final HttpContext context) throws IOException {
if (!request.containsHeader(HeaderFramework.ACCEPT_ENCODING)) request.addHeader(HeaderFramework.ACCEPT_ENCODING, HeaderFramework.CONTENT_ENCODING_GZIP);
if (!request.containsHeader("Connection")) request.addHeader("Connection", "close"); // prevent CLOSE_WAIT
if (!request.containsHeader(HTTP.CONN_DIRECTIVE)) request.addHeader(HTTP.CONN_DIRECTIVE, "close"); // prevent CLOSE_WAIT
}
});
@@ -852,7 +852,7 @@ private void setHeaders(final HttpUriRequest httpUriRequest) {
}
}
if (this.host != null) httpUriRequest.setHeader(HTTP.TARGET_HOST, this.host);
httpUriRequest.setHeader("Connection", "close"); // don't keep alive, prevent CLOSE_WAIT state
httpUriRequest.setHeader(HTTP.CONN_DIRECTIVE, "close"); // don't keep alive, prevent CLOSE_WAIT state
}
private void storeConnectionInfo(final HttpUriRequest httpUriRequest) {

0 comments on commit cd4d891

Please sign in to comment.