Migrating 0.9.4 → 0.9.5

Estimated reading time: 3 minutes


Ktor 0.9.5 is a minor update, fixing some bugs, bumping some versions, and adding some minor stuff.


Published 19 Sep 2018

Version Bumps:

  • Kotlin: 1.2.61 -> 1.2.70

Minor potential breaking changes:

  • Client’s CookiesStorage.get, CookiesStorage.addCookie and HttpCookies.get now accepts the requestUrl instead of the host. Now the get returns a list of cookies.
  • Made HTTP Client extension method HttpRequest.takeFrom(builder: HttpRequestBuilder): HttpRequestBuilder. Now also sets the typed call attributes from the builder. into a member method. Shouldn’t be a source compatibility problem when using star imports * since it is in the same package.


  • HttpClient.config was not preserving the base configuration (#559)
  • Fixed path and query escaping and make it consistent with URLBuilder (#577).
  • Fixed setting charset encoding for non-text content types


  • Introduced CallId feature
  • Added MDC support to CallLogging feature

API Improvements:

  • Added shorthand client functions for HEAD, OPTIONS, PATCH and DELETE methods (#562)
  • HTTP Client: Added List<Cookie>.get(name: String): Cookie? shortcut.
  • HTTP Client: Added fun FormBuilder.append(key: String, filename: String, block: BytePacketBuilder.() -> Unit) to the FORM DSL.
  • URLBuilder’s parser improved (#553, #567)
  • Added respondOutputStream { } response function
  • Split Infrastructure phase into Monitoring and Features phases


  • Made AcceptAllCookiesStorage be the same for all the implementations.
  • Improved client’s cookie matching and processing

New http method shorcuts for the HTTP client

Before 0.9.5, when using the HTTP client and wanting to make a HEAD, OPTIONS, PATCH or DELETE request, you had to either use the HttpClient.request or the HttpClient.call.

As for 0.9.5, in addition to HttpClient.get and HttpClient.post there are now four more convenience methods HttpClient.head, HttpClient.options, HttpClient.patch and HttpClient.delete HTTP verbs.

Split Infrastructure phase into Monitoring and Features phases

In most of the cases, you should use the Features phase instead of the Infrastructure one:

intercept(ApplicationCallPipeline.Infrastructure) {
    // ...

would become:

intercept(ApplicationCallPipeline.Features) {
    // ...

CallId and MDC support in CallLogging

The CallLogging feature have been updated to allow to specify MDC (Mapped Diagnostic Context) keys + providers to be associated to a specific call/request regardless of the ThreadScheduler. The feature is implemented using kotlinx.coroutines ThreadContextElement, so it is transparent and works well with slf4j.

0.9.5 includes a new CallId feature that allows to identify calls from an ID. It allows to provide several methods for receiving or generating that Call Identifier, and also optionally allows to include the id as part of the response, for example as a header. The CallId is also associated to the MDC of the call, so the logs for a specific call can be identified and grouped together.