TestApplicationCall

class TestApplicationCall : 
    BaseApplicationCall,
    CoroutineScope

Represents a test application call that is used in withTestApplication and handleRequest

Constructors

<init>

TestApplicationCall(
    application: Application,
    readResponse: Boolean = false,
    coroutineContext: <ERROR CLASS>)

Represents a test application call that is used in withTestApplication and handleRequest

Properties

coroutineContext

val coroutineContext: <ERROR CLASS>

request

Client request

requestHandled

var requestHandled: Boolean

Set to true when the request has been handled and a response has been produced

response

Server response

Inherited Properties

application

val application: Application

Application being called

attributes

val attributes: Attributes

Attributes attached to this instance

parameters

open val parameters: Parameters

Parameters associated with this call

Functions

toString

fun toString(): String

Inherited Functions

putResponseAttribute

fun putResponseAttribute(
    response: BaseApplicationResponse = this.response
): Unit

Put engine response attribute. This is required for base implementation to work properly

Extension Properties

authentication

Retrieves an AuthenticationContext for this call

callId

val ApplicationCall.callId: String?

A call id that is retrieved or generated by CallId feature or null (this is possible if there is no call id provided and no generators configured or CallId feature is not installed)

locations

val ApplicationCall.locations: Locations

Gets the Application.locations feature

sessions

Get current session or fail if no session feature installed

Extension Functions

decodeChunked

fun CoroutineScope.decodeChunked(
    input: ByteReadChannel
): DecoderJob

Start a chunked stream decoder coroutine

defaultTextContentType

fun ApplicationCall.defaultTextContentType(
    contentType: ContentType?
): ContentType

Creates a default ContentType based on the given contentType and current call

digestAuthenticationCredentials

fun ApplicationCall.digestAuthenticationCredentials(): DigestCredential?

Retrieves DigestCredential from this call

embeddedServer

fun <TEngine : ApplicationEngine, TConfiguration : Configuration> CoroutineScope.embeddedServer(
    factory: ApplicationEngineFactory<TEngine, TConfiguration>,
    port: Int = 80,
    host: String = "0.0.0.0",
    watchPaths: List<String> = emptyList(),
    parentCoroutineContext: <ERROR CLASS> = EmptyCoroutineContext,
    configure: TConfiguration.() -> Unit = {},
    module: Application.() -> Unit
): TEngine

Creates an embedded server with the given factory, listening on host:port

httpServer

fun CoroutineScope.httpServer(
    settings: HttpServerSettings,
    handler: HttpRequestHandler
): HttpServer

Start an http server with settings invoking handler for every request

parseMultipart

fun CoroutineScope.parseMultipart(
    input: ByteReadChannel,
    headers: HttpHeadersMap
): ReceiveChannel<MultipartEvent>
fun CoroutineScope.parseMultipart(
    input: ByteReadChannel,
    contentType: CharSequence,
    contentLength: Long?
): ReceiveChannel<MultipartEvent>
fun CoroutineScope.parseMultipart(
    boundaryPrefixed: ByteBuffer,
    input: ByteReadChannel,
    totalLength: Long?
): ReceiveChannel<MultipartEvent>

Starts a multipart parser coroutine producing multipart events

pinger

fun CoroutineScope.pinger(
    outgoing: SendChannel<Frame>,
    period: Duration,
    timeout: Duration,
    pool: ObjectPool<ByteBuffer> = KtorDefaultPool
): SendChannel<Pong>

Launch pinger coroutine on CoroutineScope that is sending ping every specified period to outgoing channel, waiting for and verifying client’s pong frames. It is also handling timeout and sending timeout close frame

fun CoroutineScope.pinger(
    outgoing: SendChannel<Frame>,
    periodMillis: Long,
    timeoutMillis: Long,
    pool: ObjectPool<ByteBuffer> = KtorDefaultPool
): SendChannel<Pong>

Launch pinger coroutine on CoroutineScope that is sending ping every specified periodMillis to outgoing channel, waiting for and verifying client’s pong frames. It is also handling timeoutMillis and sending timeout close frame

ponger

fun CoroutineScope.ponger(
    outgoing: SendChannel<Pong>,
    pool: ObjectPool<ByteBuffer> = KtorDefaultPool
): SendChannel<Ping>

Launch a ponger actor job on the CoroutineScope sending pongs to outgoing channel. It is acting for every client’s ping frame and replying with corresponding pong

principal

fun <P : Principal> ApplicationCall.principal(): P?

Retrieves authenticated Principal for this call

push

fun ApplicationCall.push(pathAndQuery: String): Unit
fun ApplicationCall.push(
    encodedPath: String,
    parameters: Parameters
): Unit

Produces HTTP/2 push from server to client or sets HTTP/1.x hint header or does nothing. Exact behaviour is up to engine implementation.

fun ApplicationCall.push(
    block: ResponsePushBuilder.() -> Unit
): Unit

Produces HTTP/2 push from server to client or sets HTTP/1.x hint header or does nothing (may call or not call block). Exact behaviour is up to engine implementation.

receive

suspend fun <T : Any> ApplicationCall.receive(): T
suspend fun <T : Any> ApplicationCall.receive(
    type: KClass<T>
): T

Receives content for this request.

receiveChannel

suspend fun ApplicationCall.receiveChannel(): ByteReadChannel

Receives channel content for this call.

receiveMultipart

suspend fun ApplicationCall.receiveMultipart(): MultiPartData

Receives multipart data for this call.

receiveOrNull

suspend fun <T : Any> ApplicationCall.receiveOrNull(): T?
suspend fun <T : Any> ApplicationCall.receiveOrNull(
    type: KClass<T>
): T?

Receives content for this request.

receiveParameters

suspend fun ApplicationCall.receiveParameters(): Parameters

Receives form parameters for this call.

receiveStream

suspend fun ApplicationCall.receiveStream(): InputStream

Receives stream content for this call.

receiveText

suspend fun ApplicationCall.receiveText(): String

Receives incoming content for this call as String.

resolveResource

fun ApplicationCall.resolveResource(
    path: String,
    resourcePackage: String? = null,
    classLoader: ClassLoader = application.environment.classLoader,
    mimeResolve: (String) -> ContentType = { ContentType.defaultForFileExtension(it) }
): OutgoingContent?

respond

suspend fun ApplicationCall.respond(message: Any): Unit

Sends a message as a response

suspend fun ApplicationCall.respond(
    status: HttpStatusCode,
    message: Any
): Unit

Sets status and sends a message as a response

respondBytes

suspend fun ApplicationCall.respondBytes(
    contentType: ContentType? = null,
    status: HttpStatusCode? = null,
    provider: suspend () -> ByteArray
): Unit

Responds to a client with a raw bytes response, using specified provider to build a byte array

suspend fun ApplicationCall.respondBytes(
    bytes: ByteArray,
    contentType: ContentType? = null,
    status: HttpStatusCode? = null,
    configure: OutgoingContent.() -> Unit = {}
): Unit

Responds to a client with a raw bytes response, using specified bytes

respondFile

suspend fun ApplicationCall.respondFile(
    baseDir: File,
    fileName: String,
    configure: OutgoingContent.() -> Unit = {}
): Unit

Responds to a client with a contents of a file with the name fileName in the baseDir folder

suspend fun ApplicationCall.respondFile(
    file: File,
    configure: OutgoingContent.() -> Unit = {}
): Unit

Responds to a client with a contents of a file

respondHtml

suspend fun ApplicationCall.respondHtml(
    status: HttpStatusCode = HttpStatusCode.OK,
    block: HTML.() -> Unit
): Unit

Responds to a client with a HTML response, using specified block to build an HTML page

respondHtmlTemplate

suspend fun <TTemplate : Template<HTML>> ApplicationCall.respondHtmlTemplate(
    template: TTemplate,
    status: HttpStatusCode = HttpStatusCode.OK,
    body: TTemplate.() -> Unit
): Unit

respondOutputStream

suspend fun ApplicationCall.respondOutputStream(
    contentType: ContentType? = null,
    status: HttpStatusCode? = null,
    producer: suspend OutputStream.() -> Unit
): Unit

Respond with binary content producer.

respondRedirect

suspend fun ApplicationCall.respondRedirect(
    url: String,
    permanent: Boolean = false
): Unit

Responds to a client with a 301 Moved Permanently or 302 Found redirect

suspend fun ApplicationCall.respondRedirect(
    permanent: Boolean = false,
    block: URLBuilder.() -> Unit
): Unit

Responds to a client with a 301 Moved Permanently or 302 Found redirect. Unlike the other respondRedirect it provides a way to build URL based on current call using block function

respondText

suspend fun ApplicationCall.respondText(
    text: String,
    contentType: ContentType? = null,
    status: HttpStatusCode? = null,
    configure: OutgoingContent.() -> Unit = {}
): Unit

Responds to a client with a plain text response, using specified text

suspend fun ApplicationCall.respondText(
    contentType: ContentType? = null,
    status: HttpStatusCode? = null,
    provider: suspend () -> String
): Unit

Responds to a client with a plain text response, using specified provider to build a text

respondTextWriter

suspend fun ApplicationCall.respondTextWriter(
    contentType: ContentType? = null,
    status: HttpStatusCode? = null,
    writer: suspend Writer.() -> Unit
): Unit

Respond with text content writer.

respondWrite

suspend fun ApplicationCall.respondWrite(
    contentType: ContentType? = null,
    status: HttpStatusCode? = null,
    writer: suspend Writer.() -> Unit
): Unit

startConnectionPipeline

fun CoroutineScope.startConnectionPipeline(
    input: ByteReadChannel,
    output: ByteWriteChannel,
    timeout: WeakTimeoutQueue,
    handler: HttpRequestHandler
): Job

Start connection HTTP pipeline invoking handler for every request. Note that handler could be invoked multiple times concurrently due to HTTP pipeline nature

suitableCharset

fun ApplicationCall.suitableCharset(
    defaultCharset: Charset = Charsets.UTF_8
): Charset

Detect suitable charset for an application call by Accept header or fallback to defaultCharset

url

fun ApplicationCall.url(
    location: Any,
    block: URLBuilder.() -> Unit = {}
): String

Constructs a String with the url of a instance location whose class must be annotated with Location.

url

fun ApplicationCall.url(
    block: URLBuilder.() -> Unit = {}
): String

Creates an url using current call’s schema, path and parameters as initial and then invokes block function on the url builder so amend parameters

withETag

suspend fun ApplicationCall.withETag(
    etag: String,
    putHeader: Boolean = true,
    block: suspend () -> Unit
): Unit

Checks current etag value and pass it through conditions supplied by the remote client. Depends on conditions it produces 410 Precondition Failed or 304 Not modified responses when necessary. Otherwise sets ETag header and delegates to the block function

writeMultipleRanges

fun CoroutineScope.writeMultipleRanges(
    channelProducer: (LongRange) -> ByteReadChannel,
    ranges: List<LongRange>,
    fullLength: Long?,
    boundary: String,
    contentType: String
): ByteReadChannel

Start multirange response writer coroutine