Package io.ktor.util

Types

AlwaysFailNonceManager

object AlwaysFailNonceManager : NonceManager

Stub implementation that always fails. Will be removed so no public signatures should rely on it

AttributeKey

class AttributeKey<T>

Specifies a key for an attribute in Attributes

Attributes

interface Attributes

Map of attributes accessible by AttributeKey in a typed manner

CaseInsensitiveMap

class CaseInsensitiveMap<Value> : MutableMap<String, Value>

A map with case insensitive String keys

ConversionService

interface ConversionService

Data conversion service that does serialization and deserialization to/from list of strings

DefaultConversionService

object DefaultConversionService : ConversionService

The default conversion service that supports only basic types and enums

Digest

interface Digest

Stateful digest class specified to calculate digest.

DispatcherWithShutdown

class DispatcherWithShutdown : CoroutineDispatcher

Specialized dispatcher useful for graceful shutdown

Encoder

interface Encoder

Content encoder.

GenerateOnlyNonceManager

object GenerateOnlyNonceManager : NonceManager

This implementation does only generate nonce values but doesn’t validate them. This is recommended for testing only.

Hash

object Hash

Identity

object Identity : Encoder

Empty Encoder

Lock

expect class Lock

LockTicket

expect class LockTicket

NonceManager

interface NonceManager

Represents a nonce manager. It’s responsibility is to produce nonce values and verify nonce values from untrusted sources that they are provided by this manager. This is usually required in web environment to mitigate CSRF attacks. Depending on it’s underlying implementation it could be stateful or stateless. Note that there is usually some timeout for nonce values to reduce memory usage and to avoid replay attacks. Nonce length is unspecified.

ReadWriteLock

expect class ReadWriteLock

StatelessHmacNonceManager

class StatelessHmacNonceManager : NonceManager

Stateless nonce manager implementation with HMAC verification and timeout. Every nonce provided by this manager consist of a random part, timestamp and HMAC.

StringValues

interface StringValues

Provides data structure for associating a String with a List of Strings

StringValuesBuilder

open class StringValuesBuilder

StringValuesImpl

open class StringValuesImpl : StringValues

StringValuesSingleImpl

open class StringValuesSingleImpl : StringValues

Annotations

InternalAPI

annotation class InternalAPI

API marked with this annotation is ktor internal and it is not intended to be used outside. It could be modified or removed without any notice. Using it outside of ktor could cause undefined behaviour and/or any strange effects.

KtorExperimentalAPI

annotation class KtorExperimentalAPI

API marked with this annotation is experimental and is not guaranteed to be stable.

Exceptions

DataConversionException

class DataConversionException : Exception

Thrown when failed to convert value

Extensions for External Classes

java.io.File

java.lang.Class

java.nio.ByteBuffer

java.nio.channels.ReadableByteChannel

java.nio.channels.WritableByteChannel

java.nio.file.Path

java.util.Date

kotlin.ByteArray

kotlin.Char

kotlin.String

kotlin.collections.List

kotlin.collections.Set

kotlin.ranges.LongRange

kotlinx.coroutines.Job

kotlinx.coroutines.io.ByteReadChannel

kotlinx.coroutines.io.ByteWriteChannel

kotlinx.io.core.ByteReadPacket

kotlinx.io.core.Input

org.slf4j.Logger

Properties

Deflate

val Deflate: Encoder

Implementation of Deflate Encoder.

GZip

val GZip: Encoder

Implementation of GZip Encoder.

GreenwichMeanTime

val GreenwichMeanTime: ZoneId

ZoneId for GMT

nonceRandom

val nonceRandom: Random

Functions

Attributes

expect fun Attributes(
    concurrent: Boolean = false
): Attributes

Create attributes instance suitable for the particular platform

Digest

expect fun Digest(name: String): Digest

Create Digest from specified hash name.

appendAll

Append all values from the specified builder

appendFiltered

fun StringValuesBuilder.appendFiltered(
    source: StringValues,
    keepEmpty: Boolean = false,
    predicate: (String, String) -> Boolean
): Unit

Append values from source filtering values by the specified predicate

build

suspend fun Digest.build(bytes: ByteArray): ByteArray

Calculate digest from current state and specified bytes.

suspend fun Digest.build(
    string: String,
    charset: Charset = Charsets.UTF_8
): ByteArray

Calculate digest from current state and specified string.

caseInsensitiveMap

fun <Value> caseInsensitiveMap(): MutableMap<String, Value>

Create an instance of case insensitive mutable map. For internal use only.

filter

fun StringValues.filter(
    keepEmpty: Boolean = false,
    predicate: (String, String) -> Boolean
): StringValues

Create a new instance of StringValues filtered by the specified predicate

flattenEntries

fun StringValues.flattenEntries(): List<Pair<String, String>>

Copy values to a list of pairs

flattenForEach

fun StringValues.flattenForEach(
    block: (String, String) -> Unit
): Unit

Invoke block function for every value pair

generateNonce

expect fun generateNonce(): String

Generates a nonce string. Could block if the system’s entropy source is empty

fun generateNonce(size: Int): ByteArray

Generates a nonce bytes of size. Could block if the system’s entropy source is empty

getDigestFunction

fun getDigestFunction(
    algorithm: String,
    salt: String
): (String) -> ByteArray

Create a digest function with the specified algorithm and salt

fun getDigestFunction(
    algorithm: String,
    salt: (value: String) -> String
): (String) -> ByteArray

Create a digest function with the specified algorithm and salt provider.

getOrFail

fun Parameters.getOrFail(name: String): String

Get parameters value associated with this name or fail with MissingRequestParameterException

getValue

operator fun <R : Any> Parameters.getValue(
    thisRef: Any?,
    property: KProperty<*>
): R

Operator function that allows to delegate variables by call parameters. It does conversion to type R using DefaultConversionService

hex

fun hex(bytes: ByteArray): String

Encode bytes as a HEX string with no spaces, newlines and 0x prefixes.

fun hex(s: String): ByteArray

Decode bytes from HEX string. It should be no spaces and 0x prefixes.

nextNonce

fun nextNonce(): String

Generates a nonce string 16 characters long. Could block if the system’s entropy source is empty

raw

fun raw(s: String): ByteArray

Encode string as UTF-8 bytes

sha1

expect fun sha1(bytes: ByteArray): ByteArray

Compute SHA-1 hash for the specified bytes

toMap

fun StringValues.toMap(): Map<String, List<String>>

Copy values to a new independent map

url

fun url(block: URLBuilder.() -> Unit): String

Construct a URL

fun ApplicationCall.url(
    block: URLBuilder.() -> Unit = {}
): String

Creates an url using current call’s schema, path and parameters as initial and then invokes block function on the url builder so amend parameters

use

fun <R> Lock.use(block: () -> R): R

valuesOf

fun valuesOf(
    vararg pairs: Pair<String, List<String>>,
    caseInsensitiveKey: Boolean = false
): StringValues

Build an instance of StringValues from a vararg list of pairs

fun valuesOf(
    name: String,
    value: String,
    caseInsensitiveKey: Boolean = false
): StringValues

Build an instance of StringValues from a single pair

fun valuesOf(
    name: String,
    values: List<String>,
    caseInsensitiveKey: Boolean = false
): StringValues

Build an instance of StringValues with a single name and multiple values

fun valuesOf(): StringValues

Build an empty StringValues instance.

fun valuesOf(
    map: Map<String, Iterable<String>>,
    caseInsensitiveKey: Boolean = false
): StringValues

Build an instance of StringValues from the specified map

Companion Object Functions

createFromCall

fun URLBuilder.Companion.createFromCall(
    call: ApplicationCall
): URLBuilder

Creates an url using current call’s schema, path and parameters as initial