public class HTTPRequest extends HTTPPacket
| Constructor and Description |
|---|
HTTPRequest() |
HTTPRequest(HTTPSocket httpSock)Creates an HTTP request from the given socket's input stream. |
HTTPRequest(InputStream in)Parses an HTTP request from the given input stream. |
| Modifier and Type | Method and Description |
|---|---|
String | getFirstLineString()Returns the first line of the HTTP request (method, URI, and version). |
String | getHeader()Returns the complete HTTP header as a string. |
String | getHTTPVersion()Returns the HTTP version string for this request. |
String | getLocalAddress()Returns the local address of the underlying socket. |
int | getLocalPort()Returns the local port of the underlying socket. |
String | getMethod()Returns the HTTP method. |
ParameterList | getParameterList()Parses the URI query string and returns the parameters as a ParameterList. |
String | getParameterValue(String name)Returns the value of the specified URI query parameter. |
String | getRequestHost()Returns the request host. |
int | getRequestPort()Returns the request port. |
HTTPSocket | getSocket()Returns the HTTPSocket for this request. |
String | getURI()Returns the request URI. |
boolean | isGetRequest()Determines if this is a GET request. |
boolean | isHeadRequest()Determines if this is a HEAD request. |
boolean | isKeepAlive()Determines if this connection should be kept alive. |
boolean | isMethod(String method)Checks if the HTTP method matches the given string. |
boolean | isNotifyRequest()Determines if this is a NOTIFY request. |
boolean | isPostRequest()Determines if this is a POST request. |
boolean | isSOAPAction()Checks if this request has a SOAPAction header. |
boolean | isSubscribeRequest()Determines if this is a SUBSCRIBE request. |
boolean | isUnsubscribeRequest()Determines if this is an UNSUBSCRIBE request. |
boolean | parseRequestLine(String lineStr)Parses an HTTP request line and extracts method, URI, and version. |
boolean | post(HTTPResponse httpRes)Posts an HTTP response back to the client. |
HTTPResponse | post(String host,
int port)Posts this HTTP request to the specified host and port with no keep-alive. |
HTTPResponse | post(String host,
int port,
boolean isKeepAlive)Posts this HTTP request to the specified host and port. |
void | print()Prints the HTTP request to the debug message stream. |
boolean | read()Reads the HTTP request from the underlying socket. |
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)Copies the contents of the given HTTP request into this request. |
void | setBindHost(String host)I2P - bind HTTP socket to specified local host address |
void | setMethod(String value)Sets the HTTP method (e.g., GET, POST). |
void | setRequestHost(String host)Sets the host for this request. |
void | setRequestPort(int host)Sets the port for this request. |
void | setSocket(HTTPSocket value)Sets the HTTPSocket for this request. |
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() |
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, setVersionpublic HTTPRequest()
public HTTPRequest(HTTPSocket httpSock)
public HTTPRequest(InputStream in)
public String getFirstLineString()
public String getHeader()
public String getHTTPVersion()
public String getLocalAddress()
public int getLocalPort()
public String getMethod()
public ParameterList getParameterList()
public String getParameterValue(String name)
name - the parameter namepublic String getRequestHost()
public int getRequestPort()
public HTTPSocket getSocket()
public String getURI()
public boolean isGetRequest()
public boolean isHeadRequest()
public boolean isKeepAlive()
public boolean isMethod(String method)
method - the method string to comparepublic boolean isNotifyRequest()
public boolean isPostRequest()
public boolean isSOAPAction()
public boolean isSubscribeRequest()
public boolean isUnsubscribeRequest()
public boolean parseRequestLine(String lineStr)
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.
lineStr - the request line string to parsepublic boolean post(HTTPResponse httpRes)
httpRes - the HTTP response to sendpublic HTTPResponse post(String host, int port)
host - the target hostport - the target portpublic HTTPResponse post(String host, int port, boolean isKeepAlive)
host - the target hostport - the target portisKeepAlive - whether to keep the connection alivepublic void print()
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.
public boolean read()
public boolean returnBadRequest()
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.
public boolean returnOK()
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.
public boolean returnResponse(int statusCode)
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.
statusCode - the HTTP status code to send (e.g., 200, 404, 500)public void set(HTTPRequest httpReq)
httpReq - the HTTP request to copy frompublic void setBindHost(String host)
host - null to not bind to a particlar local addresspublic void setMethod(String value)
value - the HTTP method stringpublic void setRequestHost(String host)
host - the host stringpublic void setRequestPort(int host)
host - the port numberpublic void setSocket(HTTPSocket value)
value - the HTTPSocket to setpublic void setURI(String value)
This is a convenience method that calls setURI(String, boolean) with
isCheckRelativeURL set to false.
value - the URI string to setpublic void setURI(String value, boolean isCheckRelativeURL)
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.
value - the URI string to setisCheckRelativeURL - if true, converts the URI to a relative URL using
HTTP.toRelativeURL()