public class HTTPResponse extends java.lang.Object implements RunningHTTPResponse
Modifier and Type | Field and Description |
---|---|
static org.apache.log4j.Logger |
log
Used for logging.
|
Constructor and Description |
---|
HTTPResponse()
Generates an empty HTTPResponse.
|
HTTPResponse(int responseID,
java.lang.String statusLine,
java.lang.String content)
Generates a new HTTPResponse, loads it with its basic data, then loads
it up with all of its HTTP headers.
|
HTTPResponse(java.lang.String rawResponse) |
Modifier and Type | Method and Description |
---|---|
void |
addHTTPHeader(HTTPHeader newHeader) |
void |
addHTTPHeader(java.lang.String key,
java.lang.String value)
Gets the value of a header, given its key.
|
boolean |
containsCookie(java.lang.String key,
java.lang.String value)
Determines whether or not the response has a "Set-Cookie" header
containing the given key/value pair.
|
boolean |
contentIsBinary()
Indicates whether or not the Content-Type header indicates
that the content for this response is binary.
|
boolean |
contentIsProbablyHTMLOrXML()
Indicates whether or not the content is probably XML or HTML by
examining the characters found in the first portion of it.
|
void |
deleteHeaders()
Deletes the headers corresponding to this response.
|
java.lang.String |
determineCharacterSet(org.apache.http.HttpResponse httpResponse)
Determines what the character should be from the
method response.
|
java.lang.String |
getCharacterSet()
Gets the character encoding of the content given by the server.
|
byte[] |
getContentAsByteArray()
Returns the content as an array of bytes.
|
java.lang.String |
getContentAsString()
Returns the content as a string.
|
java.lang.String |
getContentTypeHeader()
Attempts to get the content type.
|
boolean |
getContentUnencoded()
If the content is gzip encoded, this will indicate when it has been unencoded.
|
boolean |
getForceNonBinary()
Indicates whether or not the contents of this response should be forced
to be treated as non-binary.
|
java.lang.String |
getHTTPHeader(java.lang.String key)
Gets the value of a header, given its key.
|
java.util.Set<HTTPHeader> |
getHTTPHeaders()
Returns all of the headers.
|
java.util.Iterator |
getHTTPHeadersIterator()
Gets an
Iterator over which the headers
can be iterated. |
java.lang.String |
getHumanReadableContent()
Returns the content in a human-readable format.
|
java.lang.String |
getHumanReadableContentShort()
Returns the content in a human-readable format, truncating it if it's too long.
|
int |
getID()
Gets the ID.
|
java.lang.String |
getLocationHeader()
Attempts to get the location header.
|
byte[] |
getOriginalBytes()
Allows the original bytes of the content to be preserved.
|
java.lang.String |
getRawResponse()
Returns a string representing the raw HTTP response
held by this object.
|
int |
getStatusCode()
Gets the status code from the status line.
|
java.lang.String |
getStatusLine()
Gets the status line for the response.
|
boolean |
isContentBinaryAccordingToMimeMagic()
Indicates whether or not the content is binary by utilizing the
mime magic library.
|
boolean |
isUsefulAsScrapeableFile()
Indicates whether or not this response would likely be made into
a scrapeable file.
|
void |
removeHTTPHeader(HTTPHeader oldHeader) |
void |
removeHTTPHeader(java.lang.String key)
Removes an HTTP header
|
void |
removeHTTPHeader(java.lang.String key,
java.lang.String value)
Removes an HTTPHeader.
|
void |
save(int httpTransactionID)
Saves the information related to this response to the database.
|
void |
setCharacterSet(java.lang.String characterSet)
Sets the character encoding of the content given by the server.
|
void |
setContent(byte[] bContent)
Sets the main body of content.
|
void |
setContentAsString(java.lang.String newContent)
Sets the main body of content.
|
void |
setContentUnencoded(boolean contentUnencoded)
If the content is gzip encoded, this will set when it has been unencoded.
|
void |
setForceNonBinary(boolean forceNonBinary)
Determines whether or not the contents of this response should be forced
to be treated as non-binary.
|
void |
setHeader(java.lang.String header)
Sets a header, given a
String representing a header. |
void |
setHeaders(java.util.Set<HTTPHeader> responseHeaders)
Sets the headers.
|
void |
setID(int responseID)
Sets the ID.
|
void |
setStatusLine(java.lang.String statusLine)
Sets the status line for the response.
|
void |
write(java.io.OutputStream os) |
void |
writeContentBytesToFile(java.lang.String filePath)
Writes out the raw bytes of the content to a file (used for testing).
|
public HTTPResponse()
public HTTPResponse(int responseID, java.lang.String statusLine, @NotNull java.lang.String content)
responseID
- The ID.statusLine
- The status line of the response.content
- The content.public HTTPResponse(@Nullable java.lang.String rawResponse)
rawResponse
- The raw response.public int getID()
public void setID(int responseID)
responseID
- The ID.public void setHeaders(java.util.Set<HTTPHeader> responseHeaders)
responseHeaders
- A Set
of HTTPHeader
s.public void write(@NotNull java.io.OutputStream os) throws java.lang.Exception
java.lang.Exception
public void addHTTPHeader(HTTPHeader newHeader)
public void addHTTPHeader(java.lang.String key, java.lang.String value)
RunningHTTPResponse
addHTTPHeader
in interface RunningHTTPResponse
key
- The name of the headervalue
- The value of the headerpublic void setHeader(@NotNull java.lang.String header)
String
representing a header.header
- The header.public boolean containsCookie(java.lang.String key, java.lang.String value)
key
- The cookie key.value
- The cookie value.public java.util.Set<HTTPHeader> getHTTPHeaders()
getHTTPHeaders
in interface RunningHTTPResponse
Hashtable
containing
the headers.@NotNull public java.util.Iterator getHTTPHeadersIterator()
Iterator
over which the headers
can be iterated.Iterator
pointing to HTTPHeader
objects.@Nullable public java.lang.String getStatusLine()
getStatusLine
in interface RunningHTTPResponse
public void setStatusLine(java.lang.String statusLine)
setStatusLine
in interface RunningHTTPResponse
statusLine
- The status line.public int getStatusCode()
@Nullable public java.lang.String getHTTPHeader(@NotNull java.lang.String key)
key
- The key of the header.public void removeHTTPHeader(HTTPHeader oldHeader)
public void removeHTTPHeader(java.lang.String key, java.lang.String value)
RunningHTTPResponse
removeHTTPHeader
in interface RunningHTTPResponse
key
- The name of the headervalue
- The value of the headerpublic void removeHTTPHeader(java.lang.String key)
key
- The key of the header to be removed.public void writeContentBytesToFile(@NotNull java.lang.String filePath)
filePath
- Path to the file bytes should be written to.public void setContent(@Nullable byte[] bContent)
setContent
in interface RunningHTTPResponse
bContent
- An array of bytes containing the
content.public void setContentAsString(@NotNull java.lang.String newContent)
setContentAsString
in interface RunningHTTPResponse
newContent
- The content to set, as a String@Nullable public byte[] getContentAsByteArray()
public boolean isUsefulAsScrapeableFile()
public boolean contentIsBinary()
public boolean isContentBinaryAccordingToMimeMagic()
public boolean contentIsProbablyHTMLOrXML()
@Nullable public java.lang.String getContentTypeHeader()
@Nullable public java.lang.String getLocationHeader()
@Nullable public java.lang.String getHumanReadableContent()
@Nullable public java.lang.String getHumanReadableContentShort()
@Nullable public java.lang.String getContentAsString()
getContentAsString
in interface RunningHTTPResponse
@Nullable public byte[] getOriginalBytes()
@NotNull public java.lang.String getRawResponse()
public void save(int httpTransactionID)
httpTransactionID
- The ID of the transaction holding this response.public void deleteHeaders()
public java.lang.String determineCharacterSet(@NotNull org.apache.http.HttpResponse httpResponse) throws java.lang.Exception
httpResponse
- The HttpResponse
.java.lang.Exception
- If the chracter set can't be determined
from the server headers.@Nullable public java.lang.String getCharacterSet()
public void setCharacterSet(java.lang.String characterSet)
characterSet
- The character encoding.public boolean getContentUnencoded()
public void setContentUnencoded(boolean contentUnencoded)
contentUnencoded
- A boolean.public boolean getForceNonBinary()
public void setForceNonBinary(boolean forceNonBinary)
forceNonBinary
- Whether or not it should be forced as binary.