https://kotlinlang.org logo
Docs
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
ktor
  • g

    gotoOla

    05/17/2019, 3:28 PM
    Hi! Is there anyway to get notified on onClose-events when using websockets? I recon that you get a ClosedReceiveChannelException when you try to sendto a closed channels but I would like to get triggered as soon as a client disconnects. The Frame.Closed only seems to be sent if the user actually closes, not if they crash
    c
    • 2
    • 4
  • v

    voben

    05/19/2019, 9:28 PM
    Hi, I have created 2 Hocon files. One for dev and one for prod. When running the application, I am currently setting the dev config file like this
    io.ktor.server.netty.EngineMain.main(arrayOf("-config=dev.conf"))
    . Is it possible for the appropriate file to be set automatically based on my environment? How do I detect what environment I am in to be able to set the config file?
    g
    • 2
    • 7
  • p

    Pavel Lechev

    05/20/2019, 8:20 AM
    Hi Ktor team. I am keen on using the native config interface
    io.ktor.config.ApplicationConfig
    across our application code to access the configuration, however still seeing it as "experimental". Are there plans for this to become "official"?
    c
    • 2
    • 2
  • m

    mingkangpan

    05/20/2019, 12:00 PM
    hey I get this error
    Exception in thread "main" java.lang.ClassNotFoundException: Module function cannot be found for the fully qualified name 'com.minki.ktor.ApplicationKt.main'
    g
    d
    • 3
    • 5
  • m

    mingkangpan

    05/20/2019, 12:00 PM
    I think I get my package right?
    v
    • 2
    • 3
  • g

    gregorbg

    05/21/2019, 1:05 PM
    Any smart idea on how to intercept and modify cookies from a remote server response before passing them to the
    Cookies
    feature plugin? At work, we are communicating with an external service that requires cookies but that sends the
    Expires
    cookie in an incorrect format (i.e. localised, German weekday abbreviations that are only 2 chars long). The
    ktor-client
    module in our codebase subsequently throws an exception at https://github.com/ktorio/ktor/blob/68eef1948ce4c8c11dae794588f8d063afb67d0b/ktor-http/common/src/io/ktor/http/DateUtils.kt#L20 blocking further development. The communications partner is an enterprise-grade provider, so negotiating with them to just abide by the f*ing standards is not an option, I'm afraid. (Although it's sad that a company like them doesn't care for standards in the first place, but that's totally not my point here.)
    ✅ 1
    c
    • 2
    • 5
  • s

    Steven

    05/21/2019, 6:02 PM
    Hi, I am wondering if we can use Websockets with ktor in a kotlin multiplatform project (android and iOS)?
    c
    • 2
    • 2
  • c

    carrot

    05/22/2019, 3:41 PM
    Filed a bug report about using
    ApplicationCall.receive
    with Jackson, I know there's loads of issues on the repo, so would appreciate a sanity check about expected behaviour, if anyone fancies taking a look - happy to close it if it's what people are expecting 🙂 https://github.com/ktorio/ktor/issues/1146
    c
    • 2
    • 2
  • s

    Simon Schubert

    05/22/2019, 5:29 PM
    Is the ktor client auth feature not multiplatform compatible? i thought so but getting unresolved reference and https://github.com/ktorio/ktor/tree/master/ktor-features/ktor-auth only has a jvm folder
    c
    • 2
    • 23
  • c

    carrot

    05/22/2019, 7:14 PM
    I'm really enjoying using Ktor. We're using it for several of the services on an animal adoption project, and we'll eventually use it for all the backend services and the website itself: https://www.adoptanimals.io/ Thanks for making it 🎉
    👍 3
    🎉 5
    s
    • 2
    • 7
  • a

    Antanas A.

    05/23/2019, 7:32 AM
    Hello, I've seen that in ktor 1.2.0 new property was added in jwt authentication provider - "authHeader", currently we are using that authHeader to pass JWT token not from header but from request cookies instead. But it token is invalid we have a need to submit 301 redirect to /login page instead of 401 auth response. Is it possible somehow to setup this behaviour in ktor? With session auth provider where is a "challenge" property for that, but not in jwt.
    c
    • 2
    • 3
  • n

    Nikky

    05/23/2019, 7:49 AM
    has been a while since i checked, but can ktor httpclient now do streaming requests ? keeping the connection open and allowing me to process the chunks (of json) coming in
    c
    • 2
    • 13
  • l

    Lawik

    05/23/2019, 9:34 AM
    How can I prevent this ktor-client exception when the response type is nullable and the body is empty?
    ReceivePipelineException: Fail to run receive pipeline: NoTransformationFoundException: No transformation found: class JsHttpResponse -> class ExerciseProgressDTO
    e
    d
    • 3
    • 7
  • c

    coder82

    05/23/2019, 1:25 PM
    I wanted to creat an httpClient which gets png images bur when I set the content type it throws: Header Content-Type is controlled by the engine, any idea?
    s
    e
    • 3
    • 4
  • h

    hdarritchon

    05/23/2019, 3:30 PM
    Hi everybody, I’d like to log all requests incomming in Ktor with header and body. Currently, I use :
    install(CallLogging) {
            level = <http://Level.INFO|Level.INFO>
            filter { call -> call.request.path().startsWith("/api/v1") }
            callIdMdc()
        }
    And I have some logs like :
    200 OK: GET - /api/v1/health
    but I’d like to have more details like the header and body because in some case I have log like
    Unhandled: POST - /api/v1/catalogEdito/reunion/store
    whereas this endpoint exists and returns some datas for certain type of client. So I think I need to have more details to debug and understand what is going on ! Do you know how I can do it please ?
    j
    • 2
    • 4
  • t

    Thomas

    05/25/2019, 2:44 PM
    Adding Ktor to a project seems also to include Kotlin reflect. This makes the APK size much larger and adds Metadata annotations to all the classes which are visible when decompiling the APK. Is this intended behaviour?
    😮 1
    e
    s
    • 3
    • 6
  • m

    mingkangpan

    05/26/2019, 12:17 PM
    val ktor_version: String by project
    val kotlin_version: String by project
    val logback_version: String by project
    
    plugins {
        application
        kotlin("jvm")
    }
    
    group = "ktorserver"
    version = "0.0.1"
    
    application {
        mainClassName = "io.ktor.server.tomcat.EngineMain"
    }
    
    repositories {
        mavenLocal()
        maven { url = uri("<https://kotlin.bintray.com/ktor>") }
    }
    
    dependencies {
        compile("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version")
        compile("io.ktor:ktor-server-tomcat:$ktor_version")
        compile("ch.qos.logback:logback-classic:$logback_version")
        compile("io.ktor:ktor-server-core:$ktor_version")
        compile("io.ktor:ktor-jackson:$ktor_version")
        testCompile("io.ktor:ktor-server-tests:$ktor_version")
    }
    ^this my gradle.kts
    d
    g
    • 3
    • 4
  • m

    mingkangpan

    05/26/2019, 12:22 PM
    what I find strange is, somehow the auth library is only in test scope...
    n
    g
    • 3
    • 10
  • g

    gotoOla

    05/27/2019, 9:48 AM
    Hello! My internet may be broken but the last link on this page seems to point to nowhere
    <https://ktor.io/advanced/pipeline/route.html>
    maybe it should be called to
    <https://github.com/ktorio/ktor/blob/master/ktor-features/ktor-metrics/jvm/src/io/ktor/metrics/dropwizard/DropwizardMetrics.kt>
    :yes: 1
    e
    • 2
    • 3
  • d

    Dzmitry Neviadomski

    05/27/2019, 11:57 AM
    Hi, anybody knows good tutorial for auth in ktor? I found official documentation and samples too difficult to understand for a newbie like me. Where should Credentials come from? What's the need for Principal and where is it stored? I want to build a simple website with ability to register and login for user. I made a simple form and just store credentials in database and session in cookies, without any usage of Authentication plugin. I just check in needed endpoints, if there session stored, otherwise redirect to login.
    b
    • 2
    • 2
  • c

    cy

    05/28/2019, 10:08 AM
    📣 ktor 1.2.1 bugfix release has been published - Fixed module function lookup (regress, #1132) - Fixed SessionTransportTransformers application order (#1147) - Fixed double content length header in requests on older Androids (#1060) - Fixed receiving a byte channel crash on Android (#1140) - Fixed websocket sockets lifecyle on Jetty engine - Downgraded Gradle to reduce gradle metadata version
    🎉 18
    r
    s
    • 3
    • 4
  • i

    irus

    05/28/2019, 7:43 PM
    https://stackoverflow.com/q/56347516/1538877
    r
    e
    • 3
    • 5
  • r

    rocketraman

    05/28/2019, 9:51 PM
    I've got these two routes:
    /foo:{bar}/{baz}
    /{bar}/{baz}
    When calling
    /foo:123/456
    I was expecting the first route to trigger with bar=123 and baz=456. Instead, the second route triggers with bar=foo:123 and baz=456. Is this a bug or expected?
    d
    m
    • 3
    • 9
  • t

    tylerwilson

    05/28/2019, 11:43 PM
    I am porting some Retrofit code to ktor. I need to add additional params (a signature calculation) to an already built URLBuilder. But I get the following:
    java.lang.IllegalStateException: Cannot modify a builder when final structure has already been built
    . Is there a way to do this? Any examples out there I may refer to? Thank you.
    s
    e
    • 3
    • 5
  • k

    krtko

    05/29/2019, 5:30 AM
    Hey this might be an odd question but is it possible to limit the amount of threads ktor will use or directly set it's thread pool?
    e
    c
    • 3
    • 3
  • r

    Rick Prata

    05/29/2019, 10:56 PM
    I have two issues. 1- I'm getting too many redirects exception when using HttpsRedirect feature for server 2- I'm getting socketTimeoutException after sometime when I try to make an http call every 30 seconds. Can someone help me? I would gladly share more information if needed. Wasn't able to find anything online to help. Thank you!
    c
    • 2
    • 1
  • h

    hyukchan

    05/30/2019, 11:09 AM
    How can we log a specific header from CallLogging feature ?
    c
    • 2
    • 2
  • a

    Andrey Gromov

    05/30/2019, 3:26 PM
    Hi! I trying to work with UDP sockets and have some problem. Every time I start my code, I have 50/50 chance to start normally or receive java.net.SocketException: Already bound
    private suspend fun eventLoop(port: Int) {
            val server = aSocket(ActorSelectorManager(<http://Dispatchers.IO|Dispatchers.IO>))
                .udp()
                .bind(InetSocketAddress(port))       <<<<<<<<<<< Exception
    I'm sure that port is free on bind moment Stacktrace
    Exception in thread "main" java.net.SocketException: Already bound
    	at java.base/sun.nio.ch.Net.translateToSocketException(Net.java:164)
    	at java.base/sun.nio.ch.DatagramSocketAdaptor.bind(DatagramSocketAdaptor.java:105)
    	at io.ktor.network.sockets.UDPSocketBuilder.bind(Builders.kt:152)
    	at io.ktor.network.sockets.UDPSocketBuilder.bind$default(Builders.kt:143)
    	at co.fun.multiplayer.udp.ServerListener.eventLoop(ServerListener.kt:34)
    	at co.fun.multiplayer.udp.ServerListener$start$1.invokeSuspend(ServerListener.kt:26)
    	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    	at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:238)
    	at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.kt:116)
    	at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:80)
    	at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:54)
    	at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source)
    	at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:36)
    	at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source)
    	at co.fun.multiplayer.udp.ServerListener.start(ServerListener.kt:25)
    	at co.fun.multiplayer.udp.MainKt.main(Main.kt:14)
    Caused by: java.nio.channels.AlreadyBoundException
    	at java.base/sun.nio.ch.DatagramChannelImpl.bind(DatagramChannelImpl.java:784)
    	at java.base/sun.nio.ch.DatagramSocketAdaptor.bind(DatagramSocketAdaptor.java:103)
    	... 14 more
    This workaround helping, but it is very ugly
    var server: BoundDatagramSocket
            while (true) {
                try {
                    server = aSocket(ActorSelectorManager(<http://Dispatchers.IO|Dispatchers.IO>))
                        .udp()
                        .bind(InetSocketAddress(port))
                    break
                } catch (e: Exception) {
    
                }
            }
    c
    d
    • 3
    • 20
  • a

    anli

    05/30/2019, 9:09 PM
    Hi! How to accept any routing path?
    z
    c
    • 3
    • 2
  • a

    andev

    05/30/2019, 10:39 PM
    Since Ktor is asynchronous, should I still use coroutines to make my database access async? Currently, I'm doing it so, because that's what I saw in KotlinConf app: https://github.com/JetBrains/kotlinconf-app/blob/master/backend/src/org/jetbrains/kotlinconf/backend/database.kt
    m
    • 2
    • 3
Powered by Linen
Title
a

andev

05/30/2019, 10:39 PM
Since Ktor is asynchronous, should I still use coroutines to make my database access async? Currently, I'm doing it so, because that's what I saw in KotlinConf app: https://github.com/JetBrains/kotlinconf-app/blob/master/backend/src/org/jetbrains/kotlinconf/backend/database.kt
m

mp

05/31/2019, 2:46 PM
Depends on how you’re connecting to the db.
a

andev

05/31/2019, 5:16 PM
I'm pretty much doing it the same way it is done in the KotlinConf, I linked it above.
m

mp

05/31/2019, 7:47 PM
If you’re using blocking i/o, use
withContext(<http://Dispatchers.IO|Dispatchers.IO>) { ... }
. That’s really what it boils down to
View count: 1