11package com .microsoft .graph .httpcore ;
22
3+ import java .util .Arrays ;
4+
35import okhttp3 .Interceptor ;
46import okhttp3 .OkHttpClient ;
7+ import okhttp3 .Protocol ;
58import okhttp3 .OkHttpClient .Builder ;
69
710public class HttpClients {
@@ -16,7 +19,10 @@ private HttpClients() {
1619 * @return OkHttpClient.Builder() custom builder for developer to add its own interceptors to it
1720 */
1821 public static Builder custom () {
19- return new OkHttpClient .Builder ().addInterceptor (new TelemetryHandler ());
22+ return new OkHttpClient .Builder ()
23+ .addInterceptor (new TelemetryHandler ())
24+ .followRedirects (false )
25+ .protocols (Arrays .asList (Protocol .HTTP_1_1 )); //https://stackoverflow.com/questions/62031298/sockettimeout-on-java-11-but-not-on-java-8
2026 }
2127
2228 /**
@@ -27,11 +33,10 @@ public static Builder custom() {
2733 * @return OkHttpClient build with authentication provider given, default redirect and default retry handlers
2834 */
2935 public static OkHttpClient createDefault (ICoreAuthenticationProvider auth ) {
30- return new OkHttpClient . Builder (). addInterceptor ( new AuthenticationHandler ( auth ) )
31- . followRedirects ( false )
36+ return custom ( )
37+ . addInterceptor ( new AuthenticationHandler ( auth ) )
3238 .addInterceptor (new RetryHandler ())
3339 .addInterceptor (new RedirectHandler ())
34- .addInterceptor (new TelemetryHandler ())
3540 .build ();
3641 }
3742
@@ -42,13 +47,12 @@ public static OkHttpClient createDefault(ICoreAuthenticationProvider auth) {
4247 * @return OkHttpClient build with interceptors provided
4348 */
4449 public static OkHttpClient createFromInterceptors (Interceptor [] interceptors ) {
45- OkHttpClient .Builder builder = new OkHttpClient . Builder ();
50+ OkHttpClient .Builder builder = custom ();
4651 if (interceptors != null )
4752 for (Interceptor interceptor : interceptors ) {
4853 if (interceptor != null )
4954 builder .addInterceptor (interceptor );
5055 }
51- builder .addInterceptor (new TelemetryHandler ());
5256 return builder .build ();
5357 }
5458}
0 commit comments