1
1
package com.coder.toolbox.sdk
2
2
3
3
import com.coder.toolbox.CoderToolboxContext
4
- import com.coder.toolbox.sdk.interceptors.Interceptors
5
4
import com.coder.toolbox.util.CoderHostnameVerifier
6
5
import com.coder.toolbox.util.coderSocketFactory
7
6
import com.coder.toolbox.util.coderTrustManagers
8
7
import com.jetbrains.toolbox.api.remoteDev.connection.ProxyAuth
9
8
import okhttp3.Credentials
9
+ import okhttp3.Interceptor
10
10
import okhttp3.OkHttpClient
11
- import java.net.URL
12
11
import javax.net.ssl.X509TrustManager
13
12
14
13
object CoderHttpClientBuilder {
15
14
fun build (
16
15
context : CoderToolboxContext ,
17
- pluginVersion : String ,
18
- url : URL ,
19
- token : String? ,
16
+ interceptors : List <Interceptor >
20
17
): OkHttpClient {
21
18
val settings = context.settingsStore.readOnly()
22
19
@@ -46,20 +43,14 @@ object CoderHttpClientBuilder {
46
43
.build()
47
44
}
48
45
49
- if (context.settingsStore.requireTokenAuth) {
50
- if (token.isNullOrBlank()) {
51
- throw IllegalStateException (" Token is required for $url deployment" )
52
- }
53
- builder = builder.addInterceptor(Interceptors .tokenAuth(token))
54
- }
55
-
56
- return builder
57
- .sslSocketFactory(socketFactory, trustManagers[0 ] as X509TrustManager )
46
+ builder.sslSocketFactory(socketFactory, trustManagers[0 ] as X509TrustManager )
58
47
.hostnameVerifier(CoderHostnameVerifier (settings.tls.altHostname))
59
48
.retryOnConnectionFailure(true )
60
- .addInterceptor(Interceptors .userAgent(pluginVersion))
61
- .addInterceptor(Interceptors .externalHeaders(context, url))
62
- .addInterceptor(Interceptors .logging(context))
63
- .build()
49
+
50
+ interceptors.forEach { interceptor ->
51
+ builder.addInterceptor(interceptor)
52
+
53
+ }
54
+ return builder.build()
64
55
}
65
56
}
0 commit comments