Does anyone know how to set the socket-timeouts et...
# ktor
g
Does anyone know how to set the socket-timeouts etcetera for a ktor-client with httpEngine in ktor 1.2.3?
Copy code
suspend fun main() {
    val server = embeddedServer(Netty, port = 8080) {
        routing {
            route("/") {
                getAndReportMetrics("/hello") {
                    Thread.sleep(31_000)
                    it.respondJson(mapOf("hello" to true), HttpStatusCode.OK)
                }
            }
        }
    }.start()

    var response: HttpResponse? = null
    val responseTime = measureTimeMillis {
        try {
            val precon = OkHttpClient.Builder()
                .callTimeout(Duration.ofMillis(30_000))
                .readTimeout(Duration.ofMillis(30_000))
                .connectTimeout(Duration.ofMillis(30_000))
                .writeTimeout(Duration.ofMillis(30_000))
                .build()
            val lolClient =
                HttpClient(OkHttp) {
                    expectSuccess = false
                    engine {
                        config {
                            preconfigured = precon
                        }
                    }
                }
            response = lolClient.get<HttpResponse>("<http://localhost:8080/hello>")
            response!!.isIn200Range()
        } catch(e: Exception) {
            println("got an exception $e")
        }
    }

    println("hello $responseTime")
}
It seems the default socketTimeout of 10 seconds still applies in this case