Application

class Application : ApplicationCallPipeline, CoroutineScope

Represents configured and running web application, capable of handling requests. It is also the application coroutine scope that is cancelled immediately at application stop so useful for launching background coroutines.

Parameters

environment - Instance of ApplicationEnvironment describing environment this application runs in

Constructors

<init>

Application(environment: ApplicationEnvironment)

Represents configured and running web application, capable of handling requests. It is also the application coroutine scope that is cancelled immediately at application stop so useful for launching background coroutines.

Properties

coroutineContext

val coroutineContext: <ERROR CLASS>

environment

val environment: ApplicationEnvironment

Instance of ApplicationEnvironment describing environment this application runs in

Inherited Properties

receivePipeline

val receivePipeline: ApplicationReceivePipeline

Pipeline for receiving content

sendPipeline

val sendPipeline: ApplicationSendPipeline

Pipeline for sending content

Functions

dispose

fun dispose(): Unit

Called by ApplicationEngine when Application is terminated

Extension Properties

conversionService

Lookup for a conversion service. Returns the default one if the feature wasn’t installed

locations

val Application.locations: Locations

Gets the Application.locations feature

log

val Application.log: Logger

Convenience property to access log from application

Extension Functions

authentication

fun Application.authentication(
    block: Configuration.() -> Unit
): Unit

Installs Authentication feature if not yet installed and invokes block on it’s config. One is allowed to modify existing authentication configuration only in authentication’s block or via Authentication.configure function. Changing captured instance of configuration outside of block may have no effect or damage application’s state.

decodeChunked

fun CoroutineScope.decodeChunked(
    input: ByteReadChannel
): DecoderJob

Start a chunked stream decoder coroutine

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

execute

suspend fun <TContext : Any> Pipeline<Unit, TContext>.execute(
    context: TContext
): Unit

Executes this pipeline

httpServer

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

Start an http server with settings invoking handler for every request

intercept

fun <TSubject : Any, TContext : Any> Pipeline<*, TContext>.intercept(
    phase: PipelinePhase,
    block: suspend PipelineContext<TSubject, TContext>.(TSubject) -> Unit
): Unit

Intercepts an untyped pipeline when the subject is of the given type

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

routing

fun Application.routing(
    configuration: Routing.() -> Unit
): Routing

Gets or installs a Routing feature for the this Application and runs a configuration script on it

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

writeMultipleRanges

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

Start multirange response writer coroutine