public class HTTPRequest extends java.lang.Object implements RunningHTTPRequest
Modifier and Type | Field and Description |
---|---|
static org.apache.log4j.Logger |
log
Used for logging.
|
(package private) java.util.Hashtable |
postParameters
Holds parsed POST parameters.
|
(package private) java.lang.String |
requestLine
The Request-Line of the request.
|
(package private) java.lang.String |
version |
Constructor and Description |
---|
HTTPRequest(org.apache.http.HttpRequest httpRequest,
java.lang.String postData)
Generates a new HTTPRequest based on the given HttpRequest and POST data.
|
HTTPRequest(java.io.InputStream is,
java.lang.String protocol,
java.lang.String host,
int port)
Generates a request based on a stream, protocol and host.
|
HTTPRequest(int requestID,
java.lang.String requestMethod,
java.lang.String url,
java.lang.String postData,
java.lang.String requestLine)
Generates a new HTTPRequest, loads it with its basic data, then loads it up with all of its HTTP headers.
|
HTTPRequest(java.lang.String requestLine,
java.util.HashSet requestHeaders,
java.lang.String postData)
Generates a new HTTPRequest based on the given parameters.
|
HTTPRequest(java.lang.String request,
java.net.URL requestURL)
Generates a new HTTPRequest, given a string.
|
Modifier and Type | Method and Description |
---|---|
void |
addHTTPHeader(HTTPHeader newHeader) |
void |
addHTTPHeader(java.lang.String key,
java.lang.String value)
Adds a HTTP header as a key/value pair.
|
void |
addPOSTParameter(java.lang.String key,
java.lang.String value)
Adds a POST parameter to the local hash.
|
void |
deleteHeaders()
Deletes the headers corresponding to this request.
|
void |
forceRequestLineToHTTPS()
Forces the request line to HTTPS.
|
java.util.ArrayList |
getCookiesAsArrayList()
Gets an
ArrayList over which the cookies can be accessed as HTTPParameter objects. |
java.util.ArrayList |
getGETParametersAsArrayList(boolean doDecode)
Gets an
ArrayList over which the GET parameters can be accessed as HTTPParameter objects. |
java.util.ArrayList |
getHeadersAsArrayList()
Gets an
ArrayList over which the headers can be accessed as HTTPParameter objects. |
java.lang.String |
getHTTPHeader(java.lang.String key)
Gets the value of a header, given its key.
|
java.util.Set<HTTPHeader> |
getHTTPHeaders()
Gets the HTTP headers.
|
java.util.Iterator |
getHTTPHeadersIterator()
Gets an
Iterator over which the headers can be iterated. |
int |
getID()
Gets the ID.
|
java.lang.String |
getPOSTData()
Gets the POST data.
|
java.lang.String |
getPOSTDataShort()
Gets the POST data truncated if it's too long.
|
java.lang.String |
getPOSTParameter(java.lang.String key)
Gets a POST parameter identified by the given key.
|
java.util.Hashtable |
getPOSTParameters()
Gets the POST data as a
Hashtable of parameters. |
java.util.ArrayList |
getPOSTParametersAsArrayList(boolean doDecode)
Gets an
ArrayList over which the POST parameters can be accessed as HTTPParameter objects. |
java.lang.String |
getQueryString()
Gets the query string portion of the URL.
|
java.lang.String |
getRawRequest()
Returns a string representing the raw HTTP request held by this object.
|
java.lang.String |
getRequestLine()
Gets the request line.
|
java.lang.String |
getRequestMethod()
Gets the request method.
|
java.net.URL |
getURL()
Gets the url.
|
java.lang.String |
getURLAsString()
Gets the url.
|
java.lang.String |
getURLWithoutQueryString()
Gets the URL without the query string.
|
boolean |
isBinaryAccordingToURL()
Indicates whether or not the file is likely binary based on the URL.
|
boolean |
isMultiPart()
Indicates whether or not this is a multipart request (most likely has a file upload).
|
boolean |
isUsefulAsScrapeableFile()
Indicates whether or not this request would likely be made into a scrapeable file.
|
void |
removeHTTPHeader(HTTPHeader oldHeader) |
void |
removeHTTPHeader(java.lang.String key,
java.lang.String value)
Removes an HTTPHeader.
|
void |
removePOSTParameter(java.lang.String key)
Removes a POST parameter from the local hash.
|
boolean |
requestEntityIsKeyValuePairs()
Indicates whether or not the POST payload is key/value pairs or a raw entity.
|
void |
save(int httpTransactionID)
Saves the information related to this request to the database.
|
void |
setHeader(java.lang.String header)
Sets a header, given a
String representing a header. |
void |
setHeader(java.lang.String key,
java.lang.String value) |
void |
setHeaders(org.apache.commons.httpclient.Header[] headers)
Sets the headers.
|
void |
setID(int requestID)
Sets the ID.
|
void |
setPOSTData(java.lang.String postData)
Sets the POST data.
|
void |
setRequestLine(java.lang.String requestLine)
Sets the request line.
|
void |
setRequestLine(java.lang.String requestMethod,
java.lang.String urlString,
java.lang.String httpVersion)
Sets the request line params.
|
void |
setRequestLine(java.lang.String requestMethod,
java.net.URL url,
java.lang.String httpVersion)
Sets the request line params.
|
void |
setURL(java.net.URL url)
Sets the url.
|
public static org.apache.log4j.Logger log
@Nullable java.lang.String requestLine
@Nullable java.util.Hashtable postParameters
@Nullable java.lang.String version
public HTTPRequest(@Nullable java.lang.String request, @Nullable java.net.URL requestURL)
request
- The request, encapsulated as a string.requestURL
- The url that was initially requested, if knownpublic HTTPRequest(@NotNull java.io.InputStream is, @Nullable java.lang.String protocol, @Nullable java.lang.String host, int port) throws java.lang.Exception
is
- The InputStream
encapsulating the request.protocol
- The protocol used in the request.host
- The host corresponding to the request.port
- The port corresponding to the request.java.lang.Exception
public HTTPRequest(java.lang.String requestLine, java.util.HashSet requestHeaders, @Nullable java.lang.String postData)
requestLine
- The first line of the request.requestHeaders
- The request headers.postData
- The POST data.public HTTPRequest(int requestID, java.lang.String requestMethod, @NotNull java.lang.String url, java.lang.String postData, java.lang.String requestLine)
requestID
- The ID.requestMethod
- The request method (e.g. GET, POST).url
- The URL requested.postData
- Any POST data sent.requestLine
- The first line of the request.public HTTPRequest(@Nullable org.apache.http.HttpRequest httpRequest, java.lang.String postData)
httpRequest
- An HttpRequest
.postData
- The POST data.public void setHeaders(@NotNull org.apache.commons.httpclient.Header[] headers)
headers
- A two-dimensional array containing the headers.public void setHeader(@NotNull java.lang.String header)
String
representing a header.header
- The header.public void setHeader(java.lang.String key, java.lang.String value)
public void addHTTPHeader(HTTPHeader newHeader)
public void removeHTTPHeader(HTTPHeader oldHeader)
public void removeHTTPHeader(java.lang.String key, java.lang.String value)
RunningHTTPRequest
removeHTTPHeader
in interface RunningHTTPRequest
public int getID()
public void setID(int requestID)
requestID
- The ID.@Nullable public java.lang.String getRequestMethod()
public void setRequestLine(java.lang.String requestMethod, @NotNull java.net.URL url, java.lang.String httpVersion)
requestMethod
- The request method POST, GET or CONNECT.url
- The url.httpVersion
- The version of http.public void setRequestLine(java.lang.String requestMethod, @NotNull java.lang.String urlString, java.lang.String httpVersion)
setRequestLine
in interface RunningHTTPRequest
requestMethod
- The request method POST, GET or CONNECT.urlString
- The url.httpVersion
- The version of http.@InternalOnly public final void setRequestLine(java.lang.String requestLine)
requestLine
- The request line to set.@Nullable public java.lang.String getRequestLine()
public void forceRequestLineToHTTPS()
@Nullable public java.net.URL getURL()
getURL
in interface RunningHTTPRequest
public java.lang.String getURLAsString()
getURLAsString
in interface RunningHTTPRequest
@Nullable public java.lang.String getURLWithoutQueryString()
public void setURL(java.net.URL url)
url
- The url.@Nullable public java.lang.String getQueryString()
@Nullable public java.lang.String getPOSTData()
@Nullable public java.lang.String getPOSTDataShort()
public void setPOSTData(java.lang.String postData)
postData
- The POST data.@Nullable public java.util.Hashtable getPOSTParameters()
Hashtable
of parameters.Hashtable
of key/value pairs.@NotNull public java.lang.String getPOSTParameter(@NotNull java.lang.String key)
key
- The key associated with the desired value.public boolean requestEntityIsKeyValuePairs()
@NotNull public java.util.ArrayList getGETParametersAsArrayList(boolean doDecode)
ArrayList
over which the GET parameters can be accessed as HTTPParameter
objects.doDecode
- Whether or not parameters should be URL-decoded before returning them.ArrayList
.@NotNull public java.util.ArrayList getPOSTParametersAsArrayList(boolean doDecode)
ArrayList
over which the POST parameters can be accessed as HTTPParameter
objects.doDecode
- Whether or not parameters should be URL-decoded before returning them.ArrayList
.public boolean isMultiPart()
public void addPOSTParameter(@NotNull java.lang.String key, @NotNull java.lang.String value)
addPOSTParameter
in interface RunningHTTPRequest
key
- The key in the parameter.value
- The value in the parameter.public void removePOSTParameter(@NotNull java.lang.String key)
removePOSTParameter
in interface RunningHTTPRequest
key
- The key in the parameter.@NotNull public java.util.ArrayList getCookiesAsArrayList()
ArrayList
over which the cookies can be accessed as HTTPParameter
objects.ArrayList
.@NotNull public java.util.ArrayList getHeadersAsArrayList()
ArrayList
over which the headers can be accessed as HTTPParameter
objects.ArrayList
.public java.util.Set<HTTPHeader> getHTTPHeaders()
@NotNull public java.util.Iterator getHTTPHeadersIterator()
Iterator
over which the headers can be iterated.Iterator
pointing to HTTPHeader
objects.public void addHTTPHeader(java.lang.String key, java.lang.String value)
addHTTPHeader
in interface RunningHTTPRequest
@Nullable public java.lang.String getHTTPHeader(java.lang.String key)
key
- The key of the header.@NotNull public java.lang.String getRawRequest()
public void save(int httpTransactionID)
httpTransactionID
- The ID of the transaction holding this request.public void deleteHeaders()
public boolean isUsefulAsScrapeableFile()
public boolean isBinaryAccordingToURL()