Ktor 2.3.10 Help

FAQ

What is the proper way to pronounce Ktor?

/ke…™-tor/

What does the name "Ktor" stand for?

The name Ktor is derived from the abbreviation ctor (constructor) with the first letter replaced by 'K' for Kotlin.

How do I put questions, report bugs, contact you, contribute, give feedback, etc.?

Go to the Support page to learn more about the available support channels. The How to contribute guide describes the ways you can contribute to Ktor.

What does CIO mean?

CIO stands for Coroutine-based I/O. Usually we call it to an engine that uses Kotlin and Coroutines to implement the logic implementing an IETF RFC or another protocol without relying on external JVM-based libraries.

How to fix unresolved (red) Ktor imports?

Make sure that corresponding Ktor artifacts are added in the build script.

Does Ktor provide a way to catch IPC signals (e.g. SIGTERM or SIGINT) so the server shutdown can be handled gracefully?

If you are running an EngineMain, it will be handled automatically. Otherwise, you need to handle it manually. You can use the Runtime.getRuntime().addShutdownHook JVM's facility.

How do I get the client IP behind a proxy?

The call.request.origin property gives connection information about the original caller (the proxy) if the proxy provides proper headers, and the ForwardedHeader plugin is installed.

How can I test the latest commits on main?

You can get Ktor nightly builds from jetbrains.space. Learn more from Early Access Program.

How can I be sure of which version of Ktor am I using?

You can use the DefaultHeaders plugin that sends a Server response header with the Ktor version on it, for example:

Server: ktor-server-core/2.3.10

My route is not being executed. How can I debug it?

Ktor provides a tracing mechanism to help troubleshooting routing decisions. Check the Tracing routes section.

How to resolve 'Response has already been sent'?

This means that you, or a plugin or interceptor, have already called call.respond* functions, and you are calling it again.

How can I subscribe to Ktor events?

See the Application monitoring page to learn more.

How to resolve 'No configuration setting found for key ktor'?

This means that Ktor was not able to find a configuration file. Ensure that there is a configuration file in the resources folder, and that the resources folder is marked as such. Consider setting up a project using the Ktor project generator or the Ktor plugin for intelliJ IDEA Ultimate to have a working project as the base. For more information, see Create, open and run a new Ktor project.

Can I use Ktor on Android?

Yes, Ktor servers and clients are known to work on Android 5 (API 21) or greater, at least with the Netty engine.

Why 'CURL -I' returns a '404 Not Found'?

CURL -I is an alias of CURL --head that performs HEAD requests. By default, Ktor doesn't handle HEAD requests for GET handlers. To enable this capability, install the AutoHeadResponse plugin.

How to resolve an infinite redirect when using the 'HttpsRedirect' plugin?

The most probable cause is that your backend is behind a reverse proxy or a load balancer, and that this intermediary is making normal HTTP requests to your backend, thus the HttpsRedirect plugin inside your Ktor backend believes that it is a normal HTTP request and responds with the redirect.

Normally, reverse-proxies send some headers describing the original request (like it was HTTPS, or the original IP address), and there is a plugin ForwardedHeader to parse those headers so the HttpsRedirect plugin knows that the original request was HTTPS.

How to install 'curl' on Windows to use a corresponding engine on Kotlin/Native?

The Curl client engine requires installing the curl library. On Windows, you may want to consider a MinGW/MSYS2 curl binary.

  1. Install MinGW/MSYS2 as described in MinGW/MSYS2.

  2. Install libcurl using the following command:

    pacman -S mingw-w64-x86_64-curl
  3. If you've installed MinGW/MSYS2 to a default location, add C:\msys64\mingw64\bin\ to the PATH environment variable.

How to resolve 'NoTransformationFoundException'?

NoTransformationFoundException represents the inability to find a suitable transformation for the received body from resulted type to expected by the client type.

  1. Check that the Accept header in your request specifies the desired content type and that the Content-Type header in the server's response matches the expected type on the client side.

  2. Register the necessary content transformations for the specific content types you're working with.

    You can use the ContentNegotiation plugin for the client side. This plugin allows you to specify how to serialize and deserialize data for different content types.

    val client = HttpClient(CIO) { install(ContentNegotiation) { json() // Example: Register JSON content transformation // Add more transformations as needed for other content types } }
  3. Make sure that you install all the needed plugins. Possible missing features:

Last modified: 02 April 2024