1
1
package com.coder.toolbox.sdk
2
2
3
3
import com.coder.toolbox.CoderToolboxContext
4
- import com.coder.toolbox.sdk.interceptors.LoggingInterceptor
4
+ import com.coder.toolbox.sdk.interceptors.Interceptors
5
5
import com.coder.toolbox.util.CoderHostnameVerifier
6
6
import com.coder.toolbox.util.coderSocketFactory
7
7
import com.coder.toolbox.util.coderTrustManagers
8
- import com.coder.toolbox.util.getArch
9
- import com.coder.toolbox.util.getHeaders
10
- import com.coder.toolbox.util.getOS
11
8
import com.jetbrains.toolbox.api.remoteDev.connection.ProxyAuth
12
9
import okhttp3.Credentials
13
10
import okhttp3.OkHttpClient
@@ -53,36 +50,16 @@ object CoderHttpClientBuilder {
53
50
if (token.isNullOrBlank()) {
54
51
throw IllegalStateException (" Token is required for $url deployment" )
55
52
}
56
- builder = builder.addInterceptor {
57
- it.proceed(
58
- it.request().newBuilder().addHeader(" Coder-Session-Token" , token).build()
59
- )
60
- }
53
+ builder = builder.addInterceptor(Interceptors .tokenAuth(token))
61
54
}
62
55
63
56
return builder
64
57
.sslSocketFactory(socketFactory, trustManagers[0 ] as X509TrustManager )
65
58
.hostnameVerifier(CoderHostnameVerifier (settings.tls.altHostname))
66
59
.retryOnConnectionFailure(true )
67
- .addInterceptor {
68
- it.proceed(
69
- it.request().newBuilder().addHeader(
70
- " User-Agent" ,
71
- " Coder Toolbox/$pluginVersion (${getOS()} ; ${getArch()} )" ,
72
- ).build(),
73
- )
74
- }
75
- .addInterceptor {
76
- var request = it.request()
77
- val headers = getHeaders(url, settings.headerCommand)
78
- if (headers.isNotEmpty()) {
79
- val reqBuilder = request.newBuilder()
80
- headers.forEach { h -> reqBuilder.addHeader(h.key, h.value) }
81
- request = reqBuilder.build()
82
- }
83
- it.proceed(request)
84
- }
85
- .addInterceptor(LoggingInterceptor (context))
60
+ .addInterceptor(Interceptors .userAgent(pluginVersion))
61
+ .addInterceptor(Interceptors .externalHeaders(context, url))
62
+ .addInterceptor(Interceptors .logging(context))
86
63
.build()
87
64
}
88
65
}
0 commit comments