org.cybergarage.http

## Class HTTPRequest

- java.lang.Object
- - org.cybergarage.http.HTTPPacket
  - - org.cybergarage.http.HTTPRequest

- Direct Known Subclasses:
    SOAPRequest, SSDPRequest, SubscriptionRequest

      public class HTTPRequest
      extends HTTPPacket

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `HTTPRequest()`
    `HTTPRequest(HTTPSocket httpSock)`
    `HTTPRequest(InputStream in)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `String` | `getFirstLineString()`
    `String` | `getHeader()`
    `String` | `getHTTPVersion()`
    `String` | `getLocalAddress()`
    `int` | `getLocalPort()`
    `String` | `getMethod()`
    `ParameterList` | `getParameterList()`
    `String` | `getParameterValue(String name)`
    `String` | `getRequestHost()`
    `int` | `getRequestPort()`
    `HTTPSocket` | `getSocket()`
    `String` | `getURI()`
    `boolean` | `isGetRequest()`
    `boolean` | `isHeadRequest()`
    `boolean` | `isKeepAlive()`
    `boolean` | `isMethod(String method)`
    `boolean` | `isNotifyRequest()`
    `boolean` | `isPostRequest()`
    `boolean` | `isSOAPAction()`
    `boolean` | `isSubscribeRequest()`
    `boolean` | `isUnsubscribeRequest()`
    `boolean` | `parseRequestLine(String lineStr)` Parses an HTTP request line and extracts method, URI, and version.
    `boolean` | `post(HTTPResponse httpRes)`
    `HTTPResponse` | `post(String host, int port)`
    `HTTPResponse` | `post(String host, int port, boolean isKeepAlive)`
    `void` | `print()` Prints the HTTP request to the debug message stream.
    `boolean` | `read()`
    `boolean` | `returnBadRequest()` Sends an HTTP 400 Bad Request response with no content.
    `boolean` | `returnOK()` Sends an HTTP 200 OK response with no content.
    `boolean` | `returnResponse(int statusCode)` Sends an HTTP response with the specified status code and no content.
    `void` | `set(HTTPRequest httpReq)`
    `void` | `setBindHost(String host)` I2P - bind HTTP socket to specified local host address
    `void` | `setMethod(String value)`
    `void` | `setRequestHost(String host)`
    `void` | `setRequestPort(int host)`
    `void` | `setSocket(HTTPSocket value)`
    `void` | `setURI(String value)` Sets the URI for this HTTP request without relative URL conversion.
    `void` | `setURI(String value, boolean isCheckRelativeURL)` Sets the URI for this HTTP request.
    `String` | `toString()`

    - ### Methods inherited from class org.cybergarage.http.HTTPPacket

      `addHeader, addHeader, clearHeaders, getCacheControl, getCharSet, getConnection, getContent, getContentInputStream, getContentLanguage, getContentLength, getContentRange, getContentRangeFirstPosition, getContentRangeInstanceLength, getContentRangeLastPosition, getContentString, getContentType, getDate, getFirstLine, getFirstLineToken, getHeader, getHeader, getHeaderString, getHeaderValue, getHost, getIntegerHeaderValue, getLongHeaderValue, getNHeaders, getServer, getStringHeaderValue, getStringHeaderValue, getTransferEncoding, getVersion, hasConnection, hasContent, hasContentInputStream, hasContentRange, hasFirstLine, hasHeader, hasTransferEncoding, init, isChunked, isCloseConnection, isKeepAliveConnection, read, set, set, set, set, setCacheControl, setCacheControl, setCacheControl, setConnection, setContent, setContent, setContent, setContent, setContentInputStream, setContentLanguage, setContentLength, setContentRange, setContentType, setDate, setHeader, setHeader, setHeader, setHeader, setHost, setIntegerHeader, setLongHeader, setServer, setStringHeader, setStringHeader, setTransferEncoding, setVersion`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### HTTPRequest

          public HTTPRequest()

    - #### HTTPRequest

          public HTTPRequest(HTTPSocket httpSock)

    - #### HTTPRequest

          public HTTPRequest(InputStream in)

  - ### Method Detail

    - #### getFirstLineString

          public String getFirstLineString()

    - #### getHeader

          public String getHeader()

    - #### getHTTPVersion

          public String getHTTPVersion()

    - #### getLocalAddress

          public String getLocalAddress()

    - #### getLocalPort

          public int getLocalPort()

    - #### getMethod

          public String getMethod()

    - #### getParameterList

          public ParameterList getParameterList()

    - #### getParameterValue

          public String getParameterValue(String name)

    - #### getRequestHost

          public String getRequestHost()

    - #### getRequestPort

          public int getRequestPort()

    - #### getSocket

          public HTTPSocket getSocket()

    - #### getURI

          public String getURI()

    - #### isGetRequest

          public boolean isGetRequest()

    - #### isHeadRequest

          public boolean isHeadRequest()

    - #### isKeepAlive

          public boolean isKeepAlive()

    - #### isMethod

          public boolean isMethod(String method)

    - #### isNotifyRequest

          public boolean isNotifyRequest()

    - #### isPostRequest

          public boolean isPostRequest()

    - #### isSOAPAction

          public boolean isSOAPAction()

    - #### isSubscribeRequest

          public boolean isSubscribeRequest()

    - #### isUnsubscribeRequest

          public boolean isUnsubscribeRequest()

    - #### parseRequestLine

          public boolean parseRequestLine(String lineStr)

      Parses an HTTP request line and extracts method, URI, and version.

      This method parses a request line in the format "METHOD URI VERSION" (e.g., "GET /path HTTP/1.1") and sets the corresponding properties on this HTTP request object.

      Parameters:
        `lineStr` - the request line string to parse
      Returns:
        true if parsing was successful and all three components were found, false otherwise

    - #### post

          public boolean post(HTTPResponse httpRes)

    - #### post

          public HTTPResponse post(String host,
                                   int port)

    - #### post

          public HTTPResponse post(String host,
                                   int port,
                                   boolean isKeepAlive)

    - #### print

          public void print()

      Prints the HTTP request to the debug message stream.

      This method outputs the complete HTTP request including headers and content to the debug logging system using Debug.message(). Useful for debugging HTTP request processing.

    - #### read

          public boolean read()

    - #### returnBadRequest

          public boolean returnBadRequest()

      Sends an HTTP 400 Bad Request response with no content.

      This is a convenience method that sends a 400 Bad Request status code response, typically used when the client request is malformed or cannot be understood by the server.

      Returns:
        true if the response was sent successfully, false otherwise

    - #### returnOK

          public boolean returnOK()

      Sends an HTTP 200 OK response with no content.

      This is a convenience method that sends a 200 OK status code response, typically used to indicate successful request processing when no response body is needed.

      Returns:
        true if the response was sent successfully, false otherwise

    - #### returnResponse

          public boolean returnResponse(int statusCode)

      Sends an HTTP response with the specified status code and no content.

      This method creates a new HTTP response with the given status code, sets content length to 0, and sends it back to the client using the post() method. This is commonly used for error responses or responses that don't require a body.

      Parameters:
        `statusCode` - the HTTP status code to send (e.g., 200, 404, 500)
      Returns:
        true if the response was sent successfully, false otherwise

    - #### set

          public void set(HTTPRequest httpReq)

    - #### setBindHost

          public void setBindHost(String host)

      I2P - bind HTTP socket to specified local host address
      Parameters:
        `host` - null to not bind to a particlar local address

    - #### setMethod

          public void setMethod(String value)

    - #### setRequestHost

          public void setRequestHost(String host)

    - #### setRequestPort

          public void setRequestPort(int host)

    - #### setSocket

          public void setSocket(HTTPSocket value)

    - #### setURI

          public void setURI(String value)

      Sets the URI for this HTTP request without relative URL conversion.

      This is a convenience method that calls `setURI(String, boolean)` with isCheckRelativeURL set to false.

      Parameters:
        `value` - the URI string to set

    - #### setURI

          public void setURI(String value,
                             boolean isCheckRelativeURL)

      Sets the URI for this HTTP request.

      Sets the request URI and optionally converts it to a relative URL. This is used to handle both absolute and relative URLs in HTTP requests.

      Parameters:
        `value` - the URI string to set
        `isCheckRelativeURL` - if true, converts the URI to a relative URL using HTTP.toRelativeURL()

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`