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

    Tim Malseed

    01/17/2020, 1:36 PM
    I’m using Exposed, and I’m having trouble retrieving results from a select query..
    s
    k
    d
    • 4
    • 27
  • m

    mantono

    01/18/2020, 5:30 PM
    If I get a call with destination http://127.0.0.1:8888/login/callback#access_token=xxz - how do I read
    access_token
    in ktor? I cannot seem to find a function that does it for me 🤔 At least not on
    call.request
    ....
    v
    • 2
    • 4
  • m

    Martins Joseph

    01/18/2020, 9:20 PM
    I am having issues with activating auto reload
    j
    • 2
    • 6
  • n

    nrobi

    01/21/2020, 7:45 AM
    Anyone having the same problem?
    Unable to resolve dependency for ':common@debug/compileClasspath': Could not resolve io.ktor:ktor-client-ios:1.3.0.
    e
    • 2
    • 8
  • g

    gotoOla

    01/21/2020, 9:14 AM
    does anyone use any swagger/openapi implementation where the documentation is derived from their ktor code? I know I looked it up a year or so ago but at that point it seemed quite early days
    b
    • 2
    • 4
  • b

    bitkid

    01/21/2020, 10:16 AM
    i have a question regarding uploading files using the Apache http client. i do a simple submitFormWithBinaryData (that's the code https://gist.github.com/bitkid/e49c12c63cc4277a6139d3992a16ecb8) in multiple upload coroutines and the weird thing is .. it never gets to the log message. on the server side i see that the server returns status code 409 (conflict) which is correct but it never makes it to that log line and it just blocks in that call. any ideas?
    e
    • 2
    • 45
  • j

    jk2018

    01/22/2020, 9:51 PM
    Question re: Ktor / Client with curl : I'm trying to build a simple client that does an HTTP request .. in IntelliJ. Getting the compiler error: "... cannot find -lcurl" . What's the easiest way to add this dependency ? Can I even do this in IntelliJ or do I need CLion to compile lcurl?
    e
    • 2
    • 12
  • a

    Alexander Weickmann

    01/22/2020, 10:10 PM
    Hey all, any road map for java >= 9 support? This is slowly starting to become a real issue for us. If not even an official word is getting out that this is getting prioritized this year, then most likely 2 of our teams will be forced to switch to another framework .. which would be a shame since we really like ktor ❤️
    r
    • 2
    • 6
  • b

    bitkid

    01/23/2020, 9:28 AM
    hey! any ideas why idea complains about this code when reading multipart (BlockingMethodInNonBlockingContext)? it seems it's ok to do
    part.streamProvider().reader() // do some stuff with the reader
    but it's not ok to do
    GZIPInputStream(part.streamProvider().buffered()).reader()
    my expectation was that wrapping a stream should not be blocking or?
    c
    • 2
    • 1
  • h

    hdarritchon

    01/24/2020, 2:41 PM
    Hi, I’d like to custom my Ktor response pipeline to add 2 headers, one for the time it takes for the app to process the request and send the response and another one to handle etag response header transparently. I tried to create a Feature, try some interceptors, ... but I failed to find a phase where the response is processed but I am still able to add headers to the response. Often I get this error :
    java.lang.UnsupportedOperationException: Headers can no longer be set because response was already completed
    . I suppose it’s too late. So I was wandering if it is possible to have a phase where the Request is processed, the response is ready but I’m still able to modify the response to add some headers.
    r
    c
    • 3
    • 3
  • l

    Leon K

    01/24/2020, 4:33 PM
    hey! when creating my fat-jar and then docker-images the way the documentation suggests, i'm also including the full application.conf and all resources in my fat-jar. Is there a way to build my server such that i can mount these config-files in a volume, making them accessible and changable without needing to rebuild the server?
    d
    l
    • 3
    • 8
  • s

    snowe

    01/25/2020, 3:51 AM
    simple question. With ktor-oauth, does HttpClient need to be
    Apache
    ? It doesn't seem to want to accept
    Tomcat
    , but I don't want to run two applications servers just to use oauth.
    t
    m
    • 3
    • 13
  • r

    Rodrigo Silva

    01/25/2020, 5:50 PM
    Hello all. How do i format the date using jackson? I tried :
    install(ContentNegotiation) {
        jackson {
            registerModule(JodaModule())
            dateFormat = DateFormat.getDateInstance(3)
            enable(SerializationFeature.INDENT_OUTPUT)
        }
    }
    but my json was like:
    "date": {
          "year": 2020,
          "month": "JANUARY",
          "monthValue": 1,
          "dayOfMonth": 25,
          "chronology": {
            "id": "ISO",
            "calendarType": "iso8601"
          },
    And what I wanted
    "date": "2020/01/25"
    k
    • 2
    • 1
  • c

    cesards

    01/27/2020, 4:39 AM
    Hi everyone! I’m trying to build a small REST API with Ktor and I’m trying to connect to a Google Cloud PostgreSQL After almost an entire day trying different things, I didn’t get it working At first, I thought the problem might be related to not using the right url and driver when connecting the Database with the Expose library (I tried different urls and none of them worked). Since Google has samples relying on Hikari to get a connection pool working, I also tried it with no luck. I think the problem might be related to the fact that I’m deploying the Ktor backend using app engine (via app engine gradle plugin), which relies on:
    <servlet-class>io.ktor.server.servlet.ServletApplicationEngine</servlet-class>
    and I think the Driver used by Cloud PostgreSQL might be different than the one needed? I’m not sure if what I’m saying makes sense but I’m getting crazy trying to make this work. Has anyone deployed Ktor on Google Cloud that also connects to an external database? Is it recommended? I guess the other alternative is using h2 and have a local database, but then looking at data I guess it becomes more complicated, doesn’t it? I’m quite new to the backend world, so any suggestions are more than appreciated.
    c
    j
    • 3
    • 4
  • c

    cy

    01/27/2020, 9:55 AM
    ❓ Does anybody invoke client's
    HttpSend.intercept
    function? We are going to break it's signature (only source compatibility, not binary) in 1.3.1 so want to know if anybody cares?
    r
    • 2
    • 2
  • g

    gotoOla

    01/27/2020, 1:40 PM
    Has anyone here used the ktorClient together with mockk to verify? What I am doing right now is to setup a 200-always mock:
    private fun createMockedHttpClient(): HttpClient {
        return HttpClient(MockEngine) {
            engine {
                addHandler { request ->
                    respond("hej")
                }
            }
        }
    }
    and then I try to coVerify (a function from mockk) that calls were made towards the mock
    coVerify(exactly = 10) { <http://httpClient.post|httpClient.post>("<http://localhost:8081>") }
    but what I get is
    Missing calls inside verify { ... } block.
    • 1
    • 1
  • k

    Kris Wong

    01/27/2020, 2:15 PM
    I installed the Logging feature on an
    HttpClient
    with
    LogLevel.ALL
    , and it only seems to log requests, not responses, which doesn't make sense to me. is that the intended behavior?
    • 1
    • 2
  • k

    Kris Wong

    01/27/2020, 4:02 PM
    HttpResponse.readText
    is causing an exception with K/N: mutation attempt of frozen kotlin.collections.HashMap@3253bdb8
    • 1
    • 1
  • b

    bitkid

    01/27/2020, 4:14 PM
    is it possible to use
    call.respondTextWriter
    together with http content compression? so basically that it writes back a chunked gzip stream.
    • 1
    • 3
  • l

    Luke Rohde

    01/27/2020, 6:59 PM
    it’s a bit annoying though that it has to be inserted in this way, since the AuthenticatePhase only exists within routes of the application that are authenticated, so you end up repeating yourself
    h
    • 2
    • 12
  • s

    snowe

    01/27/2020, 9:26 PM
    How does authentication work with Ktor? I've set up oauth, but whenever I navigate to a protected route (protected with
    authenticate {}
    , it doesn't redirect me to the login page. I can't find any resources that indicate how you're supposed to accomplish this though.
    h
    • 2
    • 2
  • f

    fcosta

    01/27/2020, 10:46 PM
    Hey guys.. what’s the state of iOS websockets?
    e
    • 2
    • 1
  • d

    Dario Pellegrini

    01/28/2020, 11:48 AM
    Do you know if is there any bandwith throttling system in ktor, in order to limit bandwidth from the client?
    m
    • 2
    • 1
  • s

    sonofblip

    01/28/2020, 5:40 PM
    anyone know anything about route interception in ktor? Can I intercept a route, modify the request, then sent it on its merry way down to the normal routing coroutine?
    e
    • 2
    • 1
  • k

    Kris Wong

    01/28/2020, 7:24 PM
    it looks like
    TestEngine
    doesn't handle any HTTP. i'd like to have a super simple/lightweight embedded server for test purposes, to test my platform-specific HTTP clients. is there a recommended way to do this?
    n
    • 2
    • 3
  • c

    Cristián Arenas

    01/28/2020, 11:41 PM
    How can I set a timeout for a specific request? A colleague of mine tried doing the request inside kotlinx.coroutine’s
    withTimeout
    function, but all hell broke loose. 😅
    r
    • 2
    • 3
  • m

    MrPowerGamerBR

    01/29/2020, 2:19 AM
    For some reason sometimes my ktor http client (using Apache) gets stuck (no matter what request I do, it just timeouts) after a while the pending requests are executed. What I'm thinking it is happening is that it is queueing requests instead of executing them... how can I change how many parallel requests can I execute with the same client instance? (unless if I should create a new http client every time... but I don't think this is needed, right?)
    e
    b
    • 3
    • 14
  • g

    gotoOla

    01/29/2020, 9:03 AM
    @e5l I stumbled on a file where you have done some work https://github.com/ktorio/ktor/blob/master/ktor-client/ktor-client-mock/jvm/test/io/ktor/client/tests/mock/MockEngineExtendedTests.kt 🙂 Do you happen to know if the MockEngine is thread safe? I'm seeing some flaky test where I fire of 10 concurrent requests towards the a mocked httpClient
    mockEngineConfig.addHandler { request ->
        respondOk()
    }
    ktorMockEngine = MockEngine(mockEngineConfig)
    val httpClient = HttpClient(ktorMockEngine)
    
    // fire off 10 concurrent requests, ackording to the logs all of them are sent but I end up with
    Assertions.assertThat(ktorMockEngine.requestHistory.size).isEqualTo(10)
    Expecting:
     <8>
    to be equal to:
     <10>
    • 1
    • 1
  • s

    Sourabh Rawat

    01/29/2020, 6:30 PM
    getting
    xcrun: error: unable to find utility "xcodebuild", not a developer tool or in PATH
    while running
    gradle clean check.
    What am I missing? I want to run tests in
    ktor-client-tests
    .
    s
    • 2
    • 2
  • y

    Yyq2008

    01/30/2020, 9:29 AM
    post("/oauth/token") {
        val gt = call.parameters.get("grant_type") ?: call.respond(HttpStatusCode.BadRequest, mapOf("error" to "no grant_type specified"));
        call.respondText(call.request.headers["Authorization"] ?: "No header")
    }
    how to response and return to avoid run the second response?
    s
    d
    • 3
    • 5
Powered by Linen
Title
y

Yyq2008

01/30/2020, 9:29 AM
post("/oauth/token") {
    val gt = call.parameters.get("grant_type") ?: call.respond(HttpStatusCode.BadRequest, mapOf("error" to "no grant_type specified"));
    call.respondText(call.request.headers["Authorization"] ?: "No header")
}
how to response and return to avoid run the second response?
s

spand

01/30/2020, 10:44 AM
Something like this?
post("/oauth/token") {
param("grant_type") {
handle {
    val gt = call.parameters.get("grant_type")!! call.respond(HttpStatusCode.BadRequest, mapOf("error" to "no grant_type specified"));
    call.respondText(call.request.headers["Authorization"] ?: "No header")
}
}
}
y

Yyq2008

01/30/2020, 12:27 PM
No, I want just want to finish the response if no grant type found.
Thanks, I found the solution:
post("/oauth/token") {
    val gt = call.parameters.get("grant_type") ?: run {
        call.respond(
            HttpStatusCode.BadRequest,
            mapOf("error" to "no grant_type specified")
        );
        return@post
    }
    call.respondText(call.request.headers["Authorization"] ?: "No header")
}
d

Dico

01/31/2020, 10:52 AM
Why dont you just do
if (gt == null) {...}
?
y

Yyq2008

02/15/2020, 5:26 AM
to avoid if
View count: 9