https://kotlinlang.org logo
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
  • j

    jozefdransfield

    08/24/2020, 8:11 PM
    I have a question about websockets, i have a Channel that i am calling consumeEach on in the body of the webSocket route. This channel opens some resources which i would like to close if the websocket receives a client disconnect. Anyone any suggestions on how i might go about that?
    t
    w
    • 3
    • 6
  • a

    addamsson

    08/26/2020, 8:51 AM
    Is there anyone here who managed to get
    watch
    to work in Ktor? I've been trying for ages but it never works. Right now I get
    Module function provided as lambda cannot be unlinked for reload
    even though I copied the exact same code from the documentation site:
    fun main(args: Array<String>) {
        embeddedServer(
                Netty,
                watchPaths = listOf("mydir"),
                port = PORT,
                module = Application::module
        ).start(true)
    }
    What am I doing wrong?
    m
    • 2
    • 6
  • b

    bitkid

    08/26/2020, 2:11 PM
    Do i read it correctly that Ktors HTTP2 support does not work without SSL/TLS? browser is not an issue for me because i am implementing a REST service (netty engine).
    • 1
    • 1
  • w

    wellingtoncosta

    08/26/2020, 2:24 PM
    After update to ktor 1.4.0, the
    KotlinxSerializer
    is missing. Is there a way to solve this?
    e
    m
    d
    • 4
    • 15
  • r

    rrva

    08/26/2020, 3:02 PM
    using
    -javaagent:kotlinx-coroutines-debug-1.3.9.jar
    and
    DebugProbes.dumpCoroutines
    the coroutines running ktor client requests are not showing up… is there some case of how coroutines are created that are missing in the agent instrumentation?
    • 1
    • 1
  • g

    gotoOla

    08/26/2020, 8:35 PM
    Hi! We are using
    compile "io.ktor:ktor-client-apache:1.2.3"
    in a full fledged ktor project we have. We've been quite happy with it but lately it seems some services detoriate over time and we start to see
    IO: Connection reset by peer
    . Now my first approach was to check the server that is receiving the calls we are making (if they were being ddosed by us, potential downtime etc) but it seems that the http call doesn't even leave us. Given the detoriation over time my mind goes towards stale connection or something of that sort. Has anybody else experienced this kind of issue?
    r
    • 2
    • 10
  • r

    rrva

    08/27/2020, 9:22 AM
    Is it possible to run on ktor 1.3.x with Kotlin 1.4.x or is that mix of versions discouraged?
    m
    • 2
    • 1
  • n

    Nicolas Bourdin

    08/27/2020, 9:37 AM
    Hello, How can I get the http body message in my response when i get a http error ? I see the response.readText() but it doesn't seem to work...
    g
    m
    • 3
    • 7
  • m

    manlan

    08/27/2020, 7:40 PM
    Your current kotlinx.serialization core version is too low, while current Kotlin compiler plugin 1.4.0 requires at least 1.0-M1-SNAPSHOT. Please update your kotlinx.serialization runtime dependency.
    This is what I see after upgrading to 1.4.0
    Untitled
    m
    • 2
    • 3
  • z

    zero_coding

    08/28/2020, 12:06 PM
    Hi all I am trying to enable autoreload function and I have tried as follows:
    ktor {
        deployment {
            port = 8080
            port = ${?PORT}
            watch = [ user-svc ]
        }
        application {
            modules = [ io.databaker.ApplicationKt.module ]
        }
    }
    n
    • 2
    • 3
  • z

    zero_coding

    08/28/2020, 12:08 PM
    And the following statement does not work
    ./gradlew -t installDist .
    
    FAILURE: Build failed with an exception.
    
    * What went wrong:
    Task '.' not found in root project 'user-svc'.
    
    * Try:
    Run gradlew tasks to get a list of available tasks. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
    
    * Get more help at <https://help.gradle.org>
    
    BUILD FAILED in 409ms
    m
    r
    m
    • 4
    • 5
  • z

    zero_coding

    08/28/2020, 12:45 PM
    I am using https://github.com/JetBrains/Exposed
    e
    j
    • 3
    • 7
  • g

    Gunslingor

    08/29/2020, 1:38 AM
    How does one do:
    withTestApplication(Application::commonFeatures AND Application::someotherFeatures)
    • 1
    • 1
  • b

    basher

    08/29/2020, 1:57 AM
    Has anyone used R8 with a ktor server app?
    🇳🇴 2
    n
    • 2
    • 2
  • g

    Gunslingor

    08/29/2020, 11:40 PM
    How do I redirect ALL non-authenticated routes to a login page? i.e. how does one get("EVERYTHING")... get(" * ") only gets ANYTHING/ but not ANYTHING/ANYTHING.
    j
    • 2
    • 4
  • z

    zero_coding

    08/30/2020, 6:04 PM
    the source from https://github.com/ktorio/ktor-samples/blob/1.3.0/deployment/jetty-war/build.gradle
    j
    j
    • 3
    • 10
  • e

    efemoney

    08/31/2020, 3:08 AM
    Hey everyone, I’m wondering, will this do what I believe it will do?
    /**
     * Compose multiple pipeline [interceptors] into one. This executes [interceptors] in a new pipeline running in this
     * interceptors context on this interceptors subject
     *
     * @return A [PipelineInterceptor] that executes other [interceptors] in a pipeline within its own context on its own subject
     * @param interceptors [PipelineInterceptor]s to execute **serially**
     */
    fun <TSubject : Any, TContext : Any> compose(
      vararg interceptors: PipelineInterceptor<TSubject, TContext>
    ): PipelineInterceptor<TSubject, TContext> = {
      val pipeline = Pipeline(PipelinePhase("Compose"), interceptors.asList())
      pipeline.execute(context, subject)
    }
    with usage:
    route("/api") {
      get("/comics", GetAllComics)
      get("/comics/{page}", GetComicPage)
      get("/comics/latest", GetComicLatest)
      put("/users/token", compose(AuthenticateUser, SaveUserToken))
      put("/users/page", compose(AuthenticateUser, SaveUserPage))
    }
    I am trying to get the same behavior as nodejs’s
    express
    interceptors.
    j
    • 2
    • 4
  • g

    gotoOla

    08/31/2020, 9:30 AM
    Hi! Has anyone done a nice implementation or library where you can add an auth mechanism to the call-stack like what was usually done with mdc/thread locals in Java? I read about the ContextElements but apparantly you have to keep track of your context every time you do a launch/async which seems a bit error prone/brittle
    e
    • 2
    • 13
  • h

    Helio

    08/31/2020, 10:33 PM
    Hello guys! I was wondering if someone could give me a hand configuring a proxy using Ktor with CIO engine. I’ve been struggling to get it worked… I’m constantly receiving exceptions such as:
    Untitled
    j
    • 2
    • 8
  • k

    Kris Wong

    09/01/2020, 8:58 PM
    Could not find io.ktor:ktor-client-mock-native:1.4.0.
    • 1
    • 1
  • h

    Hyun

    09/01/2020, 9:57 PM
    Hi, guys, I have a problem on Ktor client native. I’ve been struggling to make the code below works after migrating kotlin to 1.4.0 version while migrating, I changed coroutine version to
    1.3.9-native-mt
    class TestFreezingViewModel(val client: HttpClient) {
    
        fun call() {
             CoroutineScope(Dispatchers.Main).launch(start = CoroutineStart.LAZY) {
                try {
                    client.get<String>("<https://test.com>") {}
                } catch (e: Throwable) {
                    e.printStackTrace()
                }
    
            }.start()
        }
    }
    
    // swift side code
    TestFreezingViewModel().call()
    while the code running, The error(on the slack thread) occurs when Coroutine’s
    invokeOnCompletion
    is invoked, freeze() is called. and it tells that
    HttpClient
    can’t be frozen When I checked the source code HttpClient.init calls
    preventFreeze()
    I would like to know the intention of
    preventFreeze
    and what is the proper approach to use on developer’s side. Is there some advice?
    • 1
    • 2
  • h

    Hyun

    09/02/2020, 4:42 AM
    one more questions😅 https://kotlinlang.slack.com/archives/C1CFAFJSK/p1597886480055300 ktor client 1.4.0 seems related to coroutines-core:1.3.9-native-mt when I use all of the below, there is error shared on the link • maven-publish • coroutine 1.3.9 • ktor-client-core 1.4.0 is there some workaround not to use native-mt? or instead, is it fine to use ktor 1.3.2 with kotlin 1.4.0?
    l
    e
    • 3
    • 12
  • z

    zero_coding

    09/02/2020, 10:06 AM
    However, how to configure it?
    c
    • 2
    • 5
  • o

    Ovsyannikov Alexey

    09/02/2020, 3:22 PM
    Hello. I am using ktor 1.4.0 and trying to use websockets. Setup contains: websocket client, websocket server, ktor 1.4.0, launching of websocket on client side working inside of flow. I faced the problem that it is blocking the thread and the whole page freezing. It would partially ok in case, if request would reach its destimation, but on server side there are no any tracing of connection receiving (I have enabled it) and there are no any action triggered inside of websocket routing.
    • 1
    • 2
  • k

    Kris Wong

    09/02/2020, 4:43 PM
    is it known that the native mock engine is broken in 1.4?
    r
    • 2
    • 18
  • k

    Kris Wong

    09/02/2020, 7:36 PM
    Untitled
    • 1
    • 1
  • m

    manlan

    09/03/2020, 4:05 AM
    How do I make authentication optional for a few endpoints? E.g. signin API doesn't need authentication, but the other APIs need it (I'm thinking of JWT).
    j
    • 2
    • 2
  • b

    bitkid

    09/03/2020, 8:58 AM
    Hey! Does anyone know how i can get around "Header Content-Type is controlled by the engine and cannot be set explicitly" My app can return JSON and CSV and the format is controlled by the Accept header in the request. I can set the content type explicitly to text/csv when using respondOutputStream or streamDirect but i can't use it with call.respond("my csv, as text").
    • 1
    • 1
  • l

    louiscad

    09/03/2020, 3:26 PM
    Hello! From client side, how can one get the progress of a call (pending, connecting, writing and how many bytes sent vs total, waiting for response, reading and how many bytes sent vs total)? I'd like to expose such data in a flow in order to provide the best UX possible regarding the user knowing what they are waiting for and how fast it's going.
    👍 8
    ➕ 4
    s
    • 2
    • 1
  • z

    zero_coding

    09/03/2020, 7:10 PM
    Hi all I have written a REST API in Ktor and would like secure it with Keycloak. All the examples of the website https://github.com/ktorio/ktor-samples/blob/1.3.0/feature/auth/src/io/ktor/samples/auth/OAuthLoginApplication.kt does not base on REST API. My question is, how can I secure my REST API with https://ktor.io/servers/features/authentication/oauth.html. Thanks
    m
    • 2
    • 1
Powered by Linen
Title
z

zero_coding

09/03/2020, 7:10 PM
Hi all I have written a REST API in Ktor and would like secure it with Keycloak. All the examples of the website https://github.com/ktorio/ktor-samples/blob/1.3.0/feature/auth/src/io/ktor/samples/auth/OAuthLoginApplication.kt does not base on REST API. My question is, how can I secure my REST API with https://ktor.io/servers/features/authentication/oauth.html. Thanks
m

Mathias Rørvik

09/04/2020, 1:36 PM
You just have to wrap your protected endpoints with
authenticate { }
where they send html, you send json
View count: 7