Ktor 2.1.1 Help

FAQ

What is the proper way to pronounce Ktor?

Kay-tor

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 DefaultHeadersplugin that sends a Server response header with the Ktor version on it, for example:

Server: ktor-server-core/2.1.1

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. Re-check that it is in the resources folder, and that the resources folder is marked as such. You can consider to set up a project using the project generator or the IntelliJ plugin to have a working project as the base.

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.

Last modified: 01 August 2022