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
  • s

    Slackbot

    06/29/2019, 3:31 AM
    This message was deleted.
    v
    • 2
    • 1
  • g

    gschulze

    06/30/2019, 10:36 AM
    Hey there! My name is Gunnar, I work for a small analytics company located in Austria and we're using Ktor as backend technology for serving our dashboard applications.
    d
    g
    • 3
    • 8
  • g

    gschulze

    06/30/2019, 10:37 AM
    I have a rather specific question. Would it be possible from a technical perspective to "mount" a Ktor application at a specific path, e.g. "/dashboard1", inside a host application? I know I can achieve something similar by just writing an application module, but I'd prefer complete isolation of application features. If this is possible, could anyone outline the necessary steps, e.g. custom ApplicationEnvironment, etc. to achieve this? Many thanks in advance!
    g
    c
    • 3
    • 7
  • l

    lenqnr

    07/01/2019, 6:01 AM
    When I send a POST request with String typed body,
    <http://client.post|client.post><String>("/path", "hello")
    I get double-quoted data on both sides.
    println(call.receiveText())
    // Result: "hello"
    What is the proper way to handle this?
    c
    e
    • 3
    • 5
  • d

    dhristov

    07/01/2019, 1:13 PM
    I have a question regarding request queueing in
    io.ktor.server.netty.NettyApplicationEngine
    . It seems like the inner Configuration's
    requestQueueLimit
    and
    runningLimit
    parameters are not actually used (as far as I can tell by looking in the master branch the idea seems to be that these are propagated to
    io.ktor.server.netty.cio.NettyRequestQueue
    , but don't seem to be used). Are there any plans to actually support these in the future or will they be dropped? If they are planned for support, can I help speed things up (by contributing an implementation for example)? @cy
    c
    • 2
    • 2
  • m

    Matej Drobnič

    07/01/2019, 5:02 PM
    Is there SQL database that supports nonblocking access? It is kinda moot to use nonblocking ktor server only to end up blocking on JDBC queries.
    v
    c
    +2
    • 5
    • 13
  • q

    qlitzler

    07/02/2019, 8:44 AM
    Hello, I think I've found a bug and opened an issue for it: https://github.com/ktorio/ktor/issues/1216 It seems like when a timeout occurs during the deserialization phase of a request (hard to reproduce), we get a
    Operation is a already in progress
    exception. Any advice on what I could do to avoid this in the meantime ?
    t
    • 2
    • 3
  • h

    Horv

    07/02/2019, 6:15 PM
    As I've understood it
    location
    (in terms of routing) is being deprecated? All oauth examples I can find utilizes that quite heavily and I'm a bit new to Ktor to know my way around things. Anyone can point me to an example of OAuth implementation that doesn't depend on
    location
    and such?
    😮 1
    c
    • 2
    • 3
  • s

    Sergioedcigreja

    07/03/2019, 10:48 AM
    Hello everyone, Im getting No such element exception - List is empty when changing the configuration of HttpClient in iOS. client = HttpClient().config { expectSuccess = false install(JsonFeature) { serializer = defaultSerializer() } }
    t
    e
    • 3
    • 19
  • p

    pyryjook

    07/03/2019, 7:45 PM
    Hi! I’ve been fiddling around with Ktor and K/N on MacOS. I got other suspending functions which do work in the same app(called the same way as the following function), but this suspended function just hangs forever:
    suspend fun getContent(): String {
        val client = HttpClient()
        return client.get<String>("<http://www.google.com>")
    }
    Any ideas on what might cause it? I came across with the following similar issues, but I was not able to fix the issue of mine based on how the these issues had been solved: - https://stackoverflow.com/q/56347516/1538877 - https://github.com/ktorio/ktor/issues/678 All the help is appreciated, thanks in advance!
    s
    g
    • 3
    • 13
  • a

    Akram

    07/04/2019, 4:01 PM
    hello i'm starting up with ktor , and want to implement my own oauth2 provider can i do it with ktor ?
    s
    • 2
    • 4
  • s

    Sergio Casero

    07/04/2019, 4:01 PM
    Hi everyone! I've have just a (maybe noob) question. I'm implementing Oauth2 by using this guide -> https://ktor.io/quickstart/guides/oauth.html and looks like everything is working fine, I can see the token but... the question is, how can I indicate that requests need the auth? Right now my config is something like this:
    routing {
            authenticate(OauthConfig.NAME) {
                route("/test") {
                    get { call.respond("Sample from auth part...") }
                }
            }
        }
    When I call this WS, I set the access token into the auth header (Bearer) with postman but I get 401, if I do the request from browser, I always get a redirection to the login and it generates new token 😞
    c
    • 2
    • 3
  • a

    Andrew Gazelka

    07/04/2019, 9:48 PM
    is there a shortcut to
    exception.response.content.readUTF8Line()
    ? For debugging I feel like this overly complicated and confusing
    m
    • 2
    • 1
  • s

    Sergey Akhapkin

    07/05/2019, 2:21 PM
    Hi everyone! I've following question: There is a cookie definition from Ktor:
    data class Cookie(
        val name: String,
        val value: String,
        val encoding: CookieEncoding = CookieEncoding.URI_ENCODING,
        val maxAge: Int = 0,
    How it's possible to set cookie without 'maxage' - per standard, it means the lifetime of cookie is restricted by lifetime of client ?
    s
    t
    • 3
    • 9
  • z

    zsoltkiss

    07/05/2019, 4:47 PM
    Hi all! I'm new to Ktor and I'd need some help on how to generate a .war file from my Ktor webapp? Though I created a .war using Gretty plugin but the artifact has strange folder structure. I copied the .war on a Tomcat but can't see anything in the browser.
    m
    • 2
    • 6
  • m

    magoeke

    07/05/2019, 9:42 PM
    I'm currently playing around with ktor client. It looks like the auth feature has some problems since version 1.2.0 . This import doesn't work with all versions above 1.1.5: io.ktor.client.features.auth.Auth. Is someone else having the same issue?
    v
    • 2
    • 3
  • d

    darkmoon_uk

    07/07/2019, 9:54 AM
    Is Ktor for JVM also designed with Java 9+ modules compatibility in mind (i.e. containing Java module define and avoiding split packages)?
    r
    • 2
    • 2
  • t

    tseisel

    07/08/2019, 10:16 AM
    Is there a way to automatically retry a request given a specific response (for example, HTTP 421) with HttpClient ?
    v
    • 2
    • 2
  • g

    gotoOla

    07/08/2019, 3:39 PM
    @tseisel don’t know about any such built in behavior but when we’ve come across such use cases in my team we have used kotlins repeat and in some cases just written extensions
    t
    • 2
    • 1
  • l

    Lyon Chen

    07/09/2019, 4:01 AM
    Hi all, I'm trying to use ktor 1.2.2 with Curl engine to call REST API on Windows, but it always returns the following excpetion. Could you kindly give some comments? Thanks. Console log: HttpClient: REQUEST: https://postman-echo.com/get?foo1=bar1&amp;foo2=bar2 HttpClient: METHOD: HttpMethod(value=GET) HttpClient: COMMON HEADERS HttpClient: -> Accept-Charset: UTF-8 HttpClient: -> Accept: / HttpClient: CONTENT HEADERS HttpClient: REQUEST https://postman-echo.com/get?foo1=bar1&amp;foo2=bar2 failed with exception: io.ktor.client.engine.curl.CurlIllegalStateException: Connection failed for request: io.ktor.client.engine.curl.internal.CurlRequestData@48bd218
    m
    • 2
    • 6
  • a

    Alexander Weickmann

    07/09/2019, 11:32 AM
    Hey all. Maybe you guys can help us out. We are using the ktor apache http client and we get random "Connection reset by peer" exceptions . We only observed this for a particular service that runs behind a load balancer. So the assumption is that if the client gets balanced to another node, it won't have a valid connection anymore. To start with, I don't understand how http clients are meant to be used in ktor. Our ktor backend acts as a gateway between a frontend and multiple backend services. So the question is: should we recreate a http client instance for every request and then immediately close the client, as it is shown in the ktor examples? https://ktor.io/clients/http-client.html Or should we initialize the client once, say as part of the initialization of an object, and then reuse it for all requests? What happens when a http client is instantiated? I once forgot to close a client and it seemed on every instance creation it spawned 10 new threads, which indicates to me that it is meant for reuse?
    t
    • 2
    • 3
  • j

    Jan Stoltman

    07/11/2019, 8:23 AM
    Hey guys, I have a question. Is there a way in Ktor to limit identical GET requests to the same endpoint from the client's side? Eg. if my client app makes a single GET request to the
    xyz
    endpoint and then at almost the same time makes another two to the same endpoint with the same method/payload, I would like to let only the first one to actually reach the server and deliver response to all 3 client requests. Is there any way to achieve this with ktor?
    t
    • 2
    • 7
  • s

    sonofblip

    07/11/2019, 3:35 PM
    Hi! I apologize if this has been asked before, but is there a good canonical way in ktor to map query params from a GET request to a model class in kotlin? Here’s an example:
    application.routing {
        get("myroute") {
            val queryParams = call.parameters // the query params from the call
            val paramsMap: Map<String, String> = queryParams.toMap().mapValues { it.value.first() } // I can put them in a map of string fairly easily
            val instanceOfMyClass: MyClass = MyClass(paramsMap["val1"], paramsMap["val2"], etc...) // I have to map them to my class manually each time :(
            // do stuff with the query params
            call.respondJson("your response here.")
        }
    }
    To be clear, the equivalent of what I’m looking for in spring would look like:
    import javax.validation.Valid;
    
    @RequestMapping(value = "/getItem", method = RequestMethod.GET)
    public ServiceRequest<List<SomeModel>> getClaimStatuses(@Valid RequestParamsModel model) {
        // ...
    }
    and in JAX-RS it’d use
    @BeanParam
    https://dennis-xlc.gitbooks.io/restful-java-with-jax-rs-2-0-2rd-edition/en/part1/chapter5/bean_param.html
    d
    t
    +2
    • 5
    • 13
  • m

    mbonnin

    07/13/2019, 12:03 PM
    And 2. Is it possible to gzip compress requests ? (Looks like response decompression is supported but not request compression)
    • 1
    • 1
  • d

    detouched

    07/15/2019, 2:10 AM
    Hello there, I'm trying to create a custom feature for Ktor Server that validates request signature and needs to fully read request content. I'm wondering what's the right pipeline and phase to intercept here. Currently intercepting
    ApplicationReceivePipeline.Before
    – this kinda works, but in case of invalid signature after I send 401 back and call
    finish()
    I still get
    CannotTransformContentToTypeException
    in the related target route. I understand that it's what triggers receive pipeline, so this setup is obviously wrong. Seeking for the right solution, appreciate any help.
    a
    • 2
    • 2
  • c

    coderskitchen

    07/15/2019, 7:32 PM
    Hi there 🙂 I'm currently writing a custom feature for ktor, that wraps exceptions in a RFC7807 style problem+json object (https://github.com/tyntec/ktor-problem). Even if it is in early stage, I wanted to ask if someone would be interested in doing a review / give hints what can be improved. Many thanks in advance
    ✔️ 1
    a
    • 2
    • 2
  • a

    Antanas A.

    07/17/2019, 2:58 PM
    Hello, I'm using ktor 1.2.2 and using ktor web socket client in Android, all seems ok, but if user enters airplane mode or disables internet it gets app crash with exception:
    java.io.IOException: Software caused connection abort
            at sun.nio.ch.FileDispatcherImpl.read0(Native Method)
            at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:43)
            at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:223)
            at sun.nio.ch.IOUtil.read(IOUtil.java:192)
            at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:382)
            at kotlinx.io.nio.ChannelsKt.read(Channels.kt:117)
            at io.ktor.network.sockets.CIOReaderKt$attachForReadingDirectImpl$1$1.invokeSuspend(CIOReader.kt:75)
            at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
            at kotlinx.coroutines.ResumeModeKt.resumeMode(ResumeMode.kt:67)
            at kotlinx.coroutines.DispatchedKt.resume(Dispatched.kt:309)
            at kotlinx.coroutines.DispatchedKt.resumeUnconfined(Dispatched.kt:49)
            at kotlinx.coroutines.DispatchedKt.dispatch(Dispatched.kt:295)
            at kotlinx.coroutines.CancellableContinuationImpl.dispatchResume(CancellableContinuationImpl.kt:250)
            at kotlinx.coroutines.CancellableContinuationImpl.resumeImpl(CancellableContinuationImpl.kt:260)
            at kotlinx.coroutines.CancellableContinuationImpl.resumeWith(CancellableContinuationImpl.kt:189)
            at io.ktor.network.selector.SelectorManagerSupport.handleSelectedKey(SelectorManagerSupport.kt:83)
            at io.ktor.network.selector.SelectorManagerSupport.handleSelectedKeys(SelectorManagerSupport.kt:63)
            at io.ktor.network.selector.ActorSelectorManager.process(ActorSelectorManager.kt:74)
            at io.ktor.network.selector.ActorSelectorManager$process$1.invokeSuspend(ActorSelectorManager.kt)
            at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    I've added everythere try catch blocks but still this exception was not caught anywhere. Maybe anyone can help me how to overcome this?
    m
    • 2
    • 2
  • p

    pardom

    07/17/2019, 3:52 PM
    Is it possible to mix
    websocket
    routes and
    http
    routes? I get a
    500
    hitting an
    http
    route when a websocket route is open. I thought it would suspend.
    g
    • 2
    • 4
  • o

    Ovsyannikov Alexey

    07/18/2019, 10:57 AM
    Hello, I have tried to use ktor auth, but faced problem with launching simple example. How can it be solved? If it is important: I am using OpenJDK 12 and in other project there is not problems with
    ktor client
    and
    ktor cio
    v
    • 2
    • 8
  • q

    quiqua

    07/18/2019, 2:05 PM
    For a
    HttpClient
    provided by ktor - can it be used as a singleton or should new requests made with different instances ?
    e
    • 2
    • 6
Powered by Linen
Title
q

quiqua

07/18/2019, 2:05 PM
For a
HttpClient
provided by ktor - can it be used as a singleton or should new requests made with different instances ?
We currently have a
kodein
configuration to use a singleton
bind<HttpClient>() with singleton { HttpClient(OkHttp) }
, but are also confronted with a memory leak in our app and I currently suspect the HttpClient 🤔
e

e5l

07/18/2019, 2:11 PM
Hi @quiqua, you can create multiple clients if you want to, but you also can use single
q

quiqua

07/18/2019, 2:13 PM
Alright, then it might be a different issue within the project 🙂 Thanks for the quick heads up.
is the
HttpResponse.close
method called automatically or is it my responsibility to do so at some part of the code execution?
e

e5l

07/18/2019, 2:28 PM
You should call
close
manually or with
response.use { }
method
q

quiqua

07/18/2019, 2:30 PM
thanks 🙂
View count: 2