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

    Dani Morillas

    10/04/2022, 2:58 PM
    Hello! I remember in a previous company where we used Spring we included some swagger plugin (can’t remember the name of the plugin) that would generate automatically the OpenAPI documentation for that project. As far as I remember we had to add an annotation to enable it and some configuration like the package to inspect and get the endpoints. Is there any similar for ktor? Some plugin to generate a page with the OpenAPI documentation for all the endpoints defined in a service?
    r
    r
    • 3
    • 5
  • j

    João Gabriel Zó

    10/04/2022, 6:25 PM
    the
    BadRequestException
    from Ktor just gives me “Illegal Input” and doesn’t actually say whats wrong with the request. Is there a way to improve it?
    s
    s
    • 3
    • 7
  • a

    Alexander Weickmann

    10/04/2022, 8:42 PM
    Hey all, the ktor-client-logging is producing a separate log lines for request, response, method and url. I'd prefer having a single log line, like: RESPONSE: 200 OK FROM GET <URL> Is there a way to configure the logging plugin so I could achieve that?
    a
    • 2
    • 1
  • s

    suresh

    10/05/2022, 12:46 AM
    Hi, has anybody seen this error when building native image containing ktor client ? I have tried different options by specific the offending class at build and runtime, but still having the same error.
    Fatal error: com.oracle.graal.pointsto.util.AnalysisError$ParsingError: Error encountered while parsing io.ktor.client.engine.cio.CIOEngine.<init>(io.ktor.client.engine.cio.CIOEngineConfig)
    Parsing context:
       at io.ktor.client.engine.cio.CIOEngine.<init>(CIOEngine.kt)
       at io.ktor.client.engine.cio.CIO.create(CIOCommon.kt:35)
       at io.ktor.client.HttpClientKt.HttpClient(HttpClient.kt:41)
    • 1
    • 2
  • z

    zt

    10/05/2022, 1:43 AM
    im trying to make a kotlin multiplatform library that wraps an API using ktor, is there any recommended architecture I could use for this?
  • b

    benkuly

    10/05/2022, 12:48 PM
    Is it possible to handle CONNECT-requests with ktor? I want to implement a "smart" proxy, which intercepts outgoing requests by analysing the request itself. I want to use a CA and generate TLS certs on the fly to keep the transport encryption.
  • m

    Matthew Murray

    10/05/2022, 9:06 PM
    👋 Hi, does anyone know anything about how Ktor syncs with cookies on iOS side? running into an issue where its not picking up new cookies I set https://stackoverflow.com/questions/73966313/ios-shared-cookie-storage-not-synced-with-ktor-client
    a
    • 2
    • 11
  • t

    Thomas

    10/06/2022, 11:16 AM
    Can someone from the Ktor team please look into the following issue? https://youtrack.jetbrains.com/issue/KTOR-2914
    a
    • 2
    • 1
  • p

    PHondogo

    10/06/2022, 2:41 PM
    Hello! Why Socket::close or Socket::dispose are not suspend functions?
    a
    • 2
    • 6
  • s

    spierce7

    10/06/2022, 7:03 PM
    I’ve been using unix domain sockets in mac with ktor. It’s been great. I thought windows had unix domain sockets as well, however I haven’t been able to get them to work on windows with ktor. How would I get a similar effect on windows?
    b
    a
    • 3
    • 3
  • t

    Trey

    10/06/2022, 7:49 PM
    Can somebody point me to a sample project that authenticates users? I'm trying to understand the recommended pattern for using ktor with dependency injection. I have been just injecting the httpClient where needed, but when a user logs out and then back in as another user, the auth tokens in the httpClient bearerAuthProvider need to be invalidated. I don't see an easy way to force that invalidation with my setup.
    a
    • 2
    • 2
  • s

    spierce7

    10/06/2022, 10:31 PM
    @Big Chungus Sure. I’m using a unix domain socket to communicate between a kotlin native binary and a Compose JVM application, to access the camera feed and send it. I’ve found the release version of a kotlin-native application to be more than fast enough on old, low-end hardware, at least on mac. Code posted in thread.
    b
    • 2
    • 8
  • j

    Justin (Midas) Gilman

    10/07/2022, 7:58 PM
    Hi #ktor! I am using Authentication with JWT, and I'm trying to report better errors in certain cases. If the JWT token included in the
    Authorization
    header isn't a valid JWT token (misconfigured environment might pass
    null
    or empty string) I want to log an error on the server "Missing or Invalid JWT Token". Is there a place I can do this?
    • 1
    • 1
  • g

    Gaurav Tyagi

    10/08/2022, 9:04 AM
    Hi how to refresh custom authorisation token if getting 401 error code. header("Authorization","Authorization token value")
    a
    • 2
    • 2
  • d

    dongock.kim

    10/10/2022, 6:59 AM
    Hi, everyone. I wanna know what the problem is. I have a
    ServerSocket
    and a
    Socket
    accepted to this server socket with
    keepAlive = true
    option. If the client device connected to this
    Socket
    lost internet connection, this
    Socket
    can’t know this socket is broken. Even though I have a
    keepAlive
    option, can somebody helps me what’s the problem? Sever
    val serverSocket = aSocket(SelectorManager(<http://Dispatchers.IO|Dispatchers.IO>)).tcp().bind(host, port)
    val socket = serverSocket.accept()
    Client
    val socket = aSocket(ActorSelectorManager(<http://Dispatchers.IO|Dispatchers.IO>).tcp().connect(host, port) { keepAlive = true }
    e
    • 2
    • 6
  • p

    PHondogo

    10/10/2022, 10:07 AM
    Hello! In io.ktor.network.selector.SelectorManager there is 'dispatcher: CoroutineContext' as parameter. In example Dispathers.IO is passed. What if I pass Dispathers.DEFAULT? Does it mean that for choosing right dispatcher I need to know internals if it blocking or not? Why is it not hidden in internal implementation of SelectorManager?
    d
    a
    • 3
    • 7
  • e

    Eivind

    10/10/2022, 10:32 AM
    Hi, I got a problem whit the Http client. After the new config the plugin is no longer on the client. I havent found any example on Installing it whit a intercept, as installs loks to get find pass the config block. Any one know how to get this to work or do i need to write a installable plugin?
    aHttpClient.plugin(HttpSend).intercept { request -> .... }
    val newHttpClinet = aHttpClient.config { .... }
    a
    • 2
    • 1
  • j

    Julius

    10/12/2022, 12:36 PM
    Hey! Is there a way to not set any headers with ktor client? I have the following code and it automatically sets the content-type header when run in the browser:
    val uploadHttpClient = HttpClient()
            val uploadResponse = uploadHttpClient.put(cloudflarePresignedPutUrl) {
                setBody(mediaFile)
            }
    Sadly there's a bug in cloudflare's r2 that makes cors break when you set any header
    a
    • 2
    • 3
  • p

    Pavel Kunyavskiy [JB]

    10/12/2022, 8:42 PM
    Hi! I have a sever application, which has some mission-critical background tasks. If they are failed, the best you can do, is just to stop application. What is good coroutine context to start them? I'm trying to start in Application, but it's a SupervisorJob, so it doesn't propagate failures. I can do something like add an inner scope inside Application with handler doing a
    System.exit()
    , but that's looks too rude way to stop. Maybe you have some better way to do that?
    p
    s
    e
    • 4
    • 7
  • j

    João Gabriel Zó

    10/13/2022, 12:28 PM
    What’s the best way to get a singleton HttpClient? Couldn’t figure out how to just put it inside an Object
    a
    a
    m
    • 4
    • 5
  • p

    PoisonedYouth

    10/13/2022, 5:57 PM
    Is there a possibility to cancel a respondOutputStream call in case an error occurs during writing to the outputstream and respond with a specified http status code? Currently the request just gives me an empty response but with sucess status 200
    call.respondOutputStream { 
         fileHandler.download(this)
    }
    I could only find following question on stackoverflow: https://stackoverflow.com/questions/69408466/how-to-propagate-error-in-outputstream-to-client-when-using-ktor
    j
    • 2
    • 2
  • z

    zt

    10/14/2022, 6:26 AM
    I'm working with an API that returns several items per page and to get more you have to do another request with the next page number. Is there a way I could simplify this so it just provides a flow that automatically makes the requests until it runs out of items?
    s
    • 2
    • 1
  • s

    simon.vergauwen

    10/14/2022, 10:36 AM
    Hey everyone 👋, I was playing with Ktor to build a native server and was running it locally on my
    macArm64
    (have not tried linux yet), but when I call
    engine.stop(5000, 10_000)
    on the
    ApplicationEngine
    it keeps the port occupied, and I get following exception when I try to re-run the server. I'm running the hello world example from the samples repo. Any ideas on how to fix this? Or is this a bug? I couldn't find any bug report on YouTrack, but happy to add one if needed ☺️
    Uncaught Kotlin exception: io.ktor.utils.io.errors.PosixException.AddressAlreadyInUseException: EADDRINUSE (48): Address already in use
    r
    h
    +2
    • 5
    • 14
  • b

    benkuly

    10/14/2022, 3:05 PM
    Is there any OIDC implementation for ktor client (multiplatform) or are there any plans to support it in ktor?
    a
    • 2
    • 2
  • i

    Ivan Kupriyanov

    10/14/2022, 6:16 PM
    Hi! I got an odd issue in https://github.com/JetBrains/lets-plot library after upgrading
    ktor.client
    from
    1.6.8
    to
    2.1.1
    - nothing happens when I try to open a websocket. There are no errors, no logs with
    engine { this@HttpClient.developmentMode = true }
    , even no connection in devTools/Network tab. Same issue in Chrome and Firefox. It's hard to provide minimal reproducible example as I'm talking about interactive maps, and this issue (causes tiles to not load) happens only in https://datalore.jetbrains.com/ and works well in kaggle, colab, jupyter, deepnote, nextjournal. The last line to be executed is: https://github.com/JetBrains/lets-plot/blob/master/gis/src/commonMain/kotlin/jetbrains/gis/tileprotocol/socket/TileWebSocket.kt#L24 Code inside this receiver never runs in datalore. I understand that it is very difficult to diagnose a problem without an example, but even a tiny tip what have been changed in
    2.0.0
    and what can cause such behaviour can help. Thanks in advance. Issue: https://youtrack.jetbrains.com/issue/KTOR-4993
  • c

    coroutinedispatcher

    10/16/2022, 8:00 AM
    Any good websocket resource I can read for Ktor except official docs?
    b
    • 2
    • 2
  • t

    Tomislav Hofman

    10/16/2022, 3:39 PM
    How can we save static content outside jar and server that same content to the client? I realize that this is potentially loaded question, so I'd appreciate any guidance towards right material to read.
    a
    • 2
    • 4
  • k

    Kristian Nedrevold

    10/16/2022, 6:54 PM
    Trying to install the Resources plugin for type-safe routing. However I can't seem to install it. Fresh project created with intellij ktor 2.1.2. Trying to install the plugin results with Application.kt: (21, 9): Not enough information to infer type variable B
    a
    • 2
    • 2
  • l

    Lukas S

    10/16/2022, 7:08 PM
    Hi, i'm running into an issue where the oauth authentication does not redirect to the authorization link when there is another authentication configured alongside it. The idea is that I want the block to first check if the user has a session on the web, and then if so use oauth to connect to the service its trying to access Here is my code
    routing {
        authenticate(UserAuthentication.USER_SESSION) {
            authenticate(OAUTH_NAME) {
                ebayLogin()
            }
        }
    }
    
    authentication {
        oauth(OAUTH_NAME) {
            urlProvider = { System.getenv("EBAY_REDIRECT_URI") }
            providerLookup = {
                OAuthServerSettings.OAuth2ServerSettings(
                    name = "eBay",
                    authorizeUrl = "<https://auth.ebay.com/oauth2/authorize>",
                    accessTokenUrl = "<https://api.ebay.com/identity/v1/oauth2/token>",
                    requestMethod = <http://HttpMethod.Post|HttpMethod.Post>,
                    clientId = System.getenv("EBAY_CLIENT_ID"),
                    clientSecret = System.getenv("EBAY_CLIENT_SECRET"),
                    defaultScopes = listOf(
                        "<https://api.ebay.com/oauth/api_scope>",
                    ),
                    accessTokenRequiresBasicAuth = true,
                    extraTokenParameters = listOf()
                )
            }
            client = HttpClient(CIO) {
                install(ContentNegotiation) {
                    json()
                }
            }
        }
    }
    fun Route.ebayLogin() {
        get("/ebay/login") {
            // redirects to 'authorizeUrl' automatically
        }
    
        get("/ebay/login/callback") {
            val principal = call.principal<OAuthAccessTokenResponse.OAuth2>()
            // TODO: save token to database
            call.respondRedirect("/ebay")
        }
    }
    Thanks!
    a
    • 2
    • 1
  • b

    benkuly

    10/17/2022, 6:33 AM
    How can I install addional plugins within
    createRouteScopedPlugin
    ?
    a
    • 2
    • 2
Powered by Linen
Title
b

benkuly

10/17/2022, 6:33 AM
How can I install addional plugins within
createRouteScopedPlugin
?
a

Aleksei Tirman [JB]

10/17/2022, 1:12 PM
So do you want to install additional plugins into a route?
b

benkuly

10/17/2022, 1:18 PM
Yes. Just with a plugin. I found a workaround by doing it with a simple extension function.
View count: 28