class MockResponse : Cloneable
A scripted response to be replayed by the mock web server.
MockResponse()
A scripted response to be replayed by the mock web server. |
var duplexResponseBody: DuplexResponseBody? |
|
val isDuplex: Boolean |
|
val pushPromises: List<PushPromise>
Returns the streams the server will push with this response. |
|
var settings: Settings |
|
var throttleBytesPerPeriod: Long |
|
var webSocketListener: WebSocketListener? |
fun addHeader(header: String): MockResponse
Adds header as an HTTP header. For well-formed HTTP header should contain a name followed by a colon and a value. fun addHeader(name: String, value: Any): MockResponse
Adds a new header with the name and value. This may be used to add multiple headers with the same name. |
|
fun addHeaderLenient(name: String, value: Any): MockResponse
Adds a new header with the name and value. This may be used to add multiple headers with the same name. Unlike addHeader this does not validate the name and value. |
|
fun clearHeaders(): MockResponse
Removes all HTTP headers including any "Content-Length" and "Transfer-encoding" headers that were added by default. |
|
fun clone(): MockResponse |
|
fun getBody(): Buffer?
Returns a copy of the raw HTTP payload. |
|
fun getBodyDelay(unit: TimeUnit): Long |
|
fun getHeaders(): Headers
Returns the HTTP headers, such as "Content-Length: 0". |
|
fun getHeadersDelay(unit: TimeUnit): Long |
|
fun getHttp2ErrorCode(): Int |
|
fun getSocketPolicy(): SocketPolicy |
|
fun getStatus(): String
Returns the HTTP response line, such as "HTTP/1.1 200 OK". |
|
fun getThrottlePeriod(unit: TimeUnit): Long |
|
fun getTrailers(): Headers |
|
fun removeHeader(name: String): MockResponse
Removes all headers named name. |
|
fun setBody(body: Buffer): MockResponsefun setBody(duplexResponseBody: DuplexResponseBody): MockResponsefun setBody(body: String): MockResponse
Sets the response body to the UTF-8 encoded bytes of body. |
|
fun setBodyDelay(delay: Long, unit: TimeUnit): MockResponse
Set the delayed time of the response body to delay. This applies to the response body only; response headers are not affected. |
|
fun setChunkedBody(body: Buffer, maxChunkSize: Int): MockResponse
Sets the response body to body, chunked every maxChunkSize bytes. fun setChunkedBody(body: String, maxChunkSize: Int): MockResponse
Sets the response body to the UTF-8 encoded bytes of body, chunked every maxChunkSize bytes. |
|
fun setHeader(name: String, value: Any): MockResponse
Removes all headers named name, then adds a new header with the name and value. |
|
fun setHeaders(headers: Headers): MockResponse
Replaces all headers with those specified. |
|
fun setHeadersDelay(delay: Long, unit: TimeUnit): MockResponse |
|
fun setHttp2ErrorCode(http2ErrorCode: Int): MockResponse
Sets the HTTP/2 error code to be returned when resetting the stream. This is only valid with SocketPolicy.RESET_STREAM_AT_START. |
|
fun setResponseCode(code: Int): MockResponse |
|
fun setSocketPolicy(socketPolicy: SocketPolicy): MockResponse |
|
fun setStatus(status: String): MockResponse |
|
fun setTrailers(trailers: Headers): MockResponse
Replaces all trailers with those specified. |
|
fun throttleBody(bytesPerPeriod: Long, period: Long, unit: TimeUnit): MockResponse
Throttles the request reader and response writer to sleep for the given period after each series of bytesPerPeriod bytes are transferred. Use this to simulate network behavior. |
|
fun toString(): String |
|
fun withPush(promise: PushPromise): MockResponse
When protocols include HTTP_2, this attaches a pushed stream to this response. |
|
fun withSettings(settings: Settings): MockResponse
When protocols include HTTP_2, this pushes settings before writing the response. |
|
fun withWebSocketUpgrade(listener: WebSocketListener): MockResponse
Attempts to perform a web socket upgrade on the connection. This will overwrite any previously set status or body. |