Migrating from 2.0.x to 2.2.x
This guide provides instructions on how to migrate your Ktor application from the 2.0.x version to 2.2.x.
Ktor Server
Cookies
With v2.2.0, the following API members related to configuring response cookies are changed:
The
maxAge
parameter type passed to theappend
function is changed fromInt
toLong
.The
appendExpired
function is deprecated. Use theappend
function with theexpires
parameter instead.
Request address information
Starting with the 2.2.0 version, the RequestConnectionPoint.host
and RequestConnectionPoint.port
properties used to get the hostname/port to which the request was made are deprecated.
Use RequestConnectionPoint.serverHost
and RequestConnectionPoint.serverPort
instead. We've also added the localHost
/localPort
properties that return the hostname/port on which the request was received. You can learn more from the Original request information.
Merging configurations
Before v2.2.0, the List<ApplicationConfig>.merge()
function is used to merge application configurations. In case both configurations have the same key, the resulting configuration takes the value from the first one. With this release, the following API is introduced to improve this behavior:
public fun ApplicationConfig.withFallback(other: ApplicationConfig): ApplicationConfig
: this function works the same way asmerge()
and takes the value from the first configuration.public fun ApplicationConfig.mergeWith(other: ApplicationConfig): ApplicationConfig
: the resulting configuration takes the value from the second one.
Ktor Client
Caching: Persistent storage
With v2.2.0, the following API related to response caching is deprecated:
The
HttpCacheStorage
class is replaced with theCacheStorage
interface, which can be used to implement a persistent storage for the required platform.The
publicStorage
/privateStorage
properties are replaced with corresponding functions that acceptCacheStorage
instances.
Custom plugins
Starting with the 2.2.0 release, Ktor provides a new API for creating custom client plugins. To learn more, see Custom plugins.
New memory model
With v2.2.0, Ktor uses the 1.7.20 version of Kotlin, in which the new Kotlin/Native memory model is enabled by default. This means that you don't need to enable it explicitly for Native server or client engines targeting Kotlin/Native.