Skip to content

Commit 1801e83

Browse files
committed
- fixes multiple bugs where httpclient would be partially configured
1 parent 727bdb4 commit 1801e83

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/main/java/com/microsoft/graph/httpcore/HttpClients.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package com.microsoft.graph.httpcore;
22

3+
import java.util.Arrays;
4+
35
import okhttp3.Interceptor;
46
import okhttp3.OkHttpClient;
7+
import okhttp3.Protocol;
58
import okhttp3.OkHttpClient.Builder;
69

710
public 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

Comments
 (0)