Class HTTPResponse

java.lang.Object
org.omegazero.common.util.SimpleAttachmentContainer
All Implemented Interfaces:
Serializable, org.omegazero.common.util.AttachmentContainer

public class HTTPResponse extends HTTPMessage
Represents a HTTP response, a specific type of HTTPMessage.
Since:
1.2.1
See Also:
  • Field Details

    • status

      protected int status
      The HTTP response status.
  • Constructor Details

    • HTTPResponse

      public HTTPResponse(int status, String version, HTTPHeaderContainer headers)
      Creates a new HTTPResponse.

      Note that no deep copy of the headers will be created, meaning changes made to the given HTTPHeaderContainer will reflect on this HTTPResponse.

      Parameters:
      status - The HTTP response status code
      version - The HTTP version
      headers - The HTTP headers, or null to create an empty set of headers
    • HTTPResponse

      public HTTPResponse(HTTPResponse response)
      Copies the given HTTPResponse.
      Parameters:
      response - The HTTPResponse to copy from
      See Also:
  • Method Details

    • responseLine

      public String responseLine()
      Generates a HTTP/1-style response line of the form HTTP/[version] [status].
      Returns:
      A response line
    • getStatus

      public int getStatus()
      Returns the HTTP response status code of this HTTPResponse.
      Returns:
      The HTTP response status code
      See Also:
    • setStatus

      public void setStatus(int status)
      Sets the HTTP response status code of this HTTPResponse.
      Parameters:
      status - The new HTTP response status code
      Throws:
      IllegalStateException - If this HTTPMessage is locked
      See Also:
    • isIntermediateMessage

      public boolean isIntermediateMessage()
      Determines whether this HTTPResponse is an intermediate message, meaning it is followed up by another HTTPResponse to complete the HTTP exchange or it has some other special meaning.

      This applies to responses with 1xx response codes.

      Returns:
      true if this HTTPResponse is an intermediate message
    • hasResponseBody

      public boolean hasResponseBody()
      Determines whether this HTTPResponse has a response body if initiated by the given request. This is true if this response's status has a response body, and the request that initiated this response did not use the HEAD method, or the CONNECT method with a 2xx response status.

      A call to this method is equivalent to a call to

       
       response.hasResponseBody(response.getOther());
       
       
      Returns:
      true if this HTTPResponse should contain a response body
      See Also:
    • hasResponseBody

      public boolean hasResponseBody(HTTPRequest request)
      Determines whether this HTTPResponse has a response body if initiated by the given request. This is true if this response's status has a response body, and the given request did not use the HEAD method, or the CONNECT method with a 2xx response status.
      Parameters:
      request - The request to check with. May be null, in which case only the response status is checked
      Returns:
      true if this HTTPResponse should contain a response body if initiated by the given request
      See Also:
    • getOther

      public HTTPRequest getOther()
      Description copied from class: HTTPMessage
      Returns the other HTTPMessage of the HTTP message exchange this HTTPMessage is part of. This may be null.

      For example, for HTTPRequests, this would be the response of the request, and vice versa.

      Overrides:
      getOther in class HTTPMessage
      Returns:
      The other HTTPMessage involved in the HTTP message exchange
    • hasResponseBody

      public static boolean hasResponseBody(int status)
      Determines whether responses with the given status code should have a response body. Responses with statuses 1xx, 204, and 304 do not have a response body.
      Parameters:
      status - A HTTP status code
      Returns:
      true if a response with the given status code should have a response body
      See Also: