Package io.ktor.server.response

Types

Link copied to clipboard
interface ApplicationResponse

A server's response. To learn how to send responses inside route handlers, see Sending responses.

Link copied to clipboard
open class ApplicationSendPipeline(developmentMode: Boolean)

Server response send pipeline.

Link copied to clipboard
class DefaultResponsePushBuilder(method: <ERROR CLASS>, url: <ERROR CLASS>, headers: <ERROR CLASS>, versions: List<<ERROR CLASS>>) : ResponsePushBuilder

An 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

An HTTP/2 push builder interface.

Link copied to clipboard
annotation class UseHttp2Push

HTTP/2 push is no longer supported by the Chrome web browser. Other browsers may discard it at some point. With such browsers, HTTP/2 push will be disabled, therefore using this plugin is safe, but it will have no effect. On the other hand, this plugin 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 <ERROR CLASS>.cacheControl(value: <ERROR CLASS>)
fun ApplicationResponse.cacheControl(value: <ERROR CLASS>)

Appends the Cache-Control header with the specified value to a response.

Link copied to clipboard
fun <ERROR CLASS>.contentRange(range: LongRange?, fullLength: Long? = null, unit: String = RangeUnits.Bytes.unitToken)
fun ApplicationResponse.contentRange(range: LongRange?, fullLength: Long? = null, unit: <ERROR CLASS>)
fun ApplicationResponse.contentRange(range: LongRange?, fullLength: Long? = null, unit: String = RangeUnits.Bytes.unitToken)

Appends the Content-Range header with the specified range and fullLength to a response.

Link copied to clipboard
fun ApplicationCall.defaultTextContentType(contentType: <ERROR CLASS>?): <ERROR CLASS>

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

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

Appends the E-Tag header with the specified value to a response.

Link copied to clipboard
fun HeadersBuilder.expires(expires: LocalDateTime)

Set 'Expires` header value from expires

fun ApplicationResponse.expires(value: LocalDateTime)

Append response Expires HTTP header value

Link copied to clipboard
fun ApplicationResponse.header(name: String, value: Int)
fun ApplicationResponse.header(name: String, value: Long)
fun ApplicationResponse.header(name: String, value: String)

Appends a header with the specified name and value to a response.

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

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

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

Set 'Last-Modified` header value from dateTime

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)

Sends a message as a response.

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

Sends a message as a response with the specified status code.

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

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

suspend fun ApplicationCall.respondBytes(bytes: ByteArray, contentType: <ERROR CLASS>? = null, status: <ERROR CLASS>? = null, configure: <ERROR CLASS>.() -> Unit = {})

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

Link copied to clipboard
suspend fun ApplicationCall.respondBytesWriter(contentType: <ERROR CLASS>? = null, status: <ERROR CLASS>? = null, contentLength: Long? = null, producer: suspend <ERROR CLASS>.() -> Unit)

Respond with a 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)
suspend fun ApplicationCall.respondOutputStream(contentType: ContentType? = null, status: HttpStatusCode? = null, contentLength: Long? = null, producer: suspend OutputStream.() -> Unit)

Respond with binary content producer.

Link copied to clipboard
inline suspend fun ApplicationCall.respondRedirect(permanent: Boolean = false, block: <ERROR CLASS>.() -> Unit)

Responds to a client with a 301 Moved Permanently or 302 Found redirect. Unlike the other respondRedirect, it provides a way to build a URL based on current call using the 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: <ERROR CLASS>? = null, status: <ERROR CLASS>? = null, provider: suspend () -> String)

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

suspend fun ApplicationCall.respondText(text: String, contentType: <ERROR CLASS>? = null, status: <ERROR CLASS>? = null, configure: <ERROR CLASS>.() -> Unit = {})

Responds to a client with a plain text response.

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

Respond with text content writer.

Properties

Link copied to clipboard
var ApplicationResponse.responseType: <ERROR CLASS>?

A type of response object that is passed in the respond function. Can be useful for custom serializations.