Record Class SafeHttpResponse

java.lang.Object
java.lang.Record
com.kingsrook.qqq.backend.core.utils.http.SafeHttpResponse

public record SafeHttpResponse(int statusCode, Map<String,String> headers, byte[] body, boolean truncated, String remoteAddress, long durationMillis) extends Record
The result of a SafeHttpClient request: the status, the headers (first value of each, names lower-cased), at most the policy's maxResponseBytes of the body, whether the body was cut off, the address actually connected to and the duration.
  • Constructor Summary

    Constructors
    Constructor
    Description
    SafeHttpResponse(int statusCode, Map<String,String> headers, byte[] body, boolean truncated, String remoteAddress, long durationMillis)
    Defensive copies: the response is immutable.
  • Method Summary

    Modifier and Type
    Method
    Description
    byte[]
    The body bytes read (a copy).
    bodyExcerpt(int maxChars)
    The body as UTF-8 text, cut to at most maxChars.
    long
    Returns the value of the durationMillis record component.
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    header(String name)
    A header value (case-insensitive), or null.
    Returns the value of the headers record component.
    boolean
    True for a 2xx status.
    Returns the value of the remoteAddress record component.
    int
    Returns the value of the statusCode record component.
    final String
    Returns a string representation of this record class.
    boolean
    Returns the value of the truncated record component.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • SafeHttpResponse

      public SafeHttpResponse(int statusCode, Map<String,String> headers, byte[] body, boolean truncated, String remoteAddress, long durationMillis)
      Defensive copies: the response is immutable.
  • Method Details

    • body

      public byte[] body()
      The body bytes read (a copy).
    • isSuccess

      public boolean isSuccess()
      True for a 2xx status.
    • header

      public String header(String name)
      A header value (case-insensitive), or null.
    • bodyExcerpt

      public String bodyExcerpt(int maxChars)
      The body as UTF-8 text, cut to at most maxChars.
    • toString

      public final 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
    • 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 the compare method from their corresponding wrapper classes.
      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.
    • statusCode

      public int statusCode()
      Returns the value of the statusCode record component.
      Returns:
      the value of the statusCode record component
    • headers

      public Map<String,String> headers()
      Returns the value of the headers record component.
      Returns:
      the value of the headers record component
    • truncated

      public boolean truncated()
      Returns the value of the truncated record component.
      Returns:
      the value of the truncated record component
    • remoteAddress

      public String remoteAddress()
      Returns the value of the remoteAddress record component.
      Returns:
      the value of the remoteAddress record component
    • durationMillis

      public long durationMillis()
      Returns the value of the durationMillis record component.
      Returns:
      the value of the durationMillis record component