package com.awsmithson.tcx2nikeplus.http;

import com.google.common.base.Predicate;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.impl.client.HttpClientBuilder;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public class HttpClients {

	// The "URL_DATA_SYNC" nike+ service seems to intermittently return 503, HttpComponents can deal with that nicely.
	private static final @Nonnull HttpStatusCodeRetryStrategy DEFAULT_RETRY_STRATEGY = new HttpStatusCodeRetryStrategy(10, 200, new Predicate<HttpResponse>() {
		@Override
		public boolean apply(@Nullable HttpResponse httpResponse) {
			return (httpResponse == null) || (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_SERVICE_UNAVAILABLE);
		}
	});

	public static HttpClientBuilder createDefaultHttpClientBuilder() {
		return HttpClientBuilder
				.create()
				.setDefaultRequestConfig(RequestConfig.custom()
						.setConnectTimeout(5_000)
						.setConnectionRequestTimeout(5_000)
						.setSocketTimeout(8_000)
						.build())
				.setRetryHandler(new HttpTimeoutRetryHandler(10))
				.setServiceUnavailableRetryStrategy(DEFAULT_RETRY_STRATEGY);
	}
}

@@ -352,16 +352,219 @@
 ents %7B%0A%0A
+%09private static final @Nonnull RequestConfig REQUEST_CONFIG_DEFAULT = RequestConfig.custom()%0A%09%09%09.setConnectTimeout(5_000)%0A%09%09%09.setConnectionRequestTimeout(5_000)%0A%09%09%09.setSocketTimeout(8_000)%0A%09%09%09.build();%0A%0A
 %09// The 
@@ -1176,149 +1176,29 @@
 ig(R
-equestConfig.custom()%0A%09%09%09%09%09%09.setConnectTimeout(5_000)%0A%09%09%09%09%09%09.setConnectionRequestTimeout(5_000)%0A%09%09%09%09%09%09.setSocketTimeout(8_000)%0A%09%09%09%09%09%09.build()
+EQUEST_CONFIG_DEFAULT
 )%0A%09%09

Make HttpClients default RequestConfig a constant (it's thread safe).