Record Class HttpProtocolVersion

java.lang.Object
java.lang.Record
org.apache.juneau.http.HttpProtocolVersion
Record Components:
protocol - The protocol name (e.g. "HTTP"). Must not be null.
major - The major version number (e.g. 1).
minor - The minor version number (e.g. 1).

public record HttpProtocolVersion(String protocol, int major, int minor) extends Record
The HTTP protocol version that appears in request and response start lines (e.g. "HTTP/1.1").

Mirrors the semantics of org.apache.http.ProtocolVersion without the Apache HttpCore dependency. The protocol name and major/minor numbers are stored separately so callers can compare versions numerically.

Create instances via of(String, int, int) or parse(String):

// "HTTP/1.1" HttpProtocolVersion v1 = HttpProtocolVersion.HTTP_1_1; // Parse from a wire string HttpProtocolVersion v2 = HttpProtocolVersion.parse("HTTP/2.0");

Since:
10.0.0
  • Field Details

  • Constructor Details

    • HttpProtocolVersion

      public HttpProtocolVersion(String protocol, int major, int minor)
      Canonical constructor.
      Parameters:
      protocol - The protocol name. Must not be null.
      major - The major version (must be >= 0).
      minor - The minor version (must be >= 0).
  • Method Details

    • of

      public static HttpProtocolVersion of(String protocol, int major, int minor)
      Creates a protocol version with the given protocol name and version numbers.
      Parameters:
      protocol - The protocol name (e.g. "HTTP"). Must not be null.
      major - The major version number.
      minor - The minor version number.
      Returns:
      A new instance. Never null.
    • parse

      public static HttpProtocolVersion parse(String s)
      Parses a wire-format protocol version string.

      Accepts the standard PROTOCOL/major.minor form (e.g. "HTTP/1.1") and the abbreviated PROTOCOL/major form (e.g. "HTTP/2", which is parsed as major=2, minor=0).

      Parameters:
      s - The protocol version string. Must not be null.
      Returns:
      A new instance. Never null.
      Throws:
      IllegalArgumentException - If the string cannot be parsed.
    • toString

      public String toString()
      Returns the canonical wire-format string (e.g. "HTTP/1.1").
      Specified by:
      toString in class Record
      Returns:
      The wire-format string. Never null.
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • protocol

      public String protocol()
      Returns the value of the protocol record component.
      Returns:
      the value of the protocol record component
    • major

      public int major()
      Returns the value of the major record component.
      Returns:
      the value of the major record component
    • minor

      public int minor()
      Returns the value of the minor record component.
      Returns:
      the value of the minor record component