diff --git a/google-http-client-apache-v2/src/main/java/com/google/api/client/http/apache/v2/ApacheHttpTransport.java b/google-http-client-apache-v2/src/main/java/com/google/api/client/http/apache/v2/ApacheHttpTransport.java index 42f53d490..2506fd028 100644 --- a/google-http-client-apache-v2/src/main/java/com/google/api/client/http/apache/v2/ApacheHttpTransport.java +++ b/google-http-client-apache-v2/src/main/java/com/google/api/client/http/apache/v2/ApacheHttpTransport.java @@ -123,29 +123,53 @@ public ApacheHttpTransport(HttpClient httpClient) { * @since 1.30 */ public static HttpClient newDefaultHttpClient() { + return newDefaultHttpClientBuilder().build(); + } + + /** + * Creates a new Apache HTTP client builder that is used by the + * {@link #ApacheHttpTransport()} constructor. + * + *

+ * Settings: + *

+ * + * + * @return new instance of the Apache HTTP client + * @since 1.31 + */ + public static HttpClientBuilder newDefaultHttpClientBuilder() { // Set socket buffer sizes to 8192 SocketConfig socketConfig = - SocketConfig.custom() - .setRcvBufSize(8192) - .setSndBufSize(8192) - .build(); + SocketConfig.custom() + .setRcvBufSize(8192) + .setSndBufSize(8192) + .build(); PoolingHttpClientConnectionManager connectionManager = - new PoolingHttpClientConnectionManager(-1, TimeUnit.MILLISECONDS); + new PoolingHttpClientConnectionManager(-1, TimeUnit.MILLISECONDS); // Disable the stale connection check (previously configured in the HttpConnectionParams connectionManager.setValidateAfterInactivity(-1); return HttpClientBuilder.create() - .useSystemProperties() - .setSSLSocketFactory(SSLConnectionSocketFactory.getSocketFactory()) - .setDefaultSocketConfig(socketConfig) - .setMaxConnTotal(200) - .setMaxConnPerRoute(20) - .setRoutePlanner(new SystemDefaultRoutePlanner(ProxySelector.getDefault())) - .setConnectionManager(connectionManager) - .disableRedirectHandling() - .disableAutomaticRetries() - .build(); + .useSystemProperties() + .setSSLSocketFactory(SSLConnectionSocketFactory.getSocketFactory()) + .setDefaultSocketConfig(socketConfig) + .setMaxConnTotal(200) + .setMaxConnPerRoute(20) + .setRoutePlanner(new SystemDefaultRoutePlanner(ProxySelector.getDefault())) + .setConnectionManager(connectionManager) + .disableRedirectHandling() + .disableAutomaticRetries(); } @Override