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

    Andreas Scheja

    07/29/2022, 4:06 PM
    I was wondering: Is there any plan to (properly) support accessing things like the peer principal of a
    SSLSession
    after we got the ability to configure mutual tls with ktor 2.0? I've found a workaround, but I'm not sure if the involved APIs are stable enough to rely on them so it doesn't break during a random update...
    intercept(ApplicationCallPipeline.Call) {
        val nettyCall = (call.attributes[baseApplicationResponse.EngineRersponseAttributeKey].call) as NettyApplicationCall
        val sslHandler = nettyCall.context.pipeline().get(SslHandler::class.java)
        try {
            val peerPrincipal = sslHandler.engine().session.peerPrincipal as X500Principal
            call.attributes.put(PeerPrincipalKey, peerPrincipal)
            proceed()
        catch (e: SSLPeerUnverifiedException) {
            return@intercept call.respondText("No client certificate provided", status = HttpStatusCode.BadRequest)
        }
    }
    I've tried it the other way round too (adding a custom handler to netty), but I couldn't find a way to inject the principal into the ktor call.
    a
    • 2
    • 2
  • j

    Joe Altidore

    08/01/2022, 8:54 AM
    Hello, I am new to ktor. I have built a restful API service with ktor and is working well when run locally but after deploying to Heroku, I get the error below and I am lost on how to resolve the issue.
    Error: A JNI error has occurred, please check your installation and try again
    2022-08-01T00:00:03.922254+00:00 app[web.1]: Exception in thread "main" java.lang.UnsupportedClassVersionError: com/impact/ApplicationKt has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
    2022-08-01T00:00:03.922349+00:00 app[web.1]: at java.lang.ClassLoader.defineClass1(Native Method)
    2022-08-01T00:00:03.922384+00:00 app[web.1]: at java.lang.ClassLoader.defineClass(ClassLoader.java:756)
    2022-08-01T00:00:03.922539+00:00 app[web.1]: at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    2022-08-01T00:00:03.922575+00:00 app[web.1]: at <http://java.net|java.net>.URLClassLoader.defineClass(URLClassLoader.java:473)
    2022-08-01T00:00:03.922623+00:00 app[web.1]: at <http://java.net|java.net>.URLClassLoader.access$100(URLClassLoader.java:74)
    2022-08-01T00:00:03.922664+00:00 app[web.1]: at <http://java.net|java.net>.URLClassLoader$1.run(URLClassLoader.java:369)
    2022-08-01T00:00:03.922700+00:00 app[web.1]: at <http://java.net|java.net>.URLClassLoader$1.run(URLClassLoader.java:363)
    2022-08-01T00:00:03.922740+00:00 app[web.1]: at java.security.AccessController.doPrivileged(Native Method)
    2022-08-01T00:00:03.922774+00:00 app[web.1]: at <http://java.net|java.net>.URLClassLoader.findClass(URLClassLoader.java:362)
    2022-08-01T00:00:03.922808+00:00 app[web.1]: at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
    2022-08-01T00:00:03.922842+00:00 app[web.1]: at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
    2022-08-01T00:00:03.922883+00:00 app[web.1]: at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
    2022-08-01T00:00:03.922922+00:00 app[web.1]: at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:601)
    a
    • 2
    • 2
  • j

    Jerry Yion

    08/02/2022, 1:46 AM
    or one client per request
  • r

    Rekha

    08/01/2022, 7:05 AM
    hi, i am a newbie to ktor. We are using kotr for android and trying to write the unit test for ktor network call with okhttp. how to mock the client enginfe for unit test? Thanks
    a
    • 2
    • 3
  • r

    Rohan Maity

    08/02/2022, 7:50 AM
    hi I am trying to do a redirect like this (using
    ktor-server-resources
    )
    suspend fun ApplicationCall.redirect(resource: Any) {
        val path = application.href(resource)
        respondRedirect(path)
    }
    And here is the file where redirect is used
    const val PHRASES = "/phrases"
    
    @Serializable
    @Resource(PHRASES)
    class Phrases
    
    fun Route.phrases(db: Repository) {
        authenticate("auth") {
            get<Phrases> {
                val user = call.authentication.principal as User
                val phrases = db.phrases().toTypedArray()
                call.respond(
                    FreeMarkerContent(
                        "phrases.ftl",
                        mapOf("phrases" to phrases, "displayName" to user.displayName)
                    )
                )
            }
    
            post<Phrases> {
                val params = call.receiveParameters()
                val action = params["action"] ?: throw IllegalArgumentException("Missing parameter: action")
                when(action) {
                    "delete" -> {
                        val id = params["id"] ?: throw IllegalArgumentException("Missing parameter: id")
                        db.remove(id)
                    }
                    "add" -> {
                        val emoji = params["emoji"] ?: throw IllegalArgumentException("Missing parameter: emoji")
                        val phrase = params["phrase"] ?: throw IllegalArgumentException("Missing parameter: phrase")
                        db.add(EmojiPhrase(emoji, phrase))
                    }
                }
                call.redirect(Phrases)
            }
        }
    }
    Initial page loads fine But on redirect it fails on browser console I see this 405 error Now I am not sure what is wrong here Update Actually on further checking its
    POST
    method which is not working I am not sure what's wrong when I simply use
    post(StringUrl)
    it works but when
    server-resources
    it does not work Solved It was the issue of imports, I used the
    <http://server.routing.post|server.routing.post>
    instead of
    <http://server.resources.post|server.resources.post>
    When using
    server-resources
    plugin in ktor, one needs to use HTTP methods from
    server.resources
    package and not from
    server.routing
    package Thanks @Aleksei Tirman [JB] helping me here
    a
    • 2
    • 11
  • m

    mudasar187

    08/01/2022, 11:36 AM
    Hi! Could people help me with hint of why i should use HOCON file or not and make the config in code? I am new to Ktor and i want to hear some experience from people in here 🙂
    a
    a
    • 3
    • 5
  • j

    Jerry Yion

    08/02/2022, 1:45 AM
    Hi there! I am just wondering if it is better to create one http client per app…
    a
    • 2
    • 2
  • o

    Ollis

    08/02/2022, 8:54 AM
    Hi, does anyone have any idea what causes my issue with `kotest`and
    ktor
    ? https://github.com/kotest/kotest/issues/3134
  • m

    mp

    08/02/2022, 9:10 AM
    hi there Does ktor client start log request\responses in single log message? I see deference in runtime - but haven’t seen anything about it in documentation and want clarify it any way - like it 😃
  • p

    ptsiogas

    08/02/2022, 10:39 AM
    Quick question for mobile client: can I have Ktor version 1.6.7 on a library gradle dependency and Ktor version 2.0.3 on my main project? I have tried it and I realised that those two are not working well together (e.g I got java.lang.NoClassDefFoundError: Failed resolution of: Lio/ktor/client/features/ClientRequestException).
    b
    • 2
    • 4
  • l

    Luiz Aguiar

    08/02/2022, 2:46 PM
    Hello folks… I'm giving a try to Ktor again and one aspect that still making me wonder, is related a how "properly" design an application without relying in DI. In Quarkus/Spring, you inject component classes in other components (classes) and don't think much about it, it "just works". What might be a good design approach to use in a Ktor application? Thinking that you might have a couple of "components" that might be used for other components and of course you don't want to have multiple instances spread around. I've been trying to use mostly independent functions, but not sure how "scalable" is this in a big application. Cheers 👋
    f
    p
    • 3
    • 6
  • s

    Sunny

    08/03/2022, 7:04 AM
    Hi guys, post upgrade from 1.6 to 2.0 , running into an error, calls fail with
    Serializer for class 'JsonLiteral' is not found.
    Mark the class as @Serializable or provide the serializer explicitly.HttpClientUtils
    Request is of type
    JsonElement
    . Anyone faced something similar / any leads to look into.
    a
    • 2
    • 5
  • c

    cafonsomota

    08/03/2022, 4:57 PM
    hello all! I’ve noticed something quite odd in a request client side. I’m using ktor in a multiplatform project (android/ios) and I’m sending an object with latitude/longitude (defined as double). If their value is 0.0, they’re not sent, if it’s a different value it is. Anything I might be doing wrong?
    c
    • 2
    • 2
  • f

    FunkyMuse

    08/03/2022, 5:33 PM
    hello guys, does anyone have or had come across a sample project using resilience4j with ktor, especially circuit breaker and rate limiter?
  • c

    Chad Gregory

    08/04/2022, 4:19 PM
    Hey everyone! I'm looking for some help with setting up my ktor client. I am storing the url in a proto datastore and I'm not sure how to get it out of there and into the
    defaultRequest
    block. has anyone else did this? How did you go about it?
    a
    • 2
    • 6
  • m

    MJegorovas

    08/05/2022, 7:02 AM
    How about using defaultRequest ?
    a
    m
    • 3
    • 2
  • r

    Rohde Fischer

    08/05/2022, 12:32 PM
    using KTor sockets on native, how would I go about creating a connection timeout? It seems that the
    socketTimeout
    has no effect, and my socket just keeps waiting, and I cannot find any parameters or settings for that
    a
    • 2
    • 2
  • p

    PoisonedYouth

    08/07/2022, 11:57 AM
    Hey guys, does Ktor support deserialization of form data to object (when using together with Thymeleaf) out of the box or is it necessary to write custom mapper? I installed content negotiation with Jackson but always get an exception (io.ktor.request.CannotTransformToTypeException).
    a
    • 2
    • 4
  • j

    Joe Altidore

    08/07/2022, 2:11 PM
    Hello guys. I am using ktor client and I can't find a way to handle response error.
    a
    • 2
    • 7
  • r

    Rohde Fischer

    08/07/2022, 2:56 PM
    And another curious question about KTor sockets, apart from the apparently non-existing timeout, how am I supposed to test sockets in a reasonable way? Seems the only way I can find is to wrap the static methods in interfaces so, I can inject test-implementations - but I assume that KTor sockets isn't designed in the non-testable fashions that 10+ years of programming experience have shown us to be bad design?
    a
    • 2
    • 3
  • t

    Trey

    08/08/2022, 8:59 PM
    Can somebody point me to an example project or documentation that shows how to use Ktor's websocket functionality in a project? I've seen the simple example for the client/server chat example, but it doesn't seem to be a best practice when you need to send messages across the web socket from your app. Providing the incoming messages to your app as a flow seems ideal, but the sending pattern is what I'm curious about. Especially if the web socket is considered a "source" that is encapsulated inside of a "repository".
  • m

    Marc Knaup

    08/09/2022, 9:28 AM
    Anyone ever had a
    UTF-8 is not supported.
    exception when using
    Url(String)
    constructor on K/JS? I’m trying to figure out why it’s not working 😞 I’m on Cloudflare Workers.
    j
    • 2
    • 4
  • o

    Ovsyannikov Alexey

    08/09/2022, 5:56 PM
    Hello 🙂 Is it possible in ktor clients to change default request url on the fly (after config) ?
    a
    • 2
    • 1
  • n

    Nick Halase

    08/10/2022, 4:27 PM
    Does the ktor-client ContentNegotiation plugin automatically add all registered types to the Accept header? I'm not configuring defaultRequest on my client, but when I make a request with the httpClient.get (i'm also using the Resources plugin for type-safe routing), and I log out the
    call.request.accept()
    value, it's a CSV of content types.
    a
    • 2
    • 2
  • a

    amadeu01

    08/11/2022, 8:46 AM
    hey, do you know good ktor open source projects ?
    s
    • 2
    • 2
  • d

    Didier Villevalois

    08/11/2022, 8:54 AM
    [ktor-network/ktor-io question] It seems that
    io.ktor.utils.io.ByteBufferChannel
    reuses the`kotlinx.coroutines.channels.ClosedReceiveChannelException` exception to signal all its EOF errors. It is quite confusing and hard to
    catch
    when you use both `Channel`s and `ByteBufferChannel`s in the same coroutines. Shouldn't
    ByteBufferChannel
    use a custom exception inheriting from
    IOException
    ? Should I open a YT issue?
    a
    • 2
    • 6
  • m

    Mati Galli

    08/11/2022, 7:02 PM
    Hi guys! I’m migrating my project to ktor 2.0 with kotlin 1.7 and I’m having troubles with a
    test task
    configured on my
    build.gradle.kts
    . It seems that the tests are passing, but an exception is thrown anyway
    a
    • 2
    • 5
  • z

    zt

    08/11/2022, 7:34 PM
    I'm using ktor 2.0.3 in my Android app with the CIO engine. I've found that in the emulator I get a crash when trying to make a request to
    <https://youtube.com>
    but not when I make a request to another URL such as
    <https://github.com>
    On an actual phone this crash doesn't happen. The code im using is this in my MainActivity
    HttpClient(CIO).get("<https://youtube.com/>")
    The crash
    Caused by: java.net.SocketException: Network is unreachable
    	at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
    	at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:762)
    	at io.ktor.network.sockets.SocketImpl.connect$ktor_network(SocketImpl.kt:50)
    	at io.ktor.network.sockets.SocketImpl$connect$1.invokeSuspend(Unknown Source:15)
    	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
    	at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:42)
    	at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95)
    	at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
    	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:749)
    	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
    	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
    a
    • 2
    • 9
  • l

    Lucas

    08/12/2022, 3:34 AM
    Im using ktor client to call this API which needs basic authorization. My application has credentials for several users of this API, and i need to change the auth header for each different user. Initially i thought about using the same HttpClient and change the header on each request, but i didnt find a way to do so (using the basic auth plugin). Should i be using different clients for each user? I feel like this could be expensive and if i could reuse the clients it would be much better. Or should i just be setting the header manually on each request, and stop using the basic auth plugin?
    a
    h
    • 3
    • 4
  • h

    hhariri

    08/12/2022, 9:19 AM
    📣 Ktor 2.1.0 with a bunch of new tools released! 📣 https://blog.jetbrains.com/ktor/2022/08/12/ktor-2-1-0-released-and-it-comes-with-goodies/
Powered by Linen
Title
h

hhariri

08/12/2022, 9:19 AM
📣 Ktor 2.1.0 with a bunch of new tools released! 📣 https://blog.jetbrains.com/ktor/2022/08/12/ktor-2-1-0-released-and-it-comes-with-goodies/
View count: 2