From 19a982e537c47620157c71412b8dc86b5e1f9f3f Mon Sep 17 00:00:00 2001 From: Snow Pettersen Date: Tue, 26 Nov 2024 08:57:17 -0800 Subject: [PATCH 1/3] remove okhttp interceptors --- .../capture/network/okhttp/OkHttpNetwork.kt | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/platform/jvm/capture/src/main/kotlin/io/bitdrift/capture/network/okhttp/OkHttpNetwork.kt b/platform/jvm/capture/src/main/kotlin/io/bitdrift/capture/network/okhttp/OkHttpNetwork.kt index 1944a380..e019c98a 100644 --- a/platform/jvm/capture/src/main/kotlin/io/bitdrift/capture/network/okhttp/OkHttpNetwork.kt +++ b/platform/jvm/capture/src/main/kotlin/io/bitdrift/capture/network/okhttp/OkHttpNetwork.kt @@ -79,18 +79,29 @@ internal class OkHttpNetwork( apiBaseUrl: HttpUrl, timeoutSeconds: Long = 2L * 60, ) : ICaptureNetwork { - private val client: OkHttpClient = OkHttpClient().newBuilder() - .protocols( - if (apiBaseUrl.scheme == "https") { - listOf(Protocol.HTTP_2, Protocol.HTTP_1_1) - } else { - listOf(Protocol.H2_PRIOR_KNOWLEDGE) - }, - ) - .writeTimeout(timeoutSeconds, TimeUnit.SECONDS) - .readTimeout(timeoutSeconds, TimeUnit.SECONDS) - .retryOnConnectionFailure(false) // Retrying messes up the write pipe state management, so disable. - .build() + private val client: OkHttpClient = { + val builder = OkHttpClient().newBuilder() + + // Certain other libraries will manipulate the bytecode to have the OkHttpClientBuilder + // constructor automatically add interceptors which tend to not work well with our bespoke + // client implementation. Remove these extra interceptors here to ensure that we are using + // a standard client. + builder.interceptors().clear() + builder.networkInterceptors().clear() + + builder + .protocols( + if (apiBaseUrl.scheme == "https") { + listOf(Protocol.HTTP_2, Protocol.HTTP_1_1) + } else { + listOf(Protocol.H2_PRIOR_KNOWLEDGE) + }, + ) + .writeTimeout(timeoutSeconds, TimeUnit.SECONDS) + .readTimeout(timeoutSeconds, TimeUnit.SECONDS) + .retryOnConnectionFailure(false) // Retrying messes up the write pipe state management, so disable. + .build() + } private val executor: ExecutorService = Executors.newSingleThreadExecutor { Thread(it, "io.bitdrift.capture.network.okhttp") From 39908b1193b06bbc97cb00f24609f00b613ade13 Mon Sep 17 00:00:00 2001 From: Snow Pettersen Date: Tue, 26 Nov 2024 09:07:43 -0800 Subject: [PATCH 2/3] use run {} --- .../capture/network/okhttp/OkHttpNetwork.kt | 45 +++++++++---------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/platform/jvm/capture/src/main/kotlin/io/bitdrift/capture/network/okhttp/OkHttpNetwork.kt b/platform/jvm/capture/src/main/kotlin/io/bitdrift/capture/network/okhttp/OkHttpNetwork.kt index e019c98a..4f26f8ff 100644 --- a/platform/jvm/capture/src/main/kotlin/io/bitdrift/capture/network/okhttp/OkHttpNetwork.kt +++ b/platform/jvm/capture/src/main/kotlin/io/bitdrift/capture/network/okhttp/OkHttpNetwork.kt @@ -79,29 +79,28 @@ internal class OkHttpNetwork( apiBaseUrl: HttpUrl, timeoutSeconds: Long = 2L * 60, ) : ICaptureNetwork { - private val client: OkHttpClient = { - val builder = OkHttpClient().newBuilder() - - // Certain other libraries will manipulate the bytecode to have the OkHttpClientBuilder - // constructor automatically add interceptors which tend to not work well with our bespoke - // client implementation. Remove these extra interceptors here to ensure that we are using - // a standard client. - builder.interceptors().clear() - builder.networkInterceptors().clear() - - builder - .protocols( - if (apiBaseUrl.scheme == "https") { - listOf(Protocol.HTTP_2, Protocol.HTTP_1_1) - } else { - listOf(Protocol.H2_PRIOR_KNOWLEDGE) - }, - ) - .writeTimeout(timeoutSeconds, TimeUnit.SECONDS) - .readTimeout(timeoutSeconds, TimeUnit.SECONDS) - .retryOnConnectionFailure(false) // Retrying messes up the write pipe state management, so disable. - .build() - } + private val client: OkHttpClient = + run { + val builder = OkHttpClient().newBuilder() + // Certain other libraries will manipulate the bytecode to have the OkHttpClientBuilder + // constructor automatically add interceptors which tend to not work well with our bespoke + // client implementation. Remove these extra interceptors here to ensure that we are using + // a standard client. + builder.interceptors().clear() + builder.networkInterceptors().clear() + builder + .protocols( + if (apiBaseUrl.scheme == "https") { + listOf(Protocol.HTTP_2, Protocol.HTTP_1_1) + } else { + listOf(Protocol.H2_PRIOR_KNOWLEDGE) + }, + ) + .writeTimeout(timeoutSeconds, TimeUnit.SECONDS) + .readTimeout(timeoutSeconds, TimeUnit.SECONDS) + .retryOnConnectionFailure(false) // Retrying messes up the write pipe state management, so disable. + .build() + } private val executor: ExecutorService = Executors.newSingleThreadExecutor { Thread(it, "io.bitdrift.capture.network.okhttp") From 61bb5bc2ae49a65ba2f8e9199b5b566c3b67982d Mon Sep 17 00:00:00 2001 From: Snow Pettersen Date: Tue, 26 Nov 2024 09:44:40 -0800 Subject: [PATCH 3/3] fmt --- .../capture/network/okhttp/OkHttpNetwork.kt | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/platform/jvm/capture/src/main/kotlin/io/bitdrift/capture/network/okhttp/OkHttpNetwork.kt b/platform/jvm/capture/src/main/kotlin/io/bitdrift/capture/network/okhttp/OkHttpNetwork.kt index 4f26f8ff..c9aaeafa 100644 --- a/platform/jvm/capture/src/main/kotlin/io/bitdrift/capture/network/okhttp/OkHttpNetwork.kt +++ b/platform/jvm/capture/src/main/kotlin/io/bitdrift/capture/network/okhttp/OkHttpNetwork.kt @@ -80,27 +80,27 @@ internal class OkHttpNetwork( timeoutSeconds: Long = 2L * 60, ) : ICaptureNetwork { private val client: OkHttpClient = - run { - val builder = OkHttpClient().newBuilder() - // Certain other libraries will manipulate the bytecode to have the OkHttpClientBuilder - // constructor automatically add interceptors which tend to not work well with our bespoke - // client implementation. Remove these extra interceptors here to ensure that we are using - // a standard client. - builder.interceptors().clear() - builder.networkInterceptors().clear() - builder - .protocols( - if (apiBaseUrl.scheme == "https") { - listOf(Protocol.HTTP_2, Protocol.HTTP_1_1) - } else { - listOf(Protocol.H2_PRIOR_KNOWLEDGE) - }, - ) - .writeTimeout(timeoutSeconds, TimeUnit.SECONDS) - .readTimeout(timeoutSeconds, TimeUnit.SECONDS) - .retryOnConnectionFailure(false) // Retrying messes up the write pipe state management, so disable. - .build() - } + run { + val builder = OkHttpClient().newBuilder() + // Certain other libraries will manipulate the bytecode to have the OkHttpClientBuilder + // constructor automatically add interceptors which tend to not work well with our bespoke + // client implementation. Remove these extra interceptors here to ensure that we are using + // a standard client. + builder.interceptors().clear() + builder.networkInterceptors().clear() + builder + .protocols( + if (apiBaseUrl.scheme == "https") { + listOf(Protocol.HTTP_2, Protocol.HTTP_1_1) + } else { + listOf(Protocol.H2_PRIOR_KNOWLEDGE) + }, + ) + .writeTimeout(timeoutSeconds, TimeUnit.SECONDS) + .readTimeout(timeoutSeconds, TimeUnit.SECONDS) + .retryOnConnectionFailure(false) // Retrying messes up the write pipe state management, so disable. + .build() + } private val executor: ExecutorService = Executors.newSingleThreadExecutor { Thread(it, "io.bitdrift.capture.network.okhttp")