public class HTTPRequest extends HTTPPacket
| Constructor and Description |
|---|
HTTPRequest() |
HTTPRequest(HTTPSocket httpSock) |
HTTPRequest(InputStream in) |
| 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() |
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 getRequestHost()
public int getRequestPort()
public HTTPSocket getSocket()
public String getURI()
public boolean isGetRequest()
public boolean isHeadRequest()
public boolean isKeepAlive()
public boolean isMethod(String method)
public 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)
public HTTPResponse post(String host, int port)
public HTTPResponse post(String host, int port, boolean isKeepAlive)
public 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)
public void setBindHost(String host)
host - null to not bind to a particlar local addresspublic void setMethod(String value)
public void setRequestHost(String host)
public void setRequestPort(int host)
public void setSocket(HTTPSocket value)
public 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()