public final class Response extends java.lang.Object implements RoResponse, java.lang.Cloneable
Modifier and Type | Field and Description |
---|---|
static int |
CD_0 |
static int |
CD_CHUNKED |
static int |
CD_CLOSE |
static int |
CD_CONTLEN |
static int |
CD_HDRS |
static int |
CD_MP_BR |
static int |
CD_NONE
Content delimiters
|
static int |
HTTP
possible http protocols we (might) handle
|
static int |
HTTP_1_0
some known http versions
|
static int |
HTTP_1_1 |
static int |
HTTP_NG |
static int |
HTTPS |
java.io.InputStream |
inp_stream
our input stream (usually from the stream demux).
|
static int |
SHTTP |
Constructor and Description |
---|
Response(java.lang.String version,
int status,
java.lang.String reason,
NVPair[] headers,
byte[] data,
java.io.InputStream is,
int cont_len)
Create a new response with the given info.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
clone() |
void |
deleteHeader(java.lang.String header)
Removes a header field from the list of headers.
|
void |
deleteTrailer(java.lang.String trailer)
Removes a trailer field from the list of trailers.
|
byte[] |
getData()
Reads all the response data into a byte array.
|
URI |
getEffectiveURI()
get the final URI of the document.
|
java.net.URL |
getEffectiveURL()
Deprecated.
use getEffectiveURI() instead
|
java.lang.String |
getHeader(java.lang.String hdr)
retrieves the field for a given header.
|
java.util.Date |
getHeaderAsDate(java.lang.String hdr)
retrieves the field for a given header.
|
int |
getHeaderAsInt(java.lang.String hdr)
retrieves the field for a given header.
|
java.io.InputStream |
getInputStream()
Gets an input stream from which the returned data can be read.
|
java.lang.String |
getReasonLine()
give the reason line associated with the status code.
|
int |
getStatusCode()
give the status code for this request.
|
java.lang.String |
getTrailer(java.lang.String trailer)
Retrieves the field for a given trailer.
|
java.util.Date |
getTrailerAsDate(java.lang.String trailer)
Retrieves the field for a given trailer.
|
int |
getTrailerAsInt(java.lang.String trailer)
Retrieves the field for a given tailer.
|
long |
getTtfb()
++GRINDER MODIFICATION
|
java.lang.String |
getVersion()
get the HTTP version used for the response.
|
boolean |
hasEntity()
Some responses such as those from a HEAD or with certain status
codes don't have an entity.
|
boolean |
retryRequest() |
void |
setEffectiveURI(URI final_uri)
set the final URI of the document.
|
void |
setEffectiveURL(java.net.URL final_url)
Deprecated.
use setEffectiveURI() instead
|
void |
setHeader(java.lang.String header,
java.lang.String value)
Set a header field in the list of headers.
|
void |
setRetryRequest(boolean flag)
Should the request be retried by the application? This can be used
by modules to signal to the application that it should retry the
request.
|
void |
setTrailer(java.lang.String trailer,
java.lang.String value)
Set a trailer field in the list of trailers.
|
public java.io.InputStream inp_stream
public static final int HTTP
public static final int HTTPS
public static final int SHTTP
public static final int HTTP_NG
public static final int HTTP_1_0
public static final int HTTP_1_1
public static final int CD_NONE
public static final int CD_HDRS
public static final int CD_0
public static final int CD_CLOSE
public static final int CD_CONTLEN
public static final int CD_CHUNKED
public static final int CD_MP_BR
public Response(java.lang.String version, int status, java.lang.String reason, NVPair[] headers, byte[] data, java.io.InputStream is, int cont_len)
If data is not null then that is used; else if the is is not null that is used; else the entity is empty. If the input stream is used then cont_len specifies the length of the data that can be read from it, or -1 if unknown.
version
- the response version (such as "HTTP/1.1")status
- the status codereason
- the reason lineheaders
- the response headersdata
- the response entityis
- the response entity as an InputStreamcont_len
- the length of the data in the InputStreampublic final int getStatusCode() throws java.io.IOException
getStatusCode
in interface RoResponse
java.io.IOException
- If any exception occurs on the socket.public final java.lang.String getReasonLine() throws java.io.IOException
getReasonLine
in interface RoResponse
java.io.IOException
- If any exception occurs on the socket.public final java.lang.String getVersion() throws java.io.IOException
getVersion
in interface RoResponse
java.io.IOException
- If any exception occurs on the socket.public final URI getEffectiveURI() throws java.io.IOException
java.io.IOException
- If any exception occurs on the socket.public void setEffectiveURI(URI final_uri)
public final java.net.URL getEffectiveURL() throws java.io.IOException
java.io.IOException
- If any exception occurs on the socket.getEffectiveURI()
public void setEffectiveURL(java.net.URL final_url)
setEffectiveURI(HTTPClient.URI)
public java.lang.String getHeader(java.lang.String hdr) throws java.io.IOException
getHeader
in interface RoResponse
hdr
- the header name.java.io.IOException
- If any exception occurs on the socket.public int getHeaderAsInt(java.lang.String hdr) throws java.io.IOException, java.lang.NumberFormatException
getHeaderAsInt
in interface RoResponse
hdr
- the header name.java.lang.NumberFormatException
- if the header's value is not a number
or if the header does not exist.java.io.IOException
- if any exception occurs on the socket.public java.util.Date getHeaderAsDate(java.lang.String hdr) throws java.io.IOException, java.lang.IllegalArgumentException
Note: When sending dates use Util.httpDate().
getHeaderAsDate
in interface RoResponse
hdr
- the header name.java.io.IOException
- If any exception occurs on the socket.java.lang.IllegalArgumentException
- If the header cannot be parsed
as a date or time.public void setHeader(java.lang.String header, java.lang.String value)
header
- The name of header field to set.value
- The value to set the field to.public void deleteHeader(java.lang.String header)
header
- The name of header field to remove.public java.lang.String getTrailer(java.lang.String trailer) throws java.io.IOException
getData()
.getTrailer
in interface RoResponse
trailer
- the trailer name.java.io.IOException
- If any exception occurs on the socket.public int getTrailerAsInt(java.lang.String trailer) throws java.io.IOException, java.lang.NumberFormatException
getTrailerAsInt
in interface RoResponse
trailer
- the tailer name.java.lang.NumberFormatException
- if the trailer's value is not a number
or if the trailer does not exist.java.io.IOException
- if any exception occurs on the socket.public java.util.Date getTrailerAsDate(java.lang.String trailer) throws java.io.IOException, java.lang.IllegalArgumentException
Note: When sending dates use Util.httpDate().
getTrailerAsDate
in interface RoResponse
trailer
- the trailer name.java.lang.IllegalArgumentException
- if the trailer's value is neither a
legal date nor a number.java.io.IOException
- if any exception occurs on the socket.java.lang.IllegalArgumentException
- If the header cannot be parsed
as a date or time.public void setTrailer(java.lang.String trailer, java.lang.String value)
trailer
- The name of trailer field to set.value
- The value to set the field to.public void deleteTrailer(java.lang.String trailer)
trailer
- The name of trailer field to remove.public byte[] getData() throws java.io.IOException
getData
in interface RoResponse
java.io.IOException
- If any io exception occured while reading
the datagetInputStream()
public java.io.InputStream getInputStream() throws java.io.IOException
getInputStream
in interface RoResponse
java.io.IOException
- If any exception occurs on the socket.getData()
public boolean hasEntity() throws java.io.IOException
java.io.IOException
public void setRetryRequest(boolean flag)
If a module sets this flag then it must also reset() the the HttpOutputStream so it may be reused by the application. It should then also use this HttpOutputStream to recognize the retried request in the requestHandler().
flag
- indicates whether the application should retry the request.public boolean retryRequest()
public long getTtfb()
public java.lang.Object clone()
clone
in class java.lang.Object