Skip to content

Commit

Permalink
Share the default OkHttpBuilder (#5811)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinbonnin authored Apr 15, 2024
1 parent f59f0b4 commit b364a07
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,8 @@ internal fun List<HttpHeader>.toOkHttpHeaders(): Headers =
this.forEach {
headers.add(it.name, it.value)
}
}.build()
}.build()

internal val defaultOkHttpClientBuilder: OkHttpClient.Builder by lazy {
OkHttpClient.Builder()
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.apollographql.apollo3.api.http.HttpRequest
import com.apollographql.apollo3.api.http.HttpResponse
import com.apollographql.apollo3.api.http.UploadsHttpBody
import com.apollographql.apollo3.exception.ApolloNetworkException
import com.apollographql.apollo3.network.defaultOkHttpClientBuilder
import com.apollographql.apollo3.network.toOkHttpHeaders
import kotlinx.coroutines.suspendCancellableCoroutine
import okhttp3.Call
Expand Down Expand Up @@ -42,7 +43,7 @@ private class JvmHttpEngine(
constructor(timeoutMillis: Long) : this(timeoutMillis, timeoutMillis)

constructor(connectTimeoutMillis: Long, readTimeoutMillis: Long) : this(
OkHttpClient.Builder()
defaultOkHttpClientBuilder
.connectTimeout(connectTimeoutMillis, TimeUnit.MILLISECONDS)
.readTimeout(readTimeoutMillis, TimeUnit.MILLISECONDS)
.build()
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.apollographql.apollo3.network.websocket

import com.apollographql.apollo3.api.http.HttpHeader
import com.apollographql.apollo3.exception.ApolloNetworkException
import com.apollographql.apollo3.network.defaultOkHttpClientBuilder
import com.apollographql.apollo3.network.websocket.WebSocket
import com.apollographql.apollo3.network.websocket.WebSocketListener
import okhttp3.Headers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package com.apollographql.apollo3.network.ws
import com.apollographql.apollo3.api.http.HttpHeader
import com.apollographql.apollo3.exception.ApolloNetworkException
import com.apollographql.apollo3.exception.ApolloWebSocketClosedException
import com.apollographql.apollo3.network.defaultOkHttpClientBuilder
import com.apollographql.apollo3.network.toOkHttpHeaders
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.channels.Channel
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.Response
import okhttp3.WebSocket
Expand All @@ -18,7 +18,7 @@ actual class DefaultWebSocketEngine(
) : WebSocketEngine {

actual constructor() : this(
webSocketFactory = OkHttpClient()
webSocketFactory = defaultOkHttpClientBuilder.build()
)

actual override suspend fun open(
Expand Down

0 comments on commit b364a07

Please sign in to comment.