okhttp / okhttp3 / Protocol


enum class Protocol

Protocols that OkHttp implements for ALPN selection.

Protocol vs Scheme

Despite its name, java.net.URL.getProtocol returns the scheme (http, https, etc.) of the URL, not the protocol (http/1.1, spdy/3.1, etc.). OkHttp uses the word protocol to identify how HTTP messages are framed.

Enum Values

Name Summary
HTTP_1_0 An obsolete plaintext framing that does not use persistent sockets by default.
HTTP_1_1 A plaintext framing that includes persistent connections.
HTTP_2 The IETF’s binary-framed protocol that includes header compression, multiplexing multiple requests on the same socket, and server-push. HTTP/1.1 semantics are layered on HTTP/2.
H2_PRIOR_KNOWLEDGE Cleartext HTTP/2 with no “upgrade” round trip. This option requires the client to have prior knowledge that the server supports cleartext HTTP/2.
QUIC QUIC (Quick UDP Internet Connection) is a new multiplexed and secure transport atop UDP, designed from the ground up and optimized for HTTP/2 semantics. HTTP/1.1 semantics are layered on HTTP/2.


Name Summary
toString Returns the string used to identify this protocol for ALPN, like “http/1.1”, “spdy/3.1” or “h2”.fun toString():String

Companion Object Functions

Name Summary
get Returns the protocol identified by protocol.fun get(protocol:String):Protocol