Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove magic okhttp interceptors #131

Merged
merged 3 commits into from
Nov 26, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Loading