View Javadoc
1   /*
2    * ====================================================================
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   * ====================================================================
20   *
21   * This software consists of voluntary contributions made by many
22   * individuals on behalf of the Apache Software Foundation.  For more
23   * information on the Apache Software Foundation, please see
24   * <http://www.apache.org/>.
25   *
26   */
27  
28  package org.apache.http.impl.client;
29  
30  import java.io.Closeable;
31  import java.io.IOException;
32  import java.net.ProxySelector;
33  import java.util.ArrayList;
34  import java.util.Collection;
35  import java.util.Collections;
36  import java.util.LinkedList;
37  import java.util.List;
38  import java.util.Map;
39  import java.util.concurrent.TimeUnit;
40  
41  import javax.net.ssl.HostnameVerifier;
42  import javax.net.ssl.SSLContext;
43  import javax.net.ssl.SSLSocketFactory;
44  
45  import org.apache.http.ConnectionReuseStrategy;
46  import org.apache.http.Header;
47  import org.apache.http.HttpHost;
48  import org.apache.http.HttpRequestInterceptor;
49  import org.apache.http.HttpResponseInterceptor;
50  import org.apache.http.auth.AuthSchemeProvider;
51  import org.apache.http.client.AuthenticationStrategy;
52  import org.apache.http.client.BackoffManager;
53  import org.apache.http.client.ConnectionBackoffStrategy;
54  import org.apache.http.client.CookieStore;
55  import org.apache.http.client.CredentialsProvider;
56  import org.apache.http.client.HttpRequestRetryHandler;
57  import org.apache.http.client.RedirectStrategy;
58  import org.apache.http.client.ServiceUnavailableRetryStrategy;
59  import org.apache.http.client.UserTokenHandler;
60  import org.apache.http.client.config.AuthSchemes;
61  import org.apache.http.client.config.RequestConfig;
62  import org.apache.http.client.entity.InputStreamFactory;
63  import org.apache.http.client.protocol.RequestAcceptEncoding;
64  import org.apache.http.client.protocol.RequestAddCookies;
65  import org.apache.http.client.protocol.RequestAuthCache;
66  import org.apache.http.client.protocol.RequestClientConnControl;
67  import org.apache.http.client.protocol.RequestDefaultHeaders;
68  import org.apache.http.client.protocol.RequestExpectContinue;
69  import org.apache.http.client.protocol.ResponseContentEncoding;
70  import org.apache.http.client.protocol.ResponseProcessCookies;
71  import org.apache.http.config.ConnectionConfig;
72  import org.apache.http.config.Lookup;
73  import org.apache.http.config.RegistryBuilder;
74  import org.apache.http.config.SocketConfig;
75  import org.apache.http.conn.ConnectionKeepAliveStrategy;
76  import org.apache.http.conn.DnsResolver;
77  import org.apache.http.conn.HttpClientConnectionManager;
78  import org.apache.http.conn.SchemePortResolver;
79  import org.apache.http.conn.routing.HttpRoutePlanner;
80  import org.apache.http.conn.socket.ConnectionSocketFactory;
81  import org.apache.http.conn.socket.LayeredConnectionSocketFactory;
82  import org.apache.http.conn.socket.PlainConnectionSocketFactory;
83  import org.apache.http.conn.ssl.DefaultHostnameVerifier;
84  import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
85  import org.apache.http.conn.ssl.X509HostnameVerifier;
86  import org.apache.http.conn.util.PublicSuffixMatcher;
87  import org.apache.http.conn.util.PublicSuffixMatcherLoader;
88  import org.apache.http.cookie.CookieSpecProvider;
89  import org.apache.http.impl.NoConnectionReuseStrategy;
90  import org.apache.http.impl.auth.BasicSchemeFactory;
91  import org.apache.http.impl.auth.DigestSchemeFactory;
92  import org.apache.http.impl.auth.KerberosSchemeFactory;
93  import org.apache.http.impl.auth.NTLMSchemeFactory;
94  import org.apache.http.impl.auth.SPNegoSchemeFactory;
95  import org.apache.http.impl.conn.DefaultProxyRoutePlanner;
96  import org.apache.http.impl.conn.DefaultRoutePlanner;
97  import org.apache.http.impl.conn.DefaultSchemePortResolver;
98  import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
99  import org.apache.http.impl.conn.SystemDefaultRoutePlanner;
100 import org.apache.http.impl.execchain.BackoffStrategyExec;
101 import org.apache.http.impl.execchain.ClientExecChain;
102 import org.apache.http.impl.execchain.MainClientExec;
103 import org.apache.http.impl.execchain.ProtocolExec;
104 import org.apache.http.impl.execchain.RedirectExec;
105 import org.apache.http.impl.execchain.RetryExec;
106 import org.apache.http.impl.execchain.ServiceUnavailableRetryExec;
107 import org.apache.http.protocol.HttpProcessor;
108 import org.apache.http.protocol.HttpProcessorBuilder;
109 import org.apache.http.protocol.HttpRequestExecutor;
110 import org.apache.http.protocol.ImmutableHttpProcessor;
111 import org.apache.http.protocol.RequestContent;
112 import org.apache.http.protocol.RequestTargetHost;
113 import org.apache.http.protocol.RequestUserAgent;
114 import org.apache.http.ssl.SSLContexts;
115 import org.apache.http.util.TextUtils;
116 import org.apache.http.util.VersionInfo;
117 
118 /**
119  * Builder for {@link CloseableHttpClient} instances.
120  * <p>
121  * When a particular component is not explicitly set this class will
122  * use its default implementation. System properties will be taken
123  * into account when configuring the default implementations when
124  * {@link #useSystemProperties()} method is called prior to calling
125  * {@link #build()}.
126  * </p>
127  * <ul>
128  *  <li>ssl.TrustManagerFactory.algorithm</li>
129  *  <li>javax.net.ssl.trustStoreType</li>
130  *  <li>javax.net.ssl.trustStore</li>
131  *  <li>javax.net.ssl.trustStoreProvider</li>
132  *  <li>javax.net.ssl.trustStorePassword</li>
133  *  <li>ssl.KeyManagerFactory.algorithm</li>
134  *  <li>javax.net.ssl.keyStoreType</li>
135  *  <li>javax.net.ssl.keyStore</li>
136  *  <li>javax.net.ssl.keyStoreProvider</li>
137  *  <li>javax.net.ssl.keyStorePassword</li>
138  *  <li>https.protocols</li>
139  *  <li>https.cipherSuites</li>
140  *  <li>http.proxyHost</li>
141  *  <li>http.proxyPort</li>
142  *  <li>https.proxyHost</li>
143  *  <li>https.proxyPort</li>
144  *  <li>http.nonProxyHosts</li>
145  *  <li>http.keepAlive</li>
146  *  <li>http.maxConnections</li>
147  *  <li>http.agent</li>
148  * </ul>
149  * <p>
150  * Please note that some settings used by this class can be mutually
151  * exclusive and may not apply when building {@link CloseableHttpClient}
152  * instances.
153  * </p>
154  *
155  * @since 4.3
156  */
157 public class HttpClientBuilder {
158 
159     private HttpRequestExecutor requestExec;
160     private HostnameVerifier hostnameVerifier;
161     private LayeredConnectionSocketFactory sslSocketFactory;
162     private SSLContext sslContext;
163     private HttpClientConnectionManager connManager;
164     private boolean connManagerShared;
165     private SchemePortResolver schemePortResolver;
166     private ConnectionReuseStrategy reuseStrategy;
167     private ConnectionKeepAliveStrategy keepAliveStrategy;
168     private AuthenticationStrategy targetAuthStrategy;
169     private AuthenticationStrategy proxyAuthStrategy;
170     private UserTokenHandler userTokenHandler;
171     private HttpProcessor httpprocessor;
172     private DnsResolver dnsResolver;
173 
174     private LinkedList<HttpRequestInterceptor> requestFirst;
175     private LinkedList<HttpRequestInterceptor> requestLast;
176     private LinkedList<HttpResponseInterceptor> responseFirst;
177     private LinkedList<HttpResponseInterceptor> responseLast;
178 
179     private HttpRequestRetryHandler retryHandler;
180     private HttpRoutePlanner routePlanner;
181     private RedirectStrategy redirectStrategy;
182     private ConnectionBackoffStrategy connectionBackoffStrategy;
183     private BackoffManager backoffManager;
184     private ServiceUnavailableRetryStrategy serviceUnavailStrategy;
185     private Lookup<AuthSchemeProvider> authSchemeRegistry;
186     private Lookup<CookieSpecProvider> cookieSpecRegistry;
187     private Map<String, InputStreamFactory> contentDecoderMap;
188     private CookieStore cookieStore;
189     private CredentialsProvider credentialsProvider;
190     private String userAgent;
191     private HttpHost proxy;
192     private Collection<? extends Header> defaultHeaders;
193     private SocketConfig defaultSocketConfig;
194     private ConnectionConfig defaultConnectionConfig;
195     private RequestConfig defaultRequestConfig;
196     private boolean evictExpiredConnections;
197     private boolean evictIdleConnections;
198     private long maxIdleTime;
199     private TimeUnit maxIdleTimeUnit;
200 
201     private boolean systemProperties;
202     private boolean redirectHandlingDisabled;
203     private boolean automaticRetriesDisabled;
204     private boolean contentCompressionDisabled;
205     private boolean cookieManagementDisabled;
206     private boolean authCachingDisabled;
207     private boolean connectionStateDisabled;
208     private boolean defaultUserAgentDisabled;
209 
210     private int maxConnTotal = 0;
211     private int maxConnPerRoute = 0;
212 
213     private long connTimeToLive = -1;
214     private TimeUnit connTimeToLiveTimeUnit = TimeUnit.MILLISECONDS;
215 
216     private List<Closeable> closeables;
217 
218     private PublicSuffixMatcher publicSuffixMatcher;
219 
220     public static HttpClientBuilder create() {
221         return new HttpClientBuilder();
222     }
223 
224     protected HttpClientBuilder() {
225         super();
226     }
227 
228     /**
229      * Assigns {@link HttpRequestExecutor} instance.
230      */
231     public final HttpClientBuilder setRequestExecutor(final HttpRequestExecutor requestExec) {
232         this.requestExec = requestExec;
233         return this;
234     }
235 
236     /**
237      * Assigns {@link X509HostnameVerifier} instance.
238      * <p>
239      * Please note this value can be overridden by the {@link #setConnectionManager(
240      *   org.apache.http.conn.HttpClientConnectionManager)} and the {@link #setSSLSocketFactory(
241      *   org.apache.http.conn.socket.LayeredConnectionSocketFactory)} methods.
242      * </p>
243      *
244      *   @deprecated (4.4)
245      */
246     @Deprecated
247     public final HttpClientBuilder setHostnameVerifier(final X509HostnameVerifier hostnameVerifier) {
248         this.hostnameVerifier = hostnameVerifier;
249         return this;
250     }
251 
252     /**
253      * Assigns {@link javax.net.ssl.HostnameVerifier} instance.
254      * <p>
255      * Please note this value can be overridden by the {@link #setConnectionManager(
256      *   org.apache.http.conn.HttpClientConnectionManager)} and the {@link #setSSLSocketFactory(
257      *   org.apache.http.conn.socket.LayeredConnectionSocketFactory)} methods.
258      * </p>
259      *
260      *   @since 4.4
261      */
262     public final HttpClientBuilder setSSLHostnameVerifier(final HostnameVerifier hostnameVerifier) {
263         this.hostnameVerifier = hostnameVerifier;
264         return this;
265     }
266 
267     /**
268      * Assigns file containing public suffix matcher. Instances of this class can be created
269      * with {@link org.apache.http.conn.util.PublicSuffixMatcherLoader}.
270      *
271      * @see org.apache.http.conn.util.PublicSuffixMatcher
272      * @see org.apache.http.conn.util.PublicSuffixMatcherLoader
273      *
274      *   @since 4.4
275      */
276     public final HttpClientBuilder setPublicSuffixMatcher(final PublicSuffixMatcher publicSuffixMatcher) {
277         this.publicSuffixMatcher = publicSuffixMatcher;
278         return this;
279     }
280 
281     /**
282      * Assigns {@link SSLContext} instance.
283      * <p>
284      * Please note this value can be overridden by the {@link #setConnectionManager(
285      *   org.apache.http.conn.HttpClientConnectionManager)} and the {@link #setSSLSocketFactory(
286      *   org.apache.http.conn.socket.LayeredConnectionSocketFactory)} methods.
287      * </p>
288      *
289      * @deprecated (4.5) use {@link #setSSLContext(SSLContext)}
290      */
291     @Deprecated
292     public final HttpClientBuilder setSslcontext(final SSLContext sslcontext) {
293         return setSSLContext(sslcontext);
294     }
295 
296     /**
297      * Assigns {@link SSLContext} instance.
298      * <p>
299      * Please note this value can be overridden by the {@link #setConnectionManager(
300      *   org.apache.http.conn.HttpClientConnectionManager)} and the {@link #setSSLSocketFactory(
301      *   org.apache.http.conn.socket.LayeredConnectionSocketFactory)} methods.
302      * </p>
303      */
304     public final HttpClientBuilder setSSLContext(final SSLContext sslContext) {
305         this.sslContext = sslContext;
306         return this;
307     }
308 
309     /**
310      * Assigns {@link LayeredConnectionSocketFactory} instance.
311      * <p>
312      * Please note this value can be overridden by the {@link #setConnectionManager(
313      *   org.apache.http.conn.HttpClientConnectionManager)} method.
314      * </p>
315      */
316     public final HttpClientBuilder setSSLSocketFactory(
317             final LayeredConnectionSocketFactory sslSocketFactory) {
318         this.sslSocketFactory = sslSocketFactory;
319         return this;
320     }
321 
322     /**
323      * Assigns maximum total connection value.
324      * <p>
325      * Please note this value can be overridden by the {@link #setConnectionManager(
326      *   org.apache.http.conn.HttpClientConnectionManager)} method.
327      * </p>
328      */
329     public final HttpClientBuilder setMaxConnTotal(final int maxConnTotal) {
330         this.maxConnTotal = maxConnTotal;
331         return this;
332     }
333 
334     /**
335      * Assigns maximum connection per route value.
336      * <p>
337      * Please note this value can be overridden by the {@link #setConnectionManager(
338      *   org.apache.http.conn.HttpClientConnectionManager)} method.
339      * </p>
340      */
341     public final HttpClientBuilder setMaxConnPerRoute(final int maxConnPerRoute) {
342         this.maxConnPerRoute = maxConnPerRoute;
343         return this;
344     }
345 
346     /**
347      * Assigns default {@link SocketConfig}.
348      * <p>
349      * Please note this value can be overridden by the {@link #setConnectionManager(
350      *   org.apache.http.conn.HttpClientConnectionManager)} method.
351      * </p>
352      */
353     public final HttpClientBuilder setDefaultSocketConfig(final SocketConfig config) {
354         this.defaultSocketConfig = config;
355         return this;
356     }
357 
358     /**
359      * Assigns default {@link ConnectionConfig}.
360      * <p>
361      * Please note this value can be overridden by the {@link #setConnectionManager(
362      *   org.apache.http.conn.HttpClientConnectionManager)} method.
363      * </p>
364      */
365     public final HttpClientBuilder setDefaultConnectionConfig(final ConnectionConfig config) {
366         this.defaultConnectionConfig = config;
367         return this;
368     }
369 
370     /**
371      * Sets maximum time to live for persistent connections
372      * <p>
373      * Please note this value can be overridden by the {@link #setConnectionManager(
374      *   org.apache.http.conn.HttpClientConnectionManager)} method.
375      * </p>
376      *
377      * @since 4.4
378      */
379     public final HttpClientBuilder setConnectionTimeToLive(final long connTimeToLive, final TimeUnit connTimeToLiveTimeUnit) {
380         this.connTimeToLive = connTimeToLive;
381         this.connTimeToLiveTimeUnit = connTimeToLiveTimeUnit;
382         return this;
383     }
384 
385     /**
386      * Assigns {@link HttpClientConnectionManager} instance.
387      */
388     public final HttpClientBuilder setConnectionManager(
389             final HttpClientConnectionManager connManager) {
390         this.connManager = connManager;
391         return this;
392     }
393 
394     /**
395      * Defines the connection manager is to be shared by multiple
396      * client instances.
397      * <p>
398      * If the connection manager is shared its life-cycle is expected
399      * to be managed by the caller and it will not be shut down
400      * if the client is closed.
401      * </p>
402      *
403      * @param shared defines whether or not the connection manager can be shared
404      *  by multiple clients.
405      *
406      * @since 4.4
407      */
408     public final HttpClientBuilder setConnectionManagerShared(
409             final boolean shared) {
410         this.connManagerShared = shared;
411         return this;
412     }
413 
414     /**
415      * Assigns {@link ConnectionReuseStrategy} instance.
416      */
417     public final HttpClientBuilder setConnectionReuseStrategy(
418             final ConnectionReuseStrategy reuseStrategy) {
419         this.reuseStrategy = reuseStrategy;
420         return this;
421     }
422 
423     /**
424      * Assigns {@link ConnectionKeepAliveStrategy} instance.
425      */
426     public final HttpClientBuilder setKeepAliveStrategy(
427             final ConnectionKeepAliveStrategy keepAliveStrategy) {
428         this.keepAliveStrategy = keepAliveStrategy;
429         return this;
430     }
431 
432     /**
433      * Assigns {@link AuthenticationStrategy} instance for target
434      * host authentication.
435      */
436     public final HttpClientBuilder setTargetAuthenticationStrategy(
437             final AuthenticationStrategy targetAuthStrategy) {
438         this.targetAuthStrategy = targetAuthStrategy;
439         return this;
440     }
441 
442     /**
443      * Assigns {@link AuthenticationStrategy} instance for proxy
444      * authentication.
445      */
446     public final HttpClientBuilder setProxyAuthenticationStrategy(
447             final AuthenticationStrategy proxyAuthStrategy) {
448         this.proxyAuthStrategy = proxyAuthStrategy;
449         return this;
450     }
451 
452     /**
453      * Assigns {@link UserTokenHandler} instance.
454      * <p>
455      * Please note this value can be overridden by the {@link #disableConnectionState()}
456      * method.
457      * </p>
458      */
459     public final HttpClientBuilder setUserTokenHandler(final UserTokenHandler userTokenHandler) {
460         this.userTokenHandler = userTokenHandler;
461         return this;
462     }
463 
464     /**
465      * Disables connection state tracking.
466      */
467     public final HttpClientBuilder disableConnectionState() {
468         connectionStateDisabled = true;
469         return this;
470     }
471 
472     /**
473      * Assigns {@link SchemePortResolver} instance.
474      */
475     public final HttpClientBuilder setSchemePortResolver(
476             final SchemePortResolver schemePortResolver) {
477         this.schemePortResolver = schemePortResolver;
478         return this;
479     }
480 
481     /**
482      * Assigns {@code User-Agent} value.
483      * <p>
484      * Please note this value can be overridden by the {@link #setHttpProcessor(
485      * org.apache.http.protocol.HttpProcessor)} method.
486      * </p>
487      */
488     public final HttpClientBuilder setUserAgent(final String userAgent) {
489         this.userAgent = userAgent;
490         return this;
491     }
492 
493     /**
494      * Assigns default request header values.
495      * <p>
496      * Please note this value can be overridden by the {@link #setHttpProcessor(
497      * org.apache.http.protocol.HttpProcessor)} method.
498      * </p>
499      */
500     public final HttpClientBuilder setDefaultHeaders(final Collection<? extends Header> defaultHeaders) {
501         this.defaultHeaders = defaultHeaders;
502         return this;
503     }
504 
505     /**
506      * Adds this protocol interceptor to the head of the protocol processing list.
507      * <p>
508      * Please note this value can be overridden by the {@link #setHttpProcessor(
509      * org.apache.http.protocol.HttpProcessor)} method.
510      * </p>
511      */
512     public final HttpClientBuilder addInterceptorFirst(final HttpResponseInterceptor itcp) {
513         if (itcp == null) {
514             return this;
515         }
516         if (responseFirst == null) {
517             responseFirst = new LinkedList<HttpResponseInterceptor>();
518         }
519         responseFirst.addFirst(itcp);
520         return this;
521     }
522 
523     /**
524      * Adds this protocol interceptor to the tail of the protocol processing list.
525      * <p>
526      * Please note this value can be overridden by the {@link #setHttpProcessor(
527      * org.apache.http.protocol.HttpProcessor)} method.
528      * </p>
529      */
530     public final HttpClientBuilder addInterceptorLast(final HttpResponseInterceptor itcp) {
531         if (itcp == null) {
532             return this;
533         }
534         if (responseLast == null) {
535             responseLast = new LinkedList<HttpResponseInterceptor>();
536         }
537         responseLast.addLast(itcp);
538         return this;
539     }
540 
541     /**
542      * Adds this protocol interceptor to the head of the protocol processing list.
543      * <p>
544      * Please note this value can be overridden by the {@link #setHttpProcessor(
545      * org.apache.http.protocol.HttpProcessor)} method.
546      */
547     public final HttpClientBuilder addInterceptorFirst(final HttpRequestInterceptor itcp) {
548         if (itcp == null) {
549             return this;
550         }
551         if (requestFirst == null) {
552             requestFirst = new LinkedList<HttpRequestInterceptor>();
553         }
554         requestFirst.addFirst(itcp);
555         return this;
556     }
557 
558     /**
559      * Adds this protocol interceptor to the tail of the protocol processing list.
560      * <p>
561      * Please note this value can be overridden by the {@link #setHttpProcessor(
562      * org.apache.http.protocol.HttpProcessor)} method.
563      */
564     public final HttpClientBuilder addInterceptorLast(final HttpRequestInterceptor itcp) {
565         if (itcp == null) {
566             return this;
567         }
568         if (requestLast == null) {
569             requestLast = new LinkedList<HttpRequestInterceptor>();
570         }
571         requestLast.addLast(itcp);
572         return this;
573     }
574 
575     /**
576      * Disables state (cookie) management.
577      * <p>
578      * Please note this value can be overridden by the {@link #setHttpProcessor(
579      * org.apache.http.protocol.HttpProcessor)} method.
580      */
581     public final HttpClientBuilder disableCookieManagement() {
582         this.cookieManagementDisabled = true;
583         return this;
584     }
585 
586     /**
587      * Disables automatic content decompression.
588      * <p>
589      * Please note this value can be overridden by the {@link #setHttpProcessor(
590      * org.apache.http.protocol.HttpProcessor)} method.
591      */
592     public final HttpClientBuilder disableContentCompression() {
593         contentCompressionDisabled = true;
594         return this;
595     }
596 
597     /**
598      * Disables authentication scheme caching.
599      * <p>
600      * Please note this value can be overridden by the {@link #setHttpProcessor(
601      * org.apache.http.protocol.HttpProcessor)} method.
602      */
603     public final HttpClientBuilder disableAuthCaching() {
604         this.authCachingDisabled = true;
605         return this;
606     }
607 
608     /**
609      * Assigns {@link HttpProcessor} instance.
610      */
611     public final HttpClientBuilder setHttpProcessor(final HttpProcessor httpprocessor) {
612         this.httpprocessor = httpprocessor;
613         return this;
614     }
615 
616     /**
617      * Assigns {@link DnsResolver} instance.
618      * <p>
619      * Please note this value can be overridden by the {@link #setConnectionManager(HttpClientConnectionManager)} method.
620      */
621     public final HttpClientBuilder setDnsResolver(final DnsResolver dnsResolver) {
622         this.dnsResolver = dnsResolver;
623         return this;
624     }
625 
626     /**
627      * Assigns {@link HttpRequestRetryHandler} instance.
628      * <p>
629      * Please note this value can be overridden by the {@link #disableAutomaticRetries()}
630      * method.
631      */
632     public final HttpClientBuilder setRetryHandler(final HttpRequestRetryHandler retryHandler) {
633         this.retryHandler = retryHandler;
634         return this;
635     }
636 
637     /**
638      * Disables automatic request recovery and re-execution.
639      */
640     public final HttpClientBuilder disableAutomaticRetries() {
641         automaticRetriesDisabled = true;
642         return this;
643     }
644 
645     /**
646      * Assigns default proxy value.
647      * <p>
648      * Please note this value can be overridden by the {@link #setRoutePlanner(
649      *   org.apache.http.conn.routing.HttpRoutePlanner)} method.
650      */
651     public final HttpClientBuilder setProxy(final HttpHost proxy) {
652         this.proxy = proxy;
653         return this;
654     }
655 
656     /**
657      * Assigns {@link HttpRoutePlanner} instance.
658      */
659     public final HttpClientBuilder setRoutePlanner(final HttpRoutePlanner routePlanner) {
660         this.routePlanner = routePlanner;
661         return this;
662     }
663 
664     /**
665      * Assigns {@link RedirectStrategy} instance.
666      * <p>
667      * Please note this value can be overridden by the {@link #disableRedirectHandling()}
668      * method.
669      * </p>
670 `     */
671     public final HttpClientBuilder setRedirectStrategy(final RedirectStrategy redirectStrategy) {
672         this.redirectStrategy = redirectStrategy;
673         return this;
674     }
675 
676     /**
677      * Disables automatic redirect handling.
678      */
679     public final HttpClientBuilder disableRedirectHandling() {
680         redirectHandlingDisabled = true;
681         return this;
682     }
683 
684     /**
685      * Assigns {@link ConnectionBackoffStrategy} instance.
686      */
687     public final HttpClientBuilder setConnectionBackoffStrategy(
688             final ConnectionBackoffStrategy connectionBackoffStrategy) {
689         this.connectionBackoffStrategy = connectionBackoffStrategy;
690         return this;
691     }
692 
693     /**
694      * Assigns {@link BackoffManager} instance.
695      */
696     public final HttpClientBuilder setBackoffManager(final BackoffManager backoffManager) {
697         this.backoffManager = backoffManager;
698         return this;
699     }
700 
701     /**
702      * Assigns {@link ServiceUnavailableRetryStrategy} instance.
703      */
704     public final HttpClientBuilder setServiceUnavailableRetryStrategy(
705             final ServiceUnavailableRetryStrategy serviceUnavailStrategy) {
706         this.serviceUnavailStrategy = serviceUnavailStrategy;
707         return this;
708     }
709 
710     /**
711      * Assigns default {@link CookieStore} instance which will be used for
712      * request execution if not explicitly set in the client execution context.
713      */
714     public final HttpClientBuilder setDefaultCookieStore(final CookieStore cookieStore) {
715         this.cookieStore = cookieStore;
716         return this;
717     }
718 
719     /**
720      * Assigns default {@link CredentialsProvider} instance which will be used
721      * for request execution if not explicitly set in the client execution
722      * context.
723      */
724     public final HttpClientBuilder setDefaultCredentialsProvider(
725             final CredentialsProvider credentialsProvider) {
726         this.credentialsProvider = credentialsProvider;
727         return this;
728     }
729 
730     /**
731      * Assigns default {@link org.apache.http.auth.AuthScheme} registry which will
732      * be used for request execution if not explicitly set in the client execution
733      * context.
734      */
735     public final HttpClientBuilder setDefaultAuthSchemeRegistry(
736             final Lookup<AuthSchemeProvider> authSchemeRegistry) {
737         this.authSchemeRegistry = authSchemeRegistry;
738         return this;
739     }
740 
741     /**
742      * Assigns default {@link org.apache.http.cookie.CookieSpec} registry which will
743      * be used for request execution if not explicitly set in the client execution
744      * context.
745      *
746      * @see org.apache.http.impl.client.CookieSpecRegistries
747      *
748      */
749     public final HttpClientBuilder setDefaultCookieSpecRegistry(
750             final Lookup<CookieSpecProvider> cookieSpecRegistry) {
751         this.cookieSpecRegistry = cookieSpecRegistry;
752         return this;
753     }
754 
755 
756     /**
757      * Assigns a map of {@link org.apache.http.client.entity.InputStreamFactory}s
758      * to be used for automatic content decompression.
759      */
760     public final HttpClientBuilder setContentDecoderRegistry(
761             final Map<String, InputStreamFactory> contentDecoderMap) {
762         this.contentDecoderMap = contentDecoderMap;
763         return this;
764     }
765 
766     /**
767      * Assigns default {@link RequestConfig} instance which will be used
768      * for request execution if not explicitly set in the client execution
769      * context.
770      */
771     public final HttpClientBuilder setDefaultRequestConfig(final RequestConfig config) {
772         this.defaultRequestConfig = config;
773         return this;
774     }
775 
776     /**
777      * Use system properties when creating and configuring default
778      * implementations.
779      */
780     public final HttpClientBuilder useSystemProperties() {
781         this.systemProperties = true;
782         return this;
783     }
784 
785     /**
786      * Makes this instance of HttpClient proactively evict expired connections from the
787      * connection pool using a background thread.
788      * <p>
789      * One MUST explicitly close HttpClient with {@link CloseableHttpClient#close()} in order
790      * to stop and release the background thread.
791      * <p>
792      * Please note this method has no effect if the instance of HttpClient is configuted to
793      * use a shared connection manager.
794      * <p>
795      * Please note this method may not be used when the instance of HttpClient is created
796      * inside an EJB container.
797      *
798      * @see #setConnectionManagerShared(boolean)
799      * @see org.apache.http.conn.HttpClientConnectionManager#closeExpiredConnections()
800      *
801      * @since 4.4
802      */
803     public final HttpClientBuilder evictExpiredConnections() {
804         evictExpiredConnections = true;
805         return this;
806     }
807 
808     /**
809      * Makes this instance of HttpClient proactively evict idle connections from the
810      * connection pool using a background thread.
811      * <p>
812      * One MUST explicitly close HttpClient with {@link CloseableHttpClient#close()} in order
813      * to stop and release the background thread.
814      * <p>
815      * Please note this method has no effect if the instance of HttpClient is configuted to
816      * use a shared connection manager.
817      * <p>
818      * Please note this method may not be used when the instance of HttpClient is created
819      * inside an EJB container.
820      *
821      * @see #setConnectionManagerShared(boolean)
822      * @see org.apache.http.conn.HttpClientConnectionManager#closeExpiredConnections()
823      *
824      * @param maxIdleTime maximum time persistent connections can stay idle while kept alive
825      * in the connection pool. Connections whose inactivity period exceeds this value will
826      * get closed and evicted from the pool.
827      * @param maxIdleTimeUnit time unit for the above parameter.
828      *
829      * @deprecated (4.5) use {@link #evictIdleConnections(long, TimeUnit)}
830      *
831      * @since 4.4
832      */
833     @Deprecated
834     public final HttpClientBuilder evictIdleConnections(final Long maxIdleTime, final TimeUnit maxIdleTimeUnit) {
835         return evictIdleConnections(maxIdleTime.longValue(), maxIdleTimeUnit);
836     }
837 
838     /**
839      * Makes this instance of HttpClient proactively evict idle connections from the
840      * connection pool using a background thread.
841      * <p>
842      * One MUST explicitly close HttpClient with {@link CloseableHttpClient#close()} in order
843      * to stop and release the background thread.
844      * <p>
845      * Please note this method has no effect if the instance of HttpClient is configuted to
846      * use a shared connection manager.
847      * <p>
848      * Please note this method may not be used when the instance of HttpClient is created
849      * inside an EJB container.
850      *
851      * @see #setConnectionManagerShared(boolean)
852      * @see org.apache.http.conn.HttpClientConnectionManager#closeExpiredConnections()
853      *
854      * @param maxIdleTime maximum time persistent connections can stay idle while kept alive
855      * in the connection pool. Connections whose inactivity period exceeds this value will
856      * get closed and evicted from the pool.
857      * @param maxIdleTimeUnit time unit for the above parameter.
858      *
859      * @since 4.4
860      */
861     public final HttpClientBuilder evictIdleConnections(final long maxIdleTime, final TimeUnit maxIdleTimeUnit) {
862         this.evictIdleConnections = true;
863         this.maxIdleTime = maxIdleTime;
864         this.maxIdleTimeUnit = maxIdleTimeUnit;
865         return this;
866     }
867 
868     /**
869      * Disables the default user agent set by this builder if none has been provided by the user.
870      *
871      * @since 4.5.7
872      */
873     public final HttpClientBuilder disableDefaultUserAgent() {
874         this.defaultUserAgentDisabled = true;
875         return this;
876     }
877 
878     /**
879      * Produces an instance of {@link ClientExecChain} to be used as a main exec.
880      * <p>
881      * Default implementation produces an instance of {@link MainClientExec}
882      * </p>
883      * <p>
884      * For internal use.
885      * </p>
886      *
887      * @since 4.4
888      */
889     protected ClientExecChain createMainExec(
890             final HttpRequestExecutor requestExec,
891             final HttpClientConnectionManager connManager,
892             final ConnectionReuseStrategy reuseStrategy,
893             final ConnectionKeepAliveStrategy keepAliveStrategy,
894             final HttpProcessor proxyHttpProcessor,
895             final AuthenticationStrategy targetAuthStrategy,
896             final AuthenticationStrategy proxyAuthStrategy,
897             final UserTokenHandler userTokenHandler)
898     {
899         return new MainClientExec(
900                 requestExec,
901                 connManager,
902                 reuseStrategy,
903                 keepAliveStrategy,
904                 proxyHttpProcessor,
905                 targetAuthStrategy,
906                 proxyAuthStrategy,
907                 userTokenHandler);
908     }
909 
910     /**
911      * For internal use.
912      */
913     protected ClientExecChainin.html#ClientExecChain">ClientExecChain decorateMainExec(final ClientExecChain mainExec) {
914         return mainExec;
915     }
916 
917     /**
918      * For internal use.
919      */
920     protected ClientExecChaintml#ClientExecChain">ClientExecChain decorateProtocolExec(final ClientExecChain protocolExec) {
921         return protocolExec;
922     }
923 
924     /**
925      * For internal use.
926      */
927     protected void addCloseable(final Closeable closeable) {
928         if (closeable == null) {
929             return;
930         }
931         if (closeables == null) {
932             closeables = new ArrayList<Closeable>();
933         }
934         closeables.add(closeable);
935     }
936 
937     private static String[] split(final String s) {
938         if (TextUtils.isBlank(s)) {
939             return null;
940         }
941         return s.split(" *, *");
942     }
943 
944     public CloseableHttpClient build() {
945         // Create main request executor
946         // We copy the instance fields to avoid changing them, and rename to avoid accidental use of the wrong version
947         PublicSuffixMatcher publicSuffixMatcherCopy = this.publicSuffixMatcher;
948         if (publicSuffixMatcherCopy == null) {
949             publicSuffixMatcherCopy = PublicSuffixMatcherLoader.getDefault();
950         }
951 
952         HttpRequestExecutor requestExecCopy = this.requestExec;
953         if (requestExecCopy == null) {
954             requestExecCopy = new HttpRequestExecutor();
955         }
956         HttpClientConnectionManager connManagerCopy = this.connManager;
957         if (connManagerCopy == null) {
958             LayeredConnectionSocketFactory sslSocketFactoryCopy = this.sslSocketFactory;
959             if (sslSocketFactoryCopy == null) {
960                 final String[] supportedProtocols = systemProperties ? split(
961                         System.getProperty("https.protocols")) : null;
962                 final String[] supportedCipherSuites = systemProperties ? split(
963                         System.getProperty("https.cipherSuites")) : null;
964                 HostnameVerifier hostnameVerifierCopy = this.hostnameVerifier;
965                 if (hostnameVerifierCopy == null) {
966                     hostnameVerifierCopy = new DefaultHostnameVerifier(publicSuffixMatcherCopy);
967                 }
968                 if (sslContext != null) {
969                     sslSocketFactoryCopy = new SSLConnectionSocketFactory(
970                             sslContext, supportedProtocols, supportedCipherSuites, hostnameVerifierCopy);
971                 } else {
972                     if (systemProperties) {
973                         sslSocketFactoryCopy = new SSLConnectionSocketFactory(
974                                 (SSLSocketFactory) SSLSocketFactory.getDefault(),
975                                 supportedProtocols, supportedCipherSuites, hostnameVerifierCopy);
976                     } else {
977                         sslSocketFactoryCopy = new SSLConnectionSocketFactory(
978                                 SSLContexts.createDefault(),
979                                 hostnameVerifierCopy);
980                     }
981                 }
982             }
983             @SuppressWarnings("resource")
984             final PoolingHttpClientConnectionManagerger.html#PoolingHttpClientConnectionManager">PoolingHttpClientConnectionManager poolingmgr = new PoolingHttpClientConnectionManager(
985                     RegistryBuilder.<ConnectionSocketFactory>create()
986                         .register("http", PlainConnectionSocketFactory.getSocketFactory())
987                         .register("https", sslSocketFactoryCopy)
988                         .build(),
989                     null,
990                     null,
991                     dnsResolver,
992                     connTimeToLive,
993                     connTimeToLiveTimeUnit != null ? connTimeToLiveTimeUnit : TimeUnit.MILLISECONDS);
994             if (defaultSocketConfig != null) {
995                 poolingmgr.setDefaultSocketConfig(defaultSocketConfig);
996             }
997             if (defaultConnectionConfig != null) {
998                 poolingmgr.setDefaultConnectionConfig(defaultConnectionConfig);
999             }
1000             if (systemProperties) {
1001                 String s = System.getProperty("http.keepAlive", "true");
1002                 if ("true".equalsIgnoreCase(s)) {
1003                     s = System.getProperty("http.maxConnections", "5");
1004                     final int max = Integer.parseInt(s);
1005                     poolingmgr.setDefaultMaxPerRoute(max);
1006                     poolingmgr.setMaxTotal(2 * max);
1007                 }
1008             }
1009             if (maxConnTotal > 0) {
1010                 poolingmgr.setMaxTotal(maxConnTotal);
1011             }
1012             if (maxConnPerRoute > 0) {
1013                 poolingmgr.setDefaultMaxPerRoute(maxConnPerRoute);
1014             }
1015             connManagerCopy = poolingmgr;
1016         }
1017         ConnectionReuseStrategy reuseStrategyCopy = this.reuseStrategy;
1018         if (reuseStrategyCopy == null) {
1019             if (systemProperties) {
1020                 final String s = System.getProperty("http.keepAlive", "true");
1021                 if ("true".equalsIgnoreCase(s)) {
1022                     reuseStrategyCopy = DefaultClientConnectionReuseStrategy.INSTANCE;
1023                 } else {
1024                     reuseStrategyCopy = NoConnectionReuseStrategy.INSTANCE;
1025                 }
1026             } else {
1027                 reuseStrategyCopy = DefaultClientConnectionReuseStrategy.INSTANCE;
1028             }
1029         }
1030         ConnectionKeepAliveStrategy keepAliveStrategyCopy = this.keepAliveStrategy;
1031         if (keepAliveStrategyCopy == null) {
1032             keepAliveStrategyCopy = DefaultConnectionKeepAliveStrategy.INSTANCE;
1033         }
1034         AuthenticationStrategy targetAuthStrategyCopy = this.targetAuthStrategy;
1035         if (targetAuthStrategyCopy == null) {
1036             targetAuthStrategyCopy = TargetAuthenticationStrategy.INSTANCE;
1037         }
1038         AuthenticationStrategy proxyAuthStrategyCopy = this.proxyAuthStrategy;
1039         if (proxyAuthStrategyCopy == null) {
1040             proxyAuthStrategyCopy = ProxyAuthenticationStrategy.INSTANCE;
1041         }
1042         UserTokenHandler userTokenHandlerCopy = this.userTokenHandler;
1043         if (userTokenHandlerCopy == null) {
1044             if (!connectionStateDisabled) {
1045                 userTokenHandlerCopy = DefaultUserTokenHandler.INSTANCE;
1046             } else {
1047                 userTokenHandlerCopy = NoopUserTokenHandler.INSTANCE;
1048             }
1049         }
1050 
1051         String userAgentCopy = this.userAgent;
1052         if (userAgentCopy == null) {
1053             if (systemProperties) {
1054                 userAgentCopy = System.getProperty("http.agent");
1055             }
1056             if (userAgentCopy == null && !defaultUserAgentDisabled) {
1057                 userAgentCopy = VersionInfo.getUserAgent("Apache-HttpClient",
1058                         "org.apache.http.client", getClass());
1059             }
1060         }
1061 
1062         ClientExecChain execChain = createMainExec(
1063                 requestExecCopy,
1064                 connManagerCopy,
1065                 reuseStrategyCopy,
1066                 keepAliveStrategyCopy,
1067                 new ImmutableHttpProcessor(new RequestTargetHost(), new RequestUserAgent(userAgentCopy)),
1068                 targetAuthStrategyCopy,
1069                 proxyAuthStrategyCopy,
1070                 userTokenHandlerCopy);
1071 
1072         execChain = decorateMainExec(execChain);
1073 
1074         HttpProcessor httpprocessorCopy = this.httpprocessor;
1075         if (httpprocessorCopy == null) {
1076 
1077             final HttpProcessorBuilder b = HttpProcessorBuilder.create();
1078             if (requestFirst != null) {
1079                 for (final HttpRequestInterceptor i: requestFirst) {
1080                     b.addFirst(i);
1081                 }
1082             }
1083             if (responseFirst != null) {
1084                 for (final HttpResponseInterceptor i: responseFirst) {
1085                     b.addFirst(i);
1086                 }
1087             }
1088             b.addAll(
1089                     new RequestDefaultHeaders(defaultHeaders),
1090                     new RequestContent(),
1091                     new RequestTargetHost(),
1092                     new RequestClientConnControl(),
1093                     new RequestUserAgent(userAgentCopy),
1094                     new RequestExpectContinue());
1095             if (!cookieManagementDisabled) {
1096                 b.add(new RequestAddCookies());
1097             }
1098             if (!contentCompressionDisabled) {
1099                 if (contentDecoderMap != null) {
1100                     final List<String> encodings = new ArrayList<String>(contentDecoderMap.keySet());
1101                     Collections.sort(encodings);
1102                     b.add(new RequestAcceptEncoding(encodings));
1103                 } else {
1104                     b.add(new RequestAcceptEncoding());
1105                 }
1106             }
1107             if (!authCachingDisabled) {
1108                 b.add(new RequestAuthCache());
1109             }
1110             if (!cookieManagementDisabled) {
1111                 b.add(new ResponseProcessCookies());
1112             }
1113             if (!contentCompressionDisabled) {
1114                 if (contentDecoderMap != null) {
1115                     final RegistryBuilder<InputStreamFactory> b2 = RegistryBuilder.create();
1116                     for (final Map.Entry<String, InputStreamFactory> entry: contentDecoderMap.entrySet()) {
1117                         b2.register(entry.getKey(), entry.getValue());
1118                     }
1119                     b.add(new ResponseContentEncoding(b2.build()));
1120                 } else {
1121                     b.add(new ResponseContentEncoding());
1122                 }
1123             }
1124             if (requestLast != null) {
1125                 for (final HttpRequestInterceptor i: requestLast) {
1126                     b.addLast(i);
1127                 }
1128             }
1129             if (responseLast != null) {
1130                 for (final HttpResponseInterceptor i: responseLast) {
1131                     b.addLast(i);
1132                 }
1133             }
1134             httpprocessorCopy = b.build();
1135         }
1136         execChain = new ProtocolExec(execChain, httpprocessorCopy);
1137 
1138         execChain = decorateProtocolExec(execChain);
1139 
1140         // Add request retry executor, if not disabled
1141         if (!automaticRetriesDisabled) {
1142             HttpRequestRetryHandler retryHandlerCopy = this.retryHandler;
1143             if (retryHandlerCopy == null) {
1144                 retryHandlerCopy = DefaultHttpRequestRetryHandler.INSTANCE;
1145             }
1146             execChain = new RetryExec(execChain, retryHandlerCopy);
1147         }
1148 
1149         HttpRoutePlanner routePlannerCopy = this.routePlanner;
1150         if (routePlannerCopy == null) {
1151             SchemePortResolver schemePortResolverCopy = this.schemePortResolver;
1152             if (schemePortResolverCopy == null) {
1153                 schemePortResolverCopy = DefaultSchemePortResolver.INSTANCE;
1154             }
1155             if (proxy != null) {
1156                 routePlannerCopy = new DefaultProxyRoutePlanner(proxy, schemePortResolverCopy);
1157             } else if (systemProperties) {
1158                 routePlannerCopy = new SystemDefaultRoutePlanner(
1159                         schemePortResolverCopy, ProxySelector.getDefault());
1160             } else {
1161                 routePlannerCopy = new DefaultRoutePlanner(schemePortResolverCopy);
1162             }
1163         }
1164 
1165         // Optionally, add service unavailable retry executor
1166         final ServiceUnavailableRetryStrategy serviceUnavailStrategyCopy = this.serviceUnavailStrategy;
1167         if (serviceUnavailStrategyCopy != null) {
1168             execChain = new ServiceUnavailableRetryExec(execChain, serviceUnavailStrategyCopy);
1169         }
1170 
1171         // Add redirect executor, if not disabled
1172         if (!redirectHandlingDisabled) {
1173             RedirectStrategy redirectStrategyCopy = this.redirectStrategy;
1174             if (redirectStrategyCopy == null) {
1175                 redirectStrategyCopy = DefaultRedirectStrategy.INSTANCE;
1176             }
1177             execChain = new RedirectExec(execChain, routePlannerCopy, redirectStrategyCopy);
1178         }
1179 
1180         // Optionally, add connection back-off executor
1181         if (this.backoffManager != null && this.connectionBackoffStrategy != null) {
1182             execChain = new BackoffStrategyExec(execChain, this.connectionBackoffStrategy, this.backoffManager);
1183         }
1184 
1185         Lookup<AuthSchemeProvider> authSchemeRegistryCopy = this.authSchemeRegistry;
1186         if (authSchemeRegistryCopy == null) {
1187             authSchemeRegistryCopy = RegistryBuilder.<AuthSchemeProvider>create()
1188                 .register(AuthSchemes.BASIC, new BasicSchemeFactory())
1189                 .register(AuthSchemes.DIGEST, new DigestSchemeFactory())
1190                 .register(AuthSchemes.NTLM, new NTLMSchemeFactory())
1191                 .register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory())
1192                 .register(AuthSchemes.KERBEROS, new KerberosSchemeFactory())
1193                 .build();
1194         }
1195         Lookup<CookieSpecProvider> cookieSpecRegistryCopy = this.cookieSpecRegistry;
1196         if (cookieSpecRegistryCopy == null) {
1197             cookieSpecRegistryCopy = CookieSpecRegistries.createDefault(publicSuffixMatcherCopy);
1198         }
1199 
1200         CookieStore defaultCookieStore = this.cookieStore;
1201         if (defaultCookieStore == null) {
1202             defaultCookieStore = new BasicCookieStore();
1203         }
1204 
1205         CredentialsProvider defaultCredentialsProvider = this.credentialsProvider;
1206         if (defaultCredentialsProvider == null) {
1207             if (systemProperties) {
1208                 defaultCredentialsProvider = new SystemDefaultCredentialsProvider();
1209             } else {
1210                 defaultCredentialsProvider = new BasicCredentialsProvider();
1211             }
1212         }
1213 
1214         List<Closeable> closeablesCopy = closeables != null ? new ArrayList<Closeable>(closeables) : null;
1215         if (!this.connManagerShared) {
1216             if (closeablesCopy == null) {
1217                 closeablesCopy = new ArrayList<Closeable>(1);
1218             }
1219             final HttpClientConnectionManager cm = connManagerCopy;
1220 
1221             if (evictExpiredConnections || evictIdleConnections) {
1222                 final IdleConnectionEvictortml#IdleConnectionEvictor">IdleConnectionEvictor connectionEvictor = new IdleConnectionEvictor(cm,
1223                         maxIdleTime > 0 ? maxIdleTime : 10, maxIdleTimeUnit != null ? maxIdleTimeUnit : TimeUnit.SECONDS,
1224                         maxIdleTime, maxIdleTimeUnit);
1225                 closeablesCopy.add(new Closeable() {
1226 
1227                     @Override
1228                     public void close() throws IOException {
1229                         connectionEvictor.shutdown();
1230                         try {
1231                             connectionEvictor.awaitTermination(1L, TimeUnit.SECONDS);
1232                         } catch (final InterruptedException interrupted) {
1233                             Thread.currentThread().interrupt();
1234                         }
1235                     }
1236 
1237                 });
1238                 connectionEvictor.start();
1239             }
1240             closeablesCopy.add(new Closeable() {
1241 
1242                 @Override
1243                 public void close() throws IOException {
1244                     cm.shutdown();
1245                 }
1246 
1247             });
1248         }
1249 
1250         return new InternalHttpClient(
1251                 execChain,
1252                 connManagerCopy,
1253                 routePlannerCopy,
1254                 cookieSpecRegistryCopy,
1255                 authSchemeRegistryCopy,
1256                 defaultCookieStore,
1257                 defaultCredentialsProvider,
1258                 defaultRequestConfig != null ? defaultRequestConfig : RequestConfig.DEFAULT,
1259                 closeablesCopy);
1260     }
1261 
1262 }