mockwebserver / okhttp3.mockwebserver / MockResponse


class MockResponse :Cloneable

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


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


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?


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