mockwebserver / okhttp3.mockwebserver / MockResponse

MockResponse

class MockResponse :Cloneable

A scripted response to be replayed by the mock web server.

Constructors

Name Summary
<init> A scripted response to be replayed by the mock web server.MockResponse()

Properties

Name Summary
duplexResponseBody var duplexResponseBody:DuplexResponseBody?
headers The HTTP headers, such as “Content-Length: 0”.var headers: Headers
http2ErrorCode Sets the HTTP/2 error code to be returned when resetting the stream. This is only valid with SocketPolicy.RESET_STREAM_AT_START.var http2ErrorCode:Int
isDuplex val isDuplex:Boolean
pushPromises Returns the streams the server will push with this response.val pushPromises:List<PushPromise>
settings var settings: Settings
socketPolicy var socketPolicy:SocketPolicy
status Returns the HTTP response line, such as “HTTP/1.1 200 OK”.var status:String
throttleBytesPerPeriod var throttleBytesPerPeriod:Long
trailers var trailers: Headers
webSocketListener var webSocketListener: WebSocketListener?

Functions

Name Summary
addHeader Adds header as an HTTP header. For well-formed HTTP header should contain a name followed by a colon and a value.fun addHeader(header:String):MockResponse
Adds a new header with the name and value. This may be used to add multiple headers with the same name.fun addHeader(name:String, value:Any):MockResponse
addHeaderLenient 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 addHeaderLenient(name:String, value:Any):MockResponse
clearHeaders Removes all HTTP headers including any “Content-Length” and “Transfer-encoding” headers that were added by default.fun clearHeaders():MockResponse
clone fun clone():MockResponse
getBody Returns a copy of the raw HTTP payload.fun getBody():Buffer?
getBodyDelay fun getBodyDelay(unit:TimeUnit):Long
getHeadersDelay fun getHeadersDelay(unit:TimeUnit):Long
getThrottlePeriod fun getThrottlePeriod(unit:TimeUnit):Long
removeHeader Removes all headers named name.fun removeHeader(name:String):MockResponse
setBody fun setBody(body:Buffer):MockResponse
fun setBody(duplexResponseBody:DuplexResponseBody):MockResponse
Sets the response body to the UTF-8 encoded bytes of body.fun setBody(body:String):MockResponse
setBodyDelay Set the delayed time of the response body to delay. This applies to the response body only; response headers are not affected.fun setBodyDelay(delay:Long, unit:TimeUnit):MockResponse
setChunkedBody Sets the response body to body, chunked every maxChunkSize bytes.fun setChunkedBody(body:Buffer, maxChunkSize:Int):MockResponse
Sets the response body to the UTF-8 encoded bytes of body, chunked every maxChunkSize bytes.fun setChunkedBody(body:String, maxChunkSize:Int):MockResponse
setHeader Removes all headers named name, then adds a new header with the name and value.fun setHeader(name:String, value:Any):MockResponse
setHeaders Sets the headers and returns this.fun setHeaders(headers: Headers):MockResponse
setHeadersDelay fun setHeadersDelay(delay:Long, unit:TimeUnit):MockResponse
setHttp2ErrorCode Sets the HTTP/2 error code and returns this.fun setHttp2ErrorCode(http2ErrorCode:Int):MockResponse
setResponseCode fun setResponseCode(code:Int):MockResponse
setSocketPolicy Sets the socket policy and returns this.fun setSocketPolicy(socketPolicy:SocketPolicy):MockResponse
setStatus Sets the status and returns this.fun setStatus(status:String):MockResponse
setTrailers Sets the trailers and returns this.fun setTrailers(trailers: Headers):MockResponse
throttleBody 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 throttleBody(bytesPerPeriod:Long, period:Long, unit:TimeUnit):MockResponse
toString fun toString():String
withPush When protocols include HTTP_2, this attaches a pushed stream to this response.fun withPush(promise:PushPromise):MockResponse
withSettings When protocols include HTTP_2, this pushes settings before writing the response.fun withSettings(settings: Settings):MockResponse
withWebSocketUpgrade Attempts to perform a web socket upgrade on the connection. This will overwrite any previously set status or body.fun withWebSocketUpgrade(listener: WebSocketListener):MockResponse