@@ -22,6 +22,8 @@ import com.intellij.openapi.components.Service
22
22
import com.intellij.openapi.diagnostic.Logger
23
23
import com.intellij.openapi.extensions.PluginId
24
24
import com.intellij.openapi.util.SystemInfo
25
+ import com.intellij.util.net.HttpConfigurable
26
+ import okhttp3.Credentials
25
27
import okhttp3.OkHttpClient
26
28
import okhttp3.internal.tls.OkHostnameVerifier
27
29
import okhttp3.logging.HttpLoggingInterceptor
@@ -95,9 +97,22 @@ class CoderRestClient(
95
97
pluginVersion = PluginManagerCore .getPlugin(PluginId .getId(" com.coder.gateway" ))!! .version // this is the id from the plugin.xml
96
98
}
97
99
100
+ val proxy = HttpConfigurable .getInstance()
101
+
98
102
val socketFactory = coderSocketFactory(settings)
99
103
val trustManagers = coderTrustManagers(settings.tlsCAPath)
100
104
httpClient = OkHttpClient .Builder ()
105
+ .proxySelector(proxy.onlyBySettingsSelector)
106
+ .proxyAuthenticator { _, response ->
107
+ val login = proxy.proxyLogin
108
+ val pass = proxy.plainProxyPassword
109
+ if (proxy.PROXY_AUTHENTICATION && login != null && pass != null ) {
110
+ val credentials = Credentials .basic(login, pass)
111
+ response.request.newBuilder()
112
+ .header(" Proxy-Authorization" , credentials)
113
+ .build()
114
+ } else null
115
+ }
101
116
.sslSocketFactory(socketFactory, trustManagers[0 ] as X509TrustManager )
102
117
.hostnameVerifier(CoderHostnameVerifier (settings.tlsAlternateHostname))
103
118
.addInterceptor { it.proceed(it.request().newBuilder().addHeader(" Coder-Session-Token" , token).build()) }
@@ -451,4 +466,4 @@ class MergedSystemTrustManger(private val otherTrustManager: X509TrustManager) :
451
466
override fun getAcceptedIssuers (): Array <X509Certificate > {
452
467
return otherTrustManager.acceptedIssuers + systemTrustManager.acceptedIssuers
453
468
}
454
- }
469
+ }
0 commit comments