- Direct Known Subclasses:
SOAPRequest, SSDPRequest, SubscriptionRequest
Field Summary
FieldsModifier and TypeFieldDescriptionprivate StringLocal address the connection is bound to.private HTTPSocket/////////////////////////////////////////////private String/////////////////////////////////////////////private Socket/////////////////////////////////////////////private String/////////////////////////////////////////////private intPort the request was sent to, -1 until known.private String/////////////////////////////////////////////Constructor Summary
ConstructorsConstructorDescription/////////////////////////////////////////////Parses an HTTP request from the given input stream.HTTPRequest(HTTPSocket httpSock) Creates an HTTP request from the given socket's input stream.Method Summary
All MethodsModifier and TypeMethodDescriptionReturns the first line of the HTTP request (method, URI, and version).Returns the complete HTTP header as a string.Returns the HTTP version string for this request.Returns the local address of the underlying socket.intReturns the local port of the underlying socket.Returns the HTTP method.Parses the URI query string and returns the parameters as a ParameterList.getParameterValue(String name) Returns the value of the specified URI query parameter.Returns the request host.intReturns the request port.Returns the HTTPSocket for this request.getURI()Returns the request URI.booleanDetermines if this is a GET request.booleanDetermines if this is a HEAD request.booleanDetermines if this connection should be kept alive.booleanChecks if the HTTP method matches the given string.booleanDetermines if this is a NOTIFY request.booleanDetermines if this is a POST request.booleanChecks if this request has a SOAPAction header.booleanDetermines if this is a SUBSCRIBE request.booleanDetermines if this is an UNSUBSCRIBE request.booleanparseRequestLine(String lineStr) Parses an HTTP request line and extracts method, URI, and version.Posts this HTTP request to the specified host and port with no keep-alive.Posts this HTTP request to the specified host and port.booleanpost(HTTPResponse httpRes) Posts an HTTP response back to the client.voidprint()Prints the HTTP request to the debug message stream.booleanread()Reads the HTTP request from the underlying socket.booleanSends an HTTP 400 Bad Request response with no content.booleanreturnOK()Sends an HTTP 200 OK response with no content.booleanreturnResponse(int statusCode) Sends an HTTP response with the specified status code and no content.voidset(HTTPRequest httpReq) Copies the contents of the given HTTP request into this request.voidsetBindHost(String host) I2P - bind HTTP socket to specified local host addressvoidSets the HTTP method (e.g., GET, POST).voidsetRequestHost(String host) Sets the host for this request.voidsetRequestPort(int host) Sets the port for this request.voidsetSocket(HTTPSocket value) Sets the HTTPSocket for this request.voidSets the URI for this HTTP request without relative URL conversion.voidSets the URI for this HTTP request.toString()/////////////////////////////////////////////Methods inherited from class 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, setVersionModifier and TypeMethodDescriptionvoidAdds a header with the specified name and value.voidaddHeader(HTTPHeader header) Adds a header to this HTTP packet.voidClears all headers from this HTTP packet.Get the Cache-Control header value.Gets the character set from the Content-Type header.Gets the Connection header value.byte[]Gets the content of this HTTP packet.Gets the content input stream.Gets the Content-Language header value.longGets the content length from the Content-Length header.long[]Gets the content range values as an array.longGet the first position from the content range.longGet the instance length from the content range.longGet the last position from the content range.Gets the content of this HTTP packet as a string.Gets the Content-Type header value.getDate()Get the Date header value.protected StringGets the first line of the HTTP packet.protected StringgetFirstLineToken(int num) Gets a specific token from the first line using HTTP request line delimiters.getHeader(int n) Gets the header at the specified index.Gets the header with the specified name, ignoring case.Gets all headers as a formatted string.getHeaderValue(String name) Gets the value of a header by name.getHost()Get the Host header value.intgetIntegerHeaderValue(String name) Gets an integer header value by name.longgetLongHeaderValue(String name) Gets a long header value by name.intGets the number of headers in this HTTP packet.Get the Server header value.getStringHeaderValue(String name) Gets a string header value, stripping double quotes if present.getStringHeaderValue(String name, String startWidth, String endWidth) Gets a string header value, stripping the specified delimiters if present.Get the Transfer-Encoding header value.Gets the HTTP version of this packet.booleanChecks if the Connection header is set.booleanChecks if this HTTP packet has content.booleanChecks if a content input stream has been set.booleanChecks if the Content-Range or Range header is set.booleanChecks if the first line of the HTTP packet has been set.booleanChecks if a header with the specified name exists.booleanCheck if the Transfer-Encoding header is set.voidinit()Initializes the HTTP packet to empty state.booleanCheck if the content is chunked.booleanChecks if the Connection header is set to close.booleanChecks if the Connection header is set to keep-alive.booleanread(HTTPSocket httpSock) Reads and parses HTTP packet from a socket.protected booleanset(InputStream in) Parses HTTP packet data from an input stream including content.protected booleanset(InputStream in, boolean onlyHeaders) Parses HTTP packet data from an input stream.protected voidset(HTTPPacket httpPacket) Copies all data from another HTTP packet to this packet.protected booleanset(HTTPSocket httpSock) Parses HTTP packet data from an HTTP socket.voidsetCacheControl(int value) Set the Cache-Control header with a max-age value.voidsetCacheControl(String directive) Set the Cache-Control header.voidsetCacheControl(String directive, int value) Set the Cache-Control header with a directive and value.voidsetConnection(String value) Sets the Connection header.voidsetContent(byte[] data) Sets the content of this HTTP packet.voidsetContent(byte[] data, boolean updateWithContentLength) Sets the content of this HTTP packet.voidsetContent(String data) Sets the content of this HTTP packet from a string.voidsetContent(String data, boolean updateWithContentLength) Sets the content of this HTTP packet from a string.voidSets the content input stream.voidsetContentLanguage(String code) Sets the Content-Language header.voidsetContentLength(long len) Sets the Content-Length header.voidsetContentRange(long firstPos, long lastPos, long length) Sets the Content-Range header.voidsetContentType(String type) Sets the Content-Type header.voidSet the Date header.voidSets the value of a header from an integer.voidSets the value of a header from a long.voidSets the value of a header.voidsetHeader(HTTPHeader header) Sets the value of a header from an HTTP header object.voidSet the Host header.voidsetIntegerHeader(String name, int value) Sets an integer header value.voidsetLongHeader(String name, long value) Sets a long header value.voidSet the Server header.voidsetStringHeader(String name, String value) Sets a string header value, wrapping it with double quotes if not already wrapped.voidsetStringHeader(String name, String value, String startWidth, String endWidth) Sets a string header value, wrapping it with the specified delimiters if not already wrapped.voidsetTransferEncoding(String value) Set the Transfer-Encoding header.voidsetVersion(String ver) Sets the HTTP version for this packet.
Field Details
method
/////////////////////////////////////////////uri
/////////////////////////////////////////////requestHost
/////////////////////////////////////////////requestPort
private int requestPortPort the request was sent to, -1 until known.httpSocket
/////////////////////////////////////////////postSocket
/////////////////////////////////////////////bindTo
Local address the connection is bound to.
Constructor Details
HTTPRequest
public HTTPRequest()/////////////////////////////////////////////HTTPRequest
Parses an HTTP request from the given input stream.- Parameters:
in- the stream supplying the raw request bytes
HTTPRequest
Creates an HTTP request from the given socket's input stream.- Parameters:
httpSock- the socket supplying the request bytes, retained on the new request
Method Details
setMethod
Sets the HTTP method (e.g., GET, POST).- Parameters:
value- the HTTP method string
getMethod
isMethod
Checks if the HTTP method matches the given string.- Parameters:
method- the method string to compare- Returns:
- true if the methods match (case-insensitive), false otherwise
isGetRequest
public boolean isGetRequest()Determines if this is a GET request.- Returns:
- true if the method is GET, false otherwise
isPostRequest
public boolean isPostRequest()Determines if this is a POST request.- Returns:
- true if the method is POST, false otherwise
isHeadRequest
public boolean isHeadRequest()Determines if this is a HEAD request.- Returns:
- true if the method is HEAD, false otherwise
isSubscribeRequest
public boolean isSubscribeRequest()Determines if this is a SUBSCRIBE request.- Returns:
- true if the method is SUBSCRIBE, false otherwise
isUnsubscribeRequest
public boolean isUnsubscribeRequest()Determines if this is an UNSUBSCRIBE request.- Returns:
- true if the method is UNSUBSCRIBE, false otherwise
isNotifyRequest
public boolean isNotifyRequest()Determines if this is a NOTIFY request.- Returns:
- true if the method is NOTIFY, false otherwise
setURI
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
HTTPrequests.- Parameters:
value- the URI string to setisCheckRelativeURL- if true, converts the URI to a relative URL using HTTP.toRelativeURL()
setURI
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
getURI
getParameterList
Parses the URI query string and returns the parameters as a ParameterList.- Returns:
- the ParameterList containing all query parameters, or an empty list if none exist
getParameterValue
isSOAPAction
public boolean isSOAPAction()Checks if this request has a SOAPAction header.- Returns:
- true if the SOAPAction header is present, false otherwise
setRequestHost
Sets the host for this request.- Parameters:
host- the host string
getRequestHost
setRequestPort
public void setRequestPort(int host) Sets the port for this request.- Parameters:
host- the port number
getRequestPort
public int getRequestPort()Returns the request port.- Returns:
- the port number
setSocket
Sets the HTTPSocket for this request.- Parameters:
value- the HTTPSocket to set
getSocket
Returns the HTTPSocket for this request.- Returns:
- the HTTPSocket, or null if not set
getLocalAddress
Returns the local address of the underlying socket.- Returns:
- the local address string
getLocalPort
public int getLocalPort()Returns the local port of the underlying socket.- Returns:
- the local port number
parseRequestLine
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
getHTTPVersion
Returns the HTTP version string for this request.- Returns:
- the HTTP version (e.g., "HTTP/1.1")
getFirstLineString
Returns the first line of the HTTP request (method, URI, and version).- Returns:
- the request line string
getHeader
Returns the complete HTTP header as a string.- Returns:
- the header string including the request line and headers
isKeepAlive
public boolean isKeepAlive()Determines if this connection should be kept alive.- Returns:
- true if keep-alive is enabled, false otherwise
read
public boolean read()Reads the HTTP request from the underlying socket.- Returns:
- true if the request was read successfully, false otherwise
post
Posts an HTTP response back to the client.- Parameters:
httpRes- the HTTP response to send- Returns:
- true if the response was sent successfully, false otherwise
setBindHost
I2P - bind HTTP socket to specified local host address- Parameters:
host- null to not bind to a particular local address
post
Posts this HTTP request to the specified host and port.- Parameters:
host- the target hostport- the target portisKeepAlive- whether to keep the connection alive- Returns:
- the HTTP response
post
Posts this HTTP request to the specified host and port with no keep-alive.- Parameters:
host- the target hostport- the target port- Returns:
- the HTTP response
set
Copies the contents of the given HTTP request into this request.- Parameters:
httpReq- the HTTP request to copy from
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(HTTPResponse)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
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
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
toString
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.