rybalkinsd / kohttp

Kotlin DSL http client
https://kohttp.gitbook.io
Apache License 2.0
478 stars 42 forks source link

Sample code on how to set a read/connect timeout #172

Closed girionis closed 4 years ago

girionis commented 4 years ago

Hello, I am using kohttp with dsl to send a post request

val response: Response = httpPost {...

any idea how I can set a read/connect timeout? I would appreciate any sample code.

Thank you

Panos

girionis commented 4 years ago

Ok I think I have found it. I forked the default http client and passed it as argument to the httpPost

val customClient = defaultHttpClient.fork {   
            readTimeout = 30000
            connectTimeout = 30000
            writeTimeout = 30000
        }

and then httpPost(client = customClient)

rybalkinsd commented 4 years ago

Hi @girionis, thanks for your question.

You found one of the right ways to do it with client fork fork. In general, we support two options at the moment.

Very welcome, if you have any suggestion how we can make docs better.

girionis commented 4 years ago

Hello Sergei, thank you for your prompt reply. I had to look at the source code in order to find out how to do it, so maybe you could add the part where you set the client in the httpPost?

In any case congratulations again for the great library you have given us. Keep up the good work.

Regards

Panos

rybalkinsd commented 4 years ago

Thanks Panos,

Would definitely consider adding the example of passing a client