Enum Protocol

  • All Implemented Interfaces:
    Serializable, Comparable<Protocol>

    public enum Protocol
    extends Enum<Protocol>
    Protocols that OkHttp implements for ALPN selection.

    Protocol vs Scheme

    Despite its name, 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 Constant Detail

      • HTTP_1_0

        public static final Protocol HTTP_1_0
        An obsolete plaintext framing that does not use persistent sockets by default.
      • HTTP_1_1

        public static final Protocol HTTP_1_1
        A plaintext framing that includes persistent connections.

        This version of OkHttp implements RFC 2616, and tracks revisions to that spec.

      • SPDY_3

        public static final Protocol SPDY_3
        Chromium'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 SPDY/3.

        This version of OkHttp implements SPDY 3 draft 3.1. Future releases of OkHttp may use this identifier for a newer draft of the SPDY spec.

      • HTTP_2

        public static final Protocol 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.

        HTTP/2 requires deployments of HTTP/2 that use TLS 1.2 support CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 , present in Java 8+ and Android 5+. Servers that enforce this may send an exception message including the string INADEQUATE_SECURITY.

    • Method Detail

      • values

        public static Protocol[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (Protocol c : Protocol.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static Protocol valueOf​(String name)
        Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
        Parameters:
        name - the name of the enum constant to be returned.
        Returns:
        the enum constant with the specified name
        Throws:
        IllegalArgumentException - if this enum type has no constant with the specified name
        NullPointerException - if the argument is null
      • toString

        public String toString()
        Returns the string used to identify this protocol for ALPN, like "http/1.1", "spdy/3.1" or "h2".
        Overrides:
        toString in class Enum<Protocol>
        Returns:
        a printable representation of this object.