java.lang.Object
org.cybergarage.http.HTTPPacket
org.cybergarage.http.HTTPResponse
Direct Known Subclasses:
SOAPResponse, SSDPResponse, SubscriptionResponse

public class HTTPResponseextends HTTPPacket
HTTP response message with status code, headers, and content body.
  • Field Details

    • statusCode

      private int statusCode
      /////////////////////////////////////////////
  • Constructor Details

    • HTTPResponse

      public HTTPResponse()
      Creates a new HTTP response with default settings. Sets HTTP version to 1.1, content type to HTML, server name, and empty content.
    • HTTPResponse

      public HTTPResponse(HTTPResponse httpRes)
      Creates a copy of an existing HTTP response.
      Parameters:
      httpRes - HTTP response to copy
    • HTTPResponse

      public HTTPResponse(InputStream in)
      Creates an HTTP response by parsing from an input stream.
      Parameters:
      in - input stream containing the HTTP response
    • HTTPResponse

      public HTTPResponse(HTTPSocket httpSock)
      Creates an HTTP response from an HTTP socket.
      Parameters:
      httpSock - HTTP socket containing the response data
  • Method Details

    • setStatusCode

      public void setStatusCode(int code)
      Sets the HTTP status code of this response.
      Parameters:
      code - HTTP status code (e.g., 200, 404, 500)
    • getStatusCode

      public int getStatusCode()
      Gets the HTTP status code of this response.
      Returns:
      HTTP status code, or parsed status code from first line if not explicitly set
    • isSuccessful

      public boolean isSuccessful()
      Checks if this response has a successful status code.
      Returns:
      true if status code is in the 2xx range, false otherwise
    • getStatusLineString

      public String getStatusLineString()
      Gets the status line string of this HTTP response.
      Returns:
      status line in format "HTTP/version code message"
    • getHeader

      public String getHeader()
      Return the full header string for this HTTP response.
      Returns:
      the header string
    • toString

      public String toString()
      /////////////////////////////////////////////
      Overrides:
      toString in class Object
    • print

      public void print()
      Outputs the full HTTP response to the debug log.