Skip to content

Commit

Permalink
fix: set correct timeouts on okhttp client
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-bot committed Aug 15, 2023
1 parent e18bccd commit 0265450
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val

private fun getClient(requestOptions: RequestOptions): okhttp3.OkHttpClient {
val timeout = requestOptions.timeout ?: return okHttpClient
return okHttpClient.newBuilder().callTimeout(timeout).build()
return okHttpClient
.newBuilder()
.connectTimeout(timeout)
.readTimeout(timeout)
.writeTimeout(timeout)
.callTimeout(if (timeout.seconds == 0L) timeout else timeout.plusSeconds(30))
.build()
}

override fun execute(
Expand Down Expand Up @@ -177,7 +183,13 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val

fun build(): OkHttpClient {
return OkHttpClient(
okhttp3.OkHttpClient.Builder().callTimeout(timeout).proxy(proxy).build(),
okhttp3.OkHttpClient.Builder()
.connectTimeout(timeout)
.readTimeout(timeout)
.writeTimeout(timeout)
.callTimeout(if (timeout.seconds == 0L) timeout else timeout.plusSeconds(30))
.proxy(proxy)
.build(),
checkNotNull(baseUrl) { "`baseUrl` is required but was not set" },
)
}
Expand Down

0 comments on commit 0265450

Please sign in to comment.