Package io.ktor.response

Types

ApplicationResponse

interface ApplicationResponse

Represents server’s response

ApplicationSendPipeline

open class ApplicationSendPipeline : 
    Pipeline<Any, ApplicationCall>

Server response send pipeline

DefaultResponsePushBuilder

class DefaultResponsePushBuilder : ResponsePushBuilder

HTTP/2 push builder

ResponseCookies

class ResponseCookies

Server’s response cookies

ResponseHeaders

abstract class ResponseHeaders

Server’s response headers

ResponsePushBuilder

interface ResponsePushBuilder

HTTP/2 push builder interface

Annotations

UseHttp2Push

annotation class UseHttp2Push

HTTP/2 push is no longer supported by Chrome web browser. Other browsers may discard it at some point. With such browsers, HTTP/2 push will be disabled, therefore using this feature is safe but it will have no effect. On the other hand, this feature is not deprecated and generally it is still allowed to use it, so feel free to opt-in this annotation to eliminate this warning, if you are sure that you need it. For example, it makes sense to use with a non-browser client that for sure supports HTTP/2 push.

Properties

responseType

var ApplicationResponse.responseType: KType?

Type of the response object that was passed in respond function. Can be useful for custom serializations.

Functions

cacheControl

fun ApplicationResponse.cacheControl(
    value: CacheControl
): Unit

Append response Cache-Control HTTP header value

fun HeadersBuilder.cacheControl(value: CacheControl): Unit

Append Cache-Control HTTP header value

contentRange

fun HeadersBuilder.contentRange(
    range: LongRange?,
    fullLength: Long? = null,
    unit: String = RangeUnits.Bytes.unitToken
): Unit

Append ‘Content-Range` header with specified range and fullLength

fun ApplicationResponse.contentRange(
    range: LongRange?,
    fullLength: Long? = null,
    unit: RangeUnits
): Unit
fun ApplicationResponse.contentRange(
    range: LongRange?,
    fullLength: Long? = null,
    unit: String = RangeUnits.Bytes.unitToken
): Unit

Append response Content-Range header with specified range and fullLength

defaultTextContentType

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

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

etag

fun ApplicationResponse.etag(value: String): Unit

Append response E-Tag HTTP header value

expires

fun ApplicationResponse.expires(value: LocalDateTime): Unit

Append response Expires HTTP header value

header

fun ApplicationResponse.header(
    name: String,
    value: String
): Unit

Append HTTP response header with string value

fun ApplicationResponse.header(
    name: String,
    value: Int
): Unit

Append HTTP response header with integer numeric value

fun ApplicationResponse.header(
    name: String,
    value: Long
): Unit

Append HTTP response header with long integer numeric value

fun ApplicationResponse.header(
    name: String,
    date: Temporal
): Unit

Append HTTP response header with temporal date (date, time and so on)

lastModified

fun ApplicationResponse.lastModified(
    dateTime: ZonedDateTime
): Unit

Append response Last-Modified HTTP header value from dateTime

respond

suspend fun <T : Any> ApplicationCall.respond(
    message: T
): Unit
suspend fun ApplicationCall.respond(message: Any): Unit

Sends a message as a response

suspend fun <T : Any> ApplicationCall.respond(
    status: HttpStatusCode,
    message: T
): Unit
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

respondBytesWriter

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

Respond with binary content producer.

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

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.