java.lang.Object
com.pixelservices.flash.components.http.lifecycle.Response

public class Response extends Object
Represents an HTTP response, supporting serialization to a ByteBuffer.
  • Constructor Details

    • Response

      public Response()
      Constructs a new Response object with default status and a default content type of "text/plain".
  • Method Details

    • status

      public Response status(int code)
      Sets the HTTP status code of the response.
      Parameters:
      code - the status code to set
      Returns:
      the updated Response object
      Throws:
      IllegalStateException - if the response is already finalized
    • type

      public Response type(String contentType)
      Sets the content type of the response.
      Parameters:
      contentType - the content type to set
      Returns:
      the updated Response object
      Throws:
      IllegalStateException - if the response is already finalized
    • header

      public Response header(String key, String value)
      Adds a header to the response.
      Parameters:
      key - the header name
      value - the header value
      Returns:
      the updated Response object
      Throws:
      IllegalStateException - if the response is already finalized
    • body

      public Response body(Object body)
      Sets the body of the response. Warning: Overrides existing body content.
      Parameters:
      body - the body content
      Returns:
      the updated Response object
      Throws:
      IllegalStateException - if the response is already finalized
    • getBody

      public Object getBody()
      Retrieves the body of the response.
      Returns:
      the body content
    • finalizeResponse

      public void finalizeResponse()
      Marks the response as finalized, preventing further modifications.
    • getSerialized

      public ByteBuffer getSerialized()
      Serializes the response into a ByteBuffer.
      Returns:
      the serialized response as a ByteBuffer
    • getSerializedBody

      public byte[] getSerializedBody()
      Serializes the response body based on its content type.
      Returns:
      the serialized body as a byte array
      Throws:
      UnsupportedOperationException - if the content type is unsupported or the body type is invalid
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getBodyBytes

      public byte[] getBodyBytes()
      Gets the body as a byte array.
      Returns:
      the body as a byte array
    • getContentType

      public String getContentType()
      Gets the content type of the response.
      Returns:
      the content type
    • getHeaderBytes

      public byte[] getHeaderBytes()
      Gets just the header portion of the response as a byte array. This is useful for chunked sending of large responses.
      Returns:
      the headers as a byte array
    • getHeaderBuffer

      public ByteBuffer getHeaderBuffer()
      Gets a ByteBuffer containing just the headers.
      Returns:
      ByteBuffer with headers