Package io.ktor.features
Types
Functional type for accepted content types contributor
A feature that automatically respond to HEAD requests
Base exception to indicate that the request is not correct due to wrong/missing request parameters, body content or header values. Throwing this exception in a handler will lead to 400 Bad Request response unless a custom io.ktor.features.StatusPages handler registered.
Represents a cached transformation result from a previous ApplicationCall.receive invocation.
Feature that set CachingOptions headers for every response. It invokes optionsProviders for every response and use first non null caching options
Retrieves and generates if necessary a call id. A call id (or correlation id) could be retrieved_ from a call via CallId.Configuration.retrieve function. Multiple retrieve functions could be configured that will be invoked one by one until one of them return non-null value. If no value has been provided by retrievers then a generator could be applied to generate a new call id. Generators could be provided via CallId.Configuration.generate function. Similar to retrieve, multiple generators could be configured so they will be invoked one by one. Usually call id is passed via io.ktor.http.HttpHeaders.XRequestId so one could use CallId.Configuration.retrieveFromHeader function to retrieve call id from a header.
A function that retrieves or generates call id using provided call
A function that verifies retrieved or generated call id. Should return true
for a valid call id. Also it could throw a RejectedCallIdException to reject an ApplicationCall otherwise an illegal call id will be ignored or replaced with generated one.
Logs application lifecycle and call events.
Feature to compress a response based on conditions and ability of client to decompress it
Represents a Compression encoder
Builder for compression encoder configuration
Configuration for an encoder
Compression feature configuration
Feature to check modified/match conditional headers and avoid sending contents if it was not changed
Represents a builder for conditions
A custom content converted that could be registered in ContentNegotiation feature for any particular content type Could provide bi-directional conversion implementation. One of the most typical examples of content converter is a json content converter that provides both serialization and deserialization
This feature provides automatic content conversion according to Content-Type and Accept headers
Thrown when content cannot be transformed to the desired type. It is not defined which status code will be replied when an exception of this type is thrown and not caught. Depending on child type it could be 4xx or 5xx status code. By default it will be 500 Internal Server Error.
Pair of ContentType and quality usually parsed from HttpHeaders.Accept headers.
CORS feature. Please read http://ktor.io/servers/features/cors.html first before using it.
Data conversion feature to serialize and deserialize types using converters registry
Adds standard HTTP headers Date
and Server
and provides ability to specify other headers that are included in responses.
Implementation of the deflate encoder
Custom convertor builder
This feature provides ability to invoke ApplicationCall.receive several times. Please note that not every type could be received twice. For example, even with this feature installed you can't receive a channel twice (unless Configuration.receiveEntireContent is enabled). Types that always can be received twice or more: ByteArray
, String
and Parameters
. Also some of content transformation features (such as ContentNegotiation) could support it as well. If not specified, a transformation result is not considered as reusable. So a transformation feature may mark a result as reusable by proceeding with a ApplicationReceiveRequest instance having ApplicationReceiveRequest.reusableValue= true
. So installing DoubleReceive with ContentNegotiation provides ability to receive a user type that will be deserialized at first receive and then the same instance will be returned for every further receive invocation. When the same receive type requested as the firstly received, the receive pipeline and content transformation are not triggered (except when Configuration.receiveEntireContent = true
).
Forwarded header support. See RFC 7239 https://tools.ietf.org/html/rfc7239
Implementation of the gzip encoder
HSTS feature that appends Strict-Transport-Security
HTTP header to every response. See http://ktor.io/servers/features/hsts.html for details See RFC 6797 https://tools.ietf.org/html/rfc6797
Redirect non-secure requests to HTTPS
Implementation of the identity encoder
This exception is thrown when a required parameter with name parameterName is missing
Represents a RequestConnectionPoint. Every it's component is mutable so application features could provide them
This exception means that the requested resource is not found. HTTP status 404 Not found will be replied when this exception is thrown and not caught. 404 status page could be configured by registering a custom io.ktor.features.StatusPages handler.
This exception is thrown when a required parameter with name parameterName couldn't be converted to the type
Feature to support requests to specific content ranges.
An exception that could be thrown to reject a call due to illegal call id
Thrown when a request receive was failed during the previous ApplicationCall.receive invocation so this receive attempt is simply replaying the previous exception cause.
Status pages feature that handles exceptions and status codes. Useful to configure default error pages.
Thrown when there is no conversion for a content type configured. HTTP status 415 Unsupported Media Type will be replied when this exception is thrown and not caught.
X-Forwarded-*
headers support See http://ktor.io/servers/features/forward-headers.html for details
Functions
Put call id into MDC (diagnostic context value) with name
Appends a custom condition to the encoder or Compression configuration. A predicate returns true
when a response need to be compressed. If at least one condition is not met then the response compression is skipped.
Appends deflate
encoder with default priority of 0.9
Appends a content type exclusion condition to the encoder or Compression configuration.
Generates fixed length call ids using the specified dictionary. Please note that this function generates pseudo-random identifiers via regular java.util.Random and should not be considered as cryptographically secure. Also note that you should use the same dictionary for CallIdVerifier otherwise a generated call id could be discarded or may lead to complete call rejection.
Appends gzip
encoder
Appends identity
encoder
Appends a content type condition to the encoder or Compression configuration.
Appends a minimum size condition to the encoder or Compression configuration.
Retrieves LastModified and ETag versions from headers.
Returns a list of content types sorted by quality, number of asterisks and number of parameters.
Register a status page file(s) using filePattern for multiple status code list
Detect suitable charset for an application call by Accept
header or fallback to defaultCharset
Generates a string representing this ApplicationRequest suitable for logging
Start multirange response writer coroutine
Properties
Retrieves LastModified and ETag versions from this OutgoingContent headers
A key to install a mutable RequestConnectionPoint
Represents request and connection parameters possibly overridden via https headers. By default it fallbacks to ApplicationRequest.local