Package io.ktor.http.content

Types

ByteArrayContent

class ByteArrayContent : ByteArrayContent

Implementation of the OutgoingContent.ByteArrayContent for sending array of bytes

CachingOptions

data class CachingOptions

Specifies caching properties for an OutgoingContent such as Cache-Control or Expires

EntityTagVersion

data class EntityTagVersion : Version

This version checks etag value and pass it through conditions supplied by the remote client. Depending on conditions it produces return value of enum type VersionCheckResult

HttpStatusCodeContent

class HttpStatusCodeContent : NoContent

Represents a simple status code response with no content

JarFileContent

class JarFileContent : ReadChannelContent

Represents an OutgoingContent for a resource inside a Jar file

LastModifiedVersion

data class LastModifiedVersion : Version

This version passes the given lastModified date through the client provided http conditional headers If-Modified-Since and If-Unmodified-Since.

LocalFileContent

class LocalFileContent : ReadChannelContent

OutgoingContent representing a local file with a specified contentType, expires date and caching

MultiPartData

interface MultiPartData

Represents a multipart data stream that could be received from a call

OutgoingContent

sealed class OutgoingContent

Information about the content to be sent to the peer, recognized by a client or server engine

OutputStreamContent

class OutputStreamContent : WriteChannelContent

OutgoingContent to respond with OutputStream. The stream would be automatically closed after body finish.

PartData

sealed class PartData

Represents a multipart/form-data entry. Could be a FormItem or FileItem

TextContent

class TextContent : ByteArrayContent

Represents a text content that could be sent

URIFileContent

class URIFileContent : ReadChannelContent

Represents a content that is served from the specified uri

Version

interface Version

Represents content version

VersionCheckResult

enum class VersionCheckResult

Represent result of the version comparison between content being sent and HTTP request.

WriterContent

class WriterContent : WriteChannelContent

Represents a content that is produced by body function

Properties

CachingProperty

val CachingProperty: AttributeKey<CachingOptions>

Specifies a key for CacheControl extension property for OutgoingContent

VersionListProperty

val VersionListProperty: AttributeKey<List<Version>>

Specifies a key for VersionList extension property for OutgoingContent

caching

Gets or sets CacheControl instance as an extension property on this content

staticBasePackage

var Route.staticBasePackage: String?

Base package for relative resources calculations for static content

staticRootFolder

var Route.staticRootFolder: File?

Base folder for relative files calculations for static content

streamProvider

val FileItem.streamProvider: () -> InputStream

Provides file item’s content as an InputStream

versions

Gets or sets list of Version instances as an extension property on this content

Functions

CachingOptions

fun CachingOptions(
    cacheControl: CacheControl? = null,
    expires: ZonedDateTime
): CachingOptions

Creates CachingOptions instance with ZonedDateTime expiration time

LastModifiedVersion

fun LastModifiedVersion(
    lastModified: ZonedDateTime
): LastModifiedVersion

Construct LastModifiedVersion version from a ZonedDateTime instance

fun LastModifiedVersion(
    lastModified: FileTime
): LastModifiedVersion

Construct LastModifiedVersion version from a FileTime instance

LocalFileContent

fun LocalFileContent(
    baseDir: File,
    relativePath: String,
    contentType: ContentType = ContentType.defaultForFilePath(relativePath)
): LocalFileContent
fun LocalFileContent(
    baseDir: Path,
    relativePath: Path,
    contentType: ContentType = ContentType.defaultForFile(relativePath)
): LocalFileContent

Creates an instance of LocalFileContent for a file designated by relativePath in a baseDir

default

fun Route.default(localPath: String): Unit
fun Route.default(localPath: File): Unit

Specifies localPath as a default file to serve when folder is requested

defaultResource

fun Route.defaultResource(
    resource: String,
    resourcePackage: String? = null
): Unit

Specifies resource as a default resources to serve when folder is requested

file

fun Route.file(
    remotePath: String,
    localPath: String = remotePath
): Unit
fun Route.file(remotePath: String, localPath: File): Unit

Sets up routing to serve localPath file as remotePath

files

fun Route.files(folder: String): Unit
fun Route.files(folder: File): Unit

Sets up routing to serve all files from folder

forEachPart

suspend fun MultiPartData.forEachPart(
    partHandler: suspend (PartData) -> Unit
): Unit

Parse multipart data stream and invoke partHandler for each PartData encountered

readAllParts

suspend fun MultiPartData.readAllParts(): List<PartData>

Parse multipart data stream and put all parts into a list

resolveResource

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

resource

fun Route.resource(
    remotePath: String,
    resource: String = remotePath,
    resourcePackage: String? = null
): Unit

Sets up routing to serve resource as remotePath in resourcePackage

resourceClasspathResource

fun resourceClasspathResource(
    url: URL,
    path: String,
    mimeResolve: (String) -> ContentType
): OutgoingContent?

Attempt to find a local file or a file inside of zip. This is not required but very good to have to improve performance and unnecessary java.io.InputStream creation.

resources

fun Route.resources(resourcePackage: String? = null): Unit

Sets up routing to serve all resources in resourcePackage

static

fun Route.static(configure: Route.() -> Unit): Route

Create a block for static content

fun Route.static(
    remotePath: String,
    configure: Route.() -> Unit
): Route

Create a block for static content at specified remotePath

transformDefaultContent

fun PipelineContext<Any, ApplicationCall>.transformDefaultContent(
    value: Any
): OutgoingContent?

Default outgoing content transformation