Package io.ktor.client.engine.mock

Types

MockEngine

class MockEngine : HttpClientEngine

HttpClientEngine for writing tests without network.

MockEngineConfig

class MockEngineConfig : HttpClientEngineConfig

HttpClientEngineConfig for MockEngine.

Type Aliases

MockRequestHandler

typealias MockRequestHandler = suspend (request: HttpRequestData) -> HttpResponseData

Single HttpClientCall to HttpResponse mapper.

Functions

respond

fun respond(
    content: String,
    status: HttpStatusCode = HttpStatusCode.OK,
    headers: Headers = headersOf()
): HttpResponseData

Send response with specified string content, status and headers.

fun respond(
    content: ByteArray,
    status: HttpStatusCode = HttpStatusCode.OK,
    headers: Headers = headersOf()
): HttpResponseData

Send response with specified bytes content, status and headers.

fun respond(
    content: ByteReadChannel,
    status: HttpStatusCode = HttpStatusCode.OK,
    headers: Headers = headersOf()
): HttpResponseData

Send response with specified ByteReadChannel, status and headers.

respondBadRequest

fun respondBadRequest(): HttpResponseData

Send HttpStatusCode.BadRequest response.

respondError

fun respondError(
    status: HttpStatusCode,
    content: String = status.description,
    headers: Headers = headersOf()
): HttpResponseData

Send error response.

respondOk

fun respondOk(content: String = ""): HttpResponseData

Send ok response.

toByteArray

suspend fun OutgoingContent.toByteArray(): ByteArray

toByteReadPacket

suspend fun OutgoingContent.toByteReadPacket(): ByteReadPacket