Skip to content

Commit 959fc7d

Browse files
authored
remove magic okhttp interceptors (#131)
1 parent 99fcf17 commit 959fc7d

File tree

1 file changed

+22
-12
lines changed
  • platform/jvm/capture/src/main/kotlin/io/bitdrift/capture/network/okhttp

1 file changed

+22
-12
lines changed

platform/jvm/capture/src/main/kotlin/io/bitdrift/capture/network/okhttp/OkHttpNetwork.kt

+22-12
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,28 @@ internal class OkHttpNetwork(
7979
apiBaseUrl: HttpUrl,
8080
timeoutSeconds: Long = 2L * 60,
8181
) : ICaptureNetwork {
82-
private val client: OkHttpClient = OkHttpClient().newBuilder()
83-
.protocols(
84-
if (apiBaseUrl.scheme == "https") {
85-
listOf(Protocol.HTTP_2, Protocol.HTTP_1_1)
86-
} else {
87-
listOf(Protocol.H2_PRIOR_KNOWLEDGE)
88-
},
89-
)
90-
.writeTimeout(timeoutSeconds, TimeUnit.SECONDS)
91-
.readTimeout(timeoutSeconds, TimeUnit.SECONDS)
92-
.retryOnConnectionFailure(false) // Retrying messes up the write pipe state management, so disable.
93-
.build()
82+
private val client: OkHttpClient =
83+
run {
84+
val builder = OkHttpClient().newBuilder()
85+
// Certain other libraries will manipulate the bytecode to have the OkHttpClientBuilder
86+
// constructor automatically add interceptors which tend to not work well with our bespoke
87+
// client implementation. Remove these extra interceptors here to ensure that we are using
88+
// a standard client.
89+
builder.interceptors().clear()
90+
builder.networkInterceptors().clear()
91+
builder
92+
.protocols(
93+
if (apiBaseUrl.scheme == "https") {
94+
listOf(Protocol.HTTP_2, Protocol.HTTP_1_1)
95+
} else {
96+
listOf(Protocol.H2_PRIOR_KNOWLEDGE)
97+
},
98+
)
99+
.writeTimeout(timeoutSeconds, TimeUnit.SECONDS)
100+
.readTimeout(timeoutSeconds, TimeUnit.SECONDS)
101+
.retryOnConnectionFailure(false) // Retrying messes up the write pipe state management, so disable.
102+
.build()
103+
}
94104

95105
private val executor: ExecutorService = Executors.newSingleThreadExecutor {
96106
Thread(it, "io.bitdrift.capture.network.okhttp")

0 commit comments

Comments
 (0)