Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0767980

Browse files
committedMar 20, 2024
Allow using existing http client
1 parent dad161f commit 0767980

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed
 

‎src/main/kotlin/com/coder/gateway/sdk/BaseCoderRestClient.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ open class BaseCoderRestClient(
5050
private val settings: CoderSettings = CoderSettings(CoderSettingsState()),
5151
private val proxyValues: ProxyValues? = null,
5252
private val pluginVersion: String = "development",
53+
existingHttpClient: OkHttpClient? = null,
5354
) {
5455
private val httpClient: OkHttpClient
5556
private val retroRestClient: CoderV2RestFacade
@@ -67,7 +68,7 @@ open class BaseCoderRestClient(
6768

6869
val socketFactory = coderSocketFactory(settings.tls)
6970
val trustManagers = coderTrustManagers(settings.tls.caPath)
70-
var builder = OkHttpClient.Builder()
71+
var builder = existingHttpClient?.newBuilder() ?: OkHttpClient.Builder()
7172

7273
if (proxyValues != null) {
7374
builder = builder

‎src/main/kotlin/com/coder/gateway/sdk/CoderRestClient.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,18 @@ import com.intellij.ide.plugins.PluginManagerCore
55
import com.intellij.openapi.components.service
66
import com.intellij.openapi.extensions.PluginId
77
import com.intellij.util.net.HttpConfigurable
8+
import okhttp3.OkHttpClient
89
import java.net.URL
910

1011
/**
1112
* A client instance that hooks into global JetBrains services for default
1213
* settings. Exists only so we can use the base client in tests.
1314
*/
14-
class CoderRestClient(url: URL, token: String) : BaseCoderRestClient(url, token,
15+
class CoderRestClient(url: URL, token: String, httpClient: OkHttpClient? = null) : BaseCoderRestClient(url, token,
1516
service<CoderSettingsService>(),
1617
ProxyValues(HttpConfigurable.getInstance().proxyLogin,
1718
HttpConfigurable.getInstance().plainProxyPassword,
1819
HttpConfigurable.getInstance().PROXY_AUTHENTICATION,
1920
HttpConfigurable.getInstance().onlyBySettingsSelector),
20-
PluginManagerCore.getPlugin(PluginId.getId("com.coder.gateway"))!!.version)
21+
PluginManagerCore.getPlugin(PluginId.getId("com.coder.gateway"))!!.version,
22+
httpClient)

0 commit comments

Comments
 (0)