FAQ

In this section, we provide answers to the questions you frequently ask us.

note

Can’t find an answer for your question? Head over our #ktor Kotlin Slack channel, and we will try to help you!

kay-tor

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

Depending on the content, you might consider several channels:

  • GitHub: Feature request, change suggestions/proposals, bugs and PRs.

  • Slack: Questions, troubleshooting, guidance etc.

  • StackOverflow: Questions.

Rationale:

For questions or troubleshooting we highly recommend you to use Slack or StackOverflow.

Think that using GitHub issues would notify all the people that is subscribed potentially with emails, troubleshooting usually requires several questions and answers, that could be a lot of emails spread in the time, and maybe the people subscribed want to be informed about bugs, fixes, new things introduced or proposed, but maybe they are not interested in other things.

If you have enough time or you prefer not to join Slack, you can also ask questions at StackOverflow. With slack being an hybrid between chat and forum, we can contact each other faster and troubleshoot things in less time.

When troubleshooting, if we determine that there is a bug, or something to improve, you can report it a GitHub. Of course, it is not a good idea either to keep a bug report (once confirmed) just in Slack since it could be forgotten, so lets put them in GitHub.

Pull Requests:

If you have a functionality or bugfix you think would be worth including in Ktor, you can create a PR.

Have in mind that we usually review and merge PRs in batches, so the PR could be outstanding for a few weeks. But still we encourage you to contribute if you can!

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.

Ktor imports are not being resolved. Imports are in red.

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

FAQ - 图1

If you are running a /EngineMain, it will be handled automatically.

Otherwise you will have to . You can use Runtime.getRuntime().addShutdownHook JVM’s facility.

How do I get the client IP behind a proxy?

tip

You get this error if you try to use the locations feature without actually installing it. Check the locations feature: https://ktor.io/features/locations.html

How can I test the latest commits on master?

You can use jitpack to get builds from master that are not yet released: Also you can build Ktor from source, and use your mavenLocal repository for the artifact or to upload your artifacts to your own artifactory/bintray.

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

You can use the that will send a Server header with the Ktor version on it. Something similar to Server: ktor-server-core/1.0.0 ktor-server-core/1.0.0 should be sent as part of the response headers.

Website accessibility tips and tricks

My route is not being executed, how can I debug it?

Ktor provides a tracing mechanism for the routing feature to help troubleshooting routing decisions. Check the Tracing the routing decisions section in the Routing page.

I get a io.ktor.pipeline.InvalidPhaseException: Phase Phase(‘YourPhase’) was not registered for this pipeline.

This means that you are trying to use a phase that is not registered as a reference for another phase. This might happen for example in the Routing feature if you try to register a phase relation inside a node, but the phase referenced is defined in another ancestor Route node. Since route phases and interceptors are later merged, it should work, but you need to register it in your Route node:

  1. route.addPhase(PhaseDefinedInAncestor)
  2. route.insertPhaseAfter(PhaseDefinedInAncestor, MyNodePhase)

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

How can I subscribe to Ktor events?

There is a page .

I get a Exception in thread “main” com.typesafe.config.ConfigException$Missing: No configuration setting found for key ‘ktor’ exception

This means that Ktor was not able to find the application.conf 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 to have a working project as base.

Can I use ktor on Android?

Ktor is known to work on Android 7 or greater (API 24). It will fail in lower versions like Android 5.

In unsupported versions it would fail with an exception similar to:

For more information, check Issue #495 and

CURL -I returns a 404 Not Found

CURL -I that is an alias of CURL --head that performs a request. By default Ktor doesn’t handle HEAD requests for GET handlers, so you might get something like:

  1. curl -I http://localhost:8080
  2. HTTP/1.1 404 Not Found

for:

Ktor can automatically handle HEAD requests, but requires you to first install the AutoHeadResponse feature.

  1. install(AutoHeadResponse)

I get an infinite redirect when using the HttpsRedirect feature

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