Skip to content

Commit

Permalink
Allow separate client for streaming calls (#128)
Browse files Browse the repository at this point in the history
Streaming calls often require longer timeouts (for long lived streams)
and enabling pings (to keep the underlying connection alive). Update
ConnectOkHttpClient to take a second OkHttpClient argument to the
constructor to be used for streaming calls.

Fixes #13.
  • Loading branch information
pkwarren authored Oct 11, 2023
1 parent aa4aabe commit 34cf5b1
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ import java.io.IOException
* The OkHttp implementation of HTTPClientInterface.
*/
class ConnectOkHttpClient @JvmOverloads constructor(
val client: OkHttpClient = OkHttpClient(),
private val unaryClient: OkHttpClient = OkHttpClient(),
private val streamClient: OkHttpClient = unaryClient,
) : HTTPClientInterface {

override fun unary(request: HTTPRequest, onResult: (HTTPResponse) -> Unit): Cancelable {
Expand All @@ -55,7 +56,7 @@ class ConnectOkHttpClient @JvmOverloads constructor(
.url(request.url)
.method(method, requestBody)
.build()
val newCall = client.newCall(callRequest)
val newCall = unaryClient.newCall(callRequest)
val cancelable = {
newCall.cancel()
}
Expand Down Expand Up @@ -126,7 +127,7 @@ class ConnectOkHttpClient @JvmOverloads constructor(
request: HTTPRequest,
onResult: suspend (StreamResult<Buffer>) -> Unit,
): Stream {
return client.initializeStream(request.methodSpec.method, request, onResult)
return streamClient.initializeStream(request.methodSpec.method, request, onResult)
}
}

Expand Down

0 comments on commit 34cf5b1

Please sign in to comment.