Record Class HttpResponseStatus

java.lang.Object
java.lang.Record
org.microproxy.http.HttpResponseStatus
Record Components:
code - three-digit status code, from 100 to 999
reasonPhrase - reason phrase, without CR or LF characters

public record HttpResponseStatus(int code, String reasonPhrase) extends Record
An HTTP status code and reason phrase. Equality considers only the code, so a response from a server with a non-standard reason phrase still equals the corresponding constant.
  • Field Details

  • Constructor Details

    • HttpResponseStatus

      public HttpResponseStatus(int code, String reasonPhrase)
      Creates a status with a validated code and reason phrase.
      Parameters:
      code - three-digit status code, from 100 to 999
      reasonPhrase - reason phrase, without CR or LF characters
      Throws:
      IllegalArgumentException - if the code or reason phrase is invalid
  • Method Details

    • valueOf

      public static HttpResponseStatus valueOf(int code)
      Returns the well-known status for code, or a new one with a generic phrase.
      Parameters:
      code - three-digit status code
      Returns:
      a status with the standard or generic reason phrase
      Throws:
      IllegalArgumentException - if the code is outside 100 to 999
    • valueOf

      public static HttpResponseStatus valueOf(int code, String reasonPhrase)
      Returns a status with code and reasonPhrase, reusing constants when equal.
      Parameters:
      code - three-digit status code
      reasonPhrase - reason phrase, without CR or LF characters
      Returns:
      a status retaining the supplied reason phrase
      Throws:
      IllegalArgumentException - if the code or reason phrase is invalid
    • equals

      public 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.
    • hashCode

      public 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
    • toString

      public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • code

      public int code()
      Returns the value of the code record component.
      Returns:
      the value of the code record component
    • reasonPhrase

      public String reasonPhrase()
      Returns the value of the reasonPhrase record component.
      Returns:
      the value of the reasonPhrase record component