Package io.ktor.response

Types

Link copied to clipboard
interface ApplicationResponse

Represents server's response

Link copied to clipboard
open class ApplicationSendPipeline(developmentMode: Boolean) : Pipeline<Any, ApplicationCall>

Server response send pipeline

Link copied to clipboard
class DefaultResponsePushBuilder(method: HttpMethod, url: URLBuilder, headers: HeadersBuilder, versions: List<Version>) : ResponsePushBuilder

HTTP/2 push builder

Link copied to clipboard
class ResponseCookies(response: ApplicationResponse, secureTransport: Boolean)

Server's response cookies

Link copied to clipboard
abstract class ResponseHeaders

Server's response headers

Link copied to clipboard
interface ResponsePushBuilder

HTTP/2 push builder interface

Link copied to clipboard
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.

Functions

Link copied to clipboard
fun HeadersBuilder.cacheControl(value: CacheControl)

Append Cache-Control HTTP header value

fun ApplicationResponse.cacheControl(value: CacheControl)

Append response Cache-Control HTTP header value

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

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

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

Append response Content-Range header with specified range and fullLength

Link copied to clipboard
fun ApplicationCall.defaultTextContentType(contentType: ContentType?): ContentType

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

Link copied to clipboard
fun ApplicationResponse.etag(value: String)

Append response E-Tag HTTP header value

Link copied to clipboard
fun ApplicationResponse.expires(value: LocalDateTime)

Append response Expires HTTP header value

Link copied to clipboard
fun ApplicationResponse.header(name: String, date: Temporal)

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

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

Append HTTP response header with integer numeric value

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

Append HTTP response header with long integer numeric value

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

Append HTTP response header with string value

Link copied to clipboard
fun ApplicationResponse.lastModified(dateTime: ZonedDateTime)

Append response Last-Modified HTTP header value from dateTime

Link copied to clipboard
@JvmName(name = "respondWithType")
inline suspend fun <T : Any> ApplicationCall.respond(message: T)
inline suspend fun ApplicationCall.respond(message: Any)

Sends a message as a response

@JvmName(name = "respondWithType")
inline suspend fun <T : Any> ApplicationCall.respond(status: HttpStatusCode, message: T)
inline suspend fun ApplicationCall.respond(status: HttpStatusCode, message: Any)

Sets status and sends a message as a response

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

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 = {})

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

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

Respond with binary content producer.

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

Responds to a client with a contents of a file

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

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

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

Respond with binary content producer.

Link copied to clipboard
inline suspend fun ApplicationCall.respondRedirect(permanent: Boolean = false, block: URLBuilder.() -> 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

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

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

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

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

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

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

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

Respond with text content writer.

Properties

Link copied to clipboard
var ApplicationResponse.responseType: KType?

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