| Constructor and Description |
|---|
MockResponse()
Creates a new mock response with an empty body.
|
| Modifier and Type | Method and Description |
|---|---|
MockResponse |
addHeader(String header)
Adds
header as an HTTP header. |
MockResponse |
addHeader(String name,
Object value)
Adds a new header with the name and value.
|
MockResponse |
clearHeaders()
Removes all HTTP headers including any "Content-Length" and
"Transfer-encoding" headers that were added by default.
|
MockResponse |
clone() |
byte[] |
getBody()
Returns the raw HTTP payload, or null if this response is streamed.
|
int |
getBodyDelayTimeMs() |
List<String> |
getHeaders()
Returns the HTTP headers, such as "Content-Length: 0".
|
List<PushPromise> |
getPushPromises()
Returns the streams the server will push with this response.
|
SocketPolicy |
getSocketPolicy() |
String |
getStatus()
Returns the HTTP response line, such as "HTTP/1.1 200 OK".
|
int |
getThrottleBytesPerPeriod() |
long |
getThrottlePeriod() |
TimeUnit |
getThrottleUnit() |
MockResponse |
removeHeader(String name)
Removes all headers named
name. |
MockResponse |
setBody(byte[] body) |
MockResponse |
setBody(InputStream bodyStream,
long bodyLength) |
MockResponse |
setBody(String body)
Sets the response body to the UTF-8 encoded bytes of
body. |
MockResponse |
setBodyDelayTimeMs(int delay)
Set the delayed time of the response body to
delay. |
MockResponse |
setChunkedBody(byte[] body,
int maxChunkSize)
Sets the response body to
body, chunked every maxChunkSize
bytes. |
MockResponse |
setChunkedBody(String body,
int maxChunkSize)
Sets the response body to the UTF-8 encoded bytes of
body, chunked
every maxChunkSize bytes. |
MockResponse |
setHeader(String name,
Object value)
Removes all headers named
name, then adds a new header with the
name and value. |
MockResponse |
setResponseCode(int code) |
MockResponse |
setSocketPolicy(SocketPolicy socketPolicy) |
MockResponse |
setStatus(String status) |
MockResponse |
throttleBody(int bytesPerPeriod,
long period,
TimeUnit unit)
Throttles the response body writer to sleep for the given period after each
series of
bytesPerPeriod bytes are written. |
String |
toString() |
MockResponse |
withPush(PushPromise promise)
When
protocols
include a SPDY variant, this attaches a pushed stream to this response. |
public MockResponse()
public MockResponse clone()
public String getStatus()
public MockResponse setResponseCode(int code)
public MockResponse setStatus(String status)
public MockResponse clearHeaders()
public MockResponse addHeader(String header)
header as an HTTP header. For well-formed HTTP header
should contain a name followed by a colon and a value.public MockResponse addHeader(String name, Object value)
public MockResponse setHeader(String name, Object value)
name, then adds a new header with the
name and value.public MockResponse removeHeader(String name)
name.public byte[] getBody()
public MockResponse setBody(byte[] body)
public MockResponse setBody(InputStream bodyStream, long bodyLength)
public MockResponse setBody(String body)
body.public MockResponse setChunkedBody(byte[] body, int maxChunkSize)
body, chunked every maxChunkSize
bytes.public MockResponse setChunkedBody(String body, int maxChunkSize)
body, chunked
every maxChunkSize bytes.public SocketPolicy getSocketPolicy()
public MockResponse setSocketPolicy(SocketPolicy socketPolicy)
public MockResponse throttleBody(int bytesPerPeriod, long period, TimeUnit unit)
bytesPerPeriod bytes are written. Use this to simulate
network behavior.public int getThrottleBytesPerPeriod()
public long getThrottlePeriod()
public TimeUnit getThrottleUnit()
public MockResponse setBodyDelayTimeMs(int delay)
delay. This applies to the
response body only; response headers are not affected.public int getBodyDelayTimeMs()
public MockResponse withPush(PushPromise promise)
protocols
include a SPDY variant, this attaches a pushed stream to this response.public List<PushPromise> getPushPromises()
Copyright © 2014. All Rights Reserved.