Skip to content

Commit

Permalink
use run {}
Browse files Browse the repository at this point in the history
  • Loading branch information
snowp committed Nov 26, 2024
1 parent 19a982e commit 39908b1
Showing 1 changed file with 22 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 39908b1

Please sign in to comment.