Class HttpVersion


  • public class HttpVersion
    extends Object
    Represents a HTTP version.

    Instances of this class reflect a particular HTTP version. There are well known instances for HTTP/1.0 and HTTP/1.1; these instances can be compared by identity. Other instances are constructed on demand.

    • Field Detail

      • Unknown

        public static final HttpVersion Unknown
        Instance representing an unknown HTTP version
      • Version_1_0

        public static final HttpVersion Version_1_0
        Well-known instance for HTTP/1.0
      • Version_1_1

        public static final HttpVersion Version_1_1
        Well-known instance for HTTP/1.1
    • Method Detail

      • newInstance

        public static HttpVersion newInstance​(int major,
                                              int minor)
        Get an instance for a particular version. If there is a well-known instance (e.g. for HTTP/1.0 or HTTP/1.1), that instance is returned; otherwise, a new instance is constructed.
        Parameters:
        major - the major part of the version (e.g. 1 in HTTP/1.0)
        minor - the major part of the version (e.g. 0 in HTTP/1.0)
        Returns:
        an appropriate version instance
        Throws:
        IllegalArgumentException - if major or minor are negative
      • parse

        public static HttpVersion parse​(String toParse)
                                 throws ParseException
        Get an instance for a particular version by parsing a HTTP version string. A version string is of the form "HTTP/m.n" where m and n are one or more digits; this is the same form produced by toString(), and the form used in HTTP request/response headers. If there is a well-known instance (e.g. for HTTP/1.0 or HTTP/1.1), that instance is returned; otherwise, a new instance is constructed.
        Parameters:
        toParse - the version string to parse
        Returns:
        an appropriate version instance
        Throws:
        ParseException - if the version string is badly formed
      • isUnknown

        public boolean isUnknown()
        Returns:
        true if this instance is the "unknown" instance, HttpVersion.Unknown
      • getMajor

        public int getMajor()
        Returns:
        the major part of this version (e.g. 1 for HTTP/1.0)
      • getMinor

        public int getMinor()
        Returns:
        the minor part of this version (e.g. 0 for HTTP/1.0)
      • toString

        public String toString()
        Formats this version as a HTTP version string; see parse() for details.
        Overrides:
        toString in class Object
        Returns:
        a HTTP version string, or "" if this is the unknown version