&gt; <If an engine supports HTTP/2, you can enable...
# ktor
s
If an engine supports HTTP/2, you can enable it in the engine's configuration
how do I enable that for the Js or Okhttp client for example? I can't find any option like
protocolVersion
in the engine config
a
You can configure the protocols for the OkHttp engine by configuring the underlying client:
Copy code
val client = HttpClient(OkHttp) {
    engine {
        preconfigured = OkHttpClient.Builder()
            .protocols(listOf(Protocol.HTTP_2))
            .build()
    }
}
You can't configure protocols for the Js engine because the undelying implementation doesn't allow that.
s
I see. thanks
Copy code
HttpClient(Darwin) {
    engine {
        configureSession {
            setProtocolClasses(listOf(HttpProtocolVersion.HTTP_2_0))
        }
    }
}
is that correct for Darwin?
setProtocolClasses
accepts
List<*>
so not sure what it actually expects
a
Can you please explain your use case? Do you need to disable some protocols? The description of the
protocolClasses
can be found here.
s
I just want to make sure it's using http2. the ktor docs I linked above sound like you need to enable it manually
a
If the client supports HTTP/2 and the server decides to upgrade to that version, then HTTP/2 will be used for the communication. With the OkHttp engine, you can use the
Protocol.H2_PRIOR_KNOWLEDGE
object to avoid a round trip for the upgrade.
👍🏻 1