https://kotlinlang.org logo
#http4k
Title
n

Nicola

06/23/2023, 2:31 PM
Hi in one of my tests I am using the OkHttp client wrapper .. for no particular reason, just to try it. Is there any way to set the connect timeout? I've tried to use ok http client directly but then I loose the compatibility with http4k requests Or are there any other http client which has the timeout config out of the box?Thanks!
I am using http4k 4.41.1.0
the current code I have is something like this:
Copy code
val httpClient = OkHttp()

val response = httpClient(request)
I would like to add (raise actually) the connect timeout
d

dave

06/23/2023, 2:33 PM
You need to configure the client that goes into the OkHttp wrapper constructor
It's not an http4k setting per se
n

Nicola

06/23/2023, 2:33 PM
I see
this one you mean
Copy code
operator fun invoke(
    client: OkHttpClient = defaultOkHttpClient(),
    bodyMode: BodyMode = BodyMode.Memory
): DualSyncAsyncHttpHandler =
?
a

Andrew O'Hara

06/23/2023, 2:34 PM
Copy code
val client = OkHttpClient.Builder()
        .followRedirects(false)
        .callTimeout(timeout)
        .build()
        .let { OkHttp(it) }
n

Nicola

06/23/2023, 2:34 PM
thanks a lot! 👍
a

Andrew O'Hara

06/23/2023, 2:35 PM
Yes, the snippet I shared is calling the function you provided with a customized OkHttpClient
n

Nicola

06/23/2023, 2:35 PM
I see... thanks!
2 Views