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 |
addHeaderLenient(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() |
okio.Buffer |
getBody()
Returns a copy of the raw HTTP payload.
|
long |
getBodyDelay(TimeUnit unit) |
Headers |
getHeaders()
Returns the HTTP headers, such as "Content-Length: 0".
|
long |
getHeadersDelay(TimeUnit unit) |
int |
getHttp2ErrorCode() |
List<PushPromise> |
getPushPromises()
Returns the streams the server will push with this response.
|
okhttp3.internal.http2.Settings |
getSettings() |
SocketPolicy |
getSocketPolicy() |
String |
getStatus()
Returns the HTTP response line, such as "HTTP/1.1 200 OK".
|
long |
getThrottleBytesPerPeriod() |
long |
getThrottlePeriod(TimeUnit unit) |
Headers |
getTrailers() |
WebSocketListener |
getWebSocketListener() |
MockResponse |
removeHeader(String name)
Removes all headers named
name . |
MockResponse |
setBody(okio.Buffer body) |
MockResponse |
setBody(String body)
Sets the response body to the UTF-8 encoded bytes of
body . |
MockResponse |
setBodyDelay(long delay,
TimeUnit unit)
Set the delayed time of the response body to
delay . |
MockResponse |
setChunkedBody(okio.Buffer 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 |
setHeaders(Headers headers)
Replaces all headers with those specified.
|
MockResponse |
setHeadersDelay(long delay,
TimeUnit unit) |
MockResponse |
setHttp2ErrorCode(int http2ErrorCode)
Sets the HTTP/2 error code to be
returned when resetting the stream.
|
MockResponse |
setResponseCode(int code) |
MockResponse |
setSocketPolicy(SocketPolicy socketPolicy) |
MockResponse |
setStatus(String status) |
MockResponse |
setTrailers(Headers trailers)
Replaces all trailers with those specified.
|
MockResponse |
throttleBody(long bytesPerPeriod,
long period,
TimeUnit unit)
Throttles the request reader and response writer to sleep for the given period after each
series of
bytesPerPeriod bytes are transferred. |
String |
toString() |
MockResponse |
withPush(PushPromise promise)
When
protocols include Protocol.HTTP_2, this attaches a pushed stream to this response. |
MockResponse |
withSettings(okhttp3.internal.http2.Settings settings)
|
MockResponse |
withWebSocketUpgrade(WebSocketListener listener)
Attempts to perform a web socket upgrade on the connection.
|
public MockResponse()
public MockResponse clone()
public String getStatus()
public MockResponse setResponseCode(int code)
public MockResponse setStatus(String status)
public Headers getHeaders()
public Headers getTrailers()
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 addHeaderLenient(String name, Object value)
addHeader(String, Object)
this does not validate the name and
value.public MockResponse setHeader(String name, Object value)
name
, then adds a new header with the name and value.public MockResponse setHeaders(Headers headers)
public MockResponse setTrailers(Headers trailers)
public MockResponse removeHeader(String name)
name
.public okio.Buffer getBody()
public MockResponse setBody(okio.Buffer body)
public MockResponse setBody(String body)
body
.public MockResponse setChunkedBody(okio.Buffer 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 int getHttp2ErrorCode()
public MockResponse setHttp2ErrorCode(int http2ErrorCode)
SocketPolicy.RESET_STREAM_AT_START
.public MockResponse throttleBody(long bytesPerPeriod, long period, TimeUnit unit)
bytesPerPeriod
bytes are transferred. Use this to simulate network behavior.public long getThrottleBytesPerPeriod()
public long getThrottlePeriod(TimeUnit unit)
public MockResponse setBodyDelay(long delay, TimeUnit unit)
delay
. This applies to the response body
only; response headers are not affected.public long getBodyDelay(TimeUnit unit)
public MockResponse setHeadersDelay(long delay, TimeUnit unit)
public long getHeadersDelay(TimeUnit unit)
public MockResponse withPush(PushPromise promise)
protocols
include Protocol.HTTP_2, this attaches a pushed stream to this response.public List<PushPromise> getPushPromises()
public MockResponse withSettings(okhttp3.internal.http2.Settings settings)
public okhttp3.internal.http2.Settings getSettings()
public MockResponse withWebSocketUpgrade(WebSocketListener listener)
public WebSocketListener getWebSocketListener()
Copyright © 2019. All rights reserved.