Record Class SafeFetchResponse

java.lang.Object
java.lang.Record
io.meeds.commons.http.SafeFetchResponse
Record Components:
status - the HTTP status answered
notModified - whether the server answered 304: nothing changed since the validators sent
truncated - whether the body was cut at the request's limit, as the request allowed
body - the body read; empty for an answer without one, null when not modified
contentType - the Content-Type header answered, as sent, or null
headers - the first value of every header answered, by name, case ignored; a value carrying a control character other than a tab is left out, as a request would refuse to send it
uri - the URL the answer came from, after the redirects followed

public record SafeFetchResponse(int status, boolean notModified, boolean truncated, byte[] body, String contentType, Map<String,String> headers, URI uri) extends Record
What SafeHttpFetcher read from a URL: a 2xx answer with its body, or a 304 to a conditional read.
  • Constructor Details

    • SafeFetchResponse

      public SafeFetchResponse(int status, boolean notModified, boolean truncated, byte[] body, String contentType, Map<String,String> headers, URI uri)
      Keeps the headers in a case-insensitive, unmodifiable map.
      Parameters:
      status - the HTTP status answered
      notModified - whether the server answered 304
      truncated - whether the body was cut at the limit
      body - the body read
      contentType - the Content-Type answered
      headers - the headers answered
      uri - the URL the answer came from
  • Method Details

    • header

      public String header(String name)
      The first value of a header answered.
      Parameters:
      name - the header name, case ignored
      Returns:
      the value, or null when the header was not answered or its value carried a control character other than a tab
    • mediaType

      public String mediaType()
      The media type answered: the Content-Type without its parameters, lower-cased.
      Returns:
      the media type, or null when none was answered
    • equals

      public boolean equals(Object other)
      Compares by content: the body is an array.
      Specified by:
      equals in class Record
      Parameters:
      other - the other object
      Returns:
      true when every component is equal, the body byte by byte
    • hashCode

      public int hashCode()
      Hashes by content, the body included.
      Specified by:
      hashCode in class Record
      Returns:
      the hash
    • toString

      public String toString()
      Describes the answer by its status, size and type; never the body, never the URL, which may embed a secret.
      Specified by:
      toString in class Record
      Returns:
      the description
    • status

      public int status()
      Returns the value of the status record component.
      Returns:
      the value of the status record component
    • notModified

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

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

      public byte[] body()
      Returns the value of the body record component.
      Returns:
      the value of the body record component
    • contentType

      public String contentType()
      Returns the value of the contentType record component.
      Returns:
      the value of the contentType record component
    • headers

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

      public URI uri()
      Returns the value of the uri record component.
      Returns:
      the value of the uri record component