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

    Nacho Ruiz Martin

    05/07/2022, 1:11 PM
    Hey people! 👋 Not sure if this would be the best chan for this. Please, let me know otherwise. I’m starting a new project and I’m kind of tired of always doing the same auth-wise: creating User entities, sign-up, login and refresh endpoints, generation of JWT and so on. Do you know if there’s any plug-and-play thingy for Ktor or do you have some experience with any auth as a service option? Thanks! 🙇
    r
    • 2
    • 2
  • r

    Ryan Brink

    05/07/2022, 2:52 PM
    On a route scoped plugin… is there any way to access the full path of the route it is being installed on?
    a
    r
    • 3
    • 9
  • d

    dany giguere

    05/07/2022, 9:16 PM
    Hello everyone. Anyone could help me with a serialization error. I’ve set up an Exposed user in ktor 2:
    object Users: IntIdTable() {
        val username = varchar("username", 128)
        val email = varchar("email", 128)
        val password = varchar("password", 1024)
    }
    
    class User(id: EntityID<Int>, username: String, email: String, password: String): IntEntity(id) {
        companion object : IntEntityClass<User>(Users)
        var username by Users.username
        var email by Users.email
        var password by Users.password
    }
    my serialization plugin is :
    import io.ktor.serialization.kotlinx.json.*
    import io.ktor.server.plugins.*
    import io.ktor.server.application.*
    
    fun Application.configureSerialization() {
        install(ContentNegotiation) {
            json()
        }
    }
    when I call http://0.0.0.0:8080/users, I get
    500: kotlinx.serialization.SerializationException: Serializer for class 'User' is not found.
    Mark the class as @Serializable or provide the serializer explicitly.
    If I try adding @Serializable above the class User, my ide says
    This class does not have a constructor
    Cannot access 'Serializable': it is internal in '<http://kotlin.io|kotlin.io>'
    You can view my project on this branch: https://github.com/danygiguere/ktor-kotlin-example/tree/setting-up-exposed
    e
    a
    • 3
    • 9
  • j

    Joakim Forslund

    05/08/2022, 12:07 PM
    Do we have any way to catch if
    aSocket(selectorManager).tcp().connect
    is not able to connect i.e the hostname is not reachable?
    • 1
    • 1
  • j

    jmfayard

    05/08/2022, 3:45 PM
    Hello, newbie question: ktor is asynchronous and based on coroutines most people seem to use exposed as a database layer with ktor, but exposed ain't asynchronous and coroutines-based. Don't we loose the benefits of coroutines ? Is there a asynchronous database layer ? (I'm using Postgres)
    r
    r
    +3
    • 6
    • 7
  • g

    giso

    05/09/2022, 10:13 AM
    Hi there, I am currently struggling with a behavioural change in Ktor 2 client with the ContentNegotiation plugin. We have a base HttpClient configured with a default json configuration. Then we have a special HttpClient derived from the former with
    .config()
    and a dedicated Json configuration. With Ktor 2 we now end up with a dedicated HttpClient containing 2 json registration, where the default json config is always winning, effectively disabling the dedicated Json configuration. Is there a way to remove the first registration? Or is this maybe even a bug?
    a
    • 2
    • 1
  • m

    martmists

    05/09/2022, 11:55 PM
    How do I get Thymeleaf to use
    resources/lang
    as its root folder for internationalization instead of
    resources/templates
    , or alternatively just use a single .properties file for all pages?
    a
    • 2
    • 2
  • r

    Robert Kempton

    05/10/2022, 2:18 AM
    How can I expose some routes via http, and some routes via https? Do I need to start two separate embedded servers?
    m
    a
    • 3
    • 5
  • m

    Muhammad Talha

    05/10/2022, 3:38 AM
    Is it possible to use the form auth plugin to accept json data instead of form data? If not, is there another plugin to do so?
    a
    • 2
    • 4
  • r

    Robert Kempton

    05/10/2022, 4:36 AM
    Is there a way to update the ssl certificate an embedded server is using without restarting the server?
    a
    • 2
    • 2
  • d

    dodalovic

    05/10/2022, 5:48 AM
    Hi, I'm trying to use
    externalServices
    mocking with the
    2.0.1
    ktor version, but it doesn't kick in:
    externalServices {
            hosts("<https://api.sendinblue.com>") {
                install(ContentNegotiation) {
                    json()
                }
                routing {
                    post("v3/smtp/email") {
                        call.response.status(HttpStatusCode.OK)
                    }
                }
            }
        }
    and then I call the API:
    val response = <http://httpClient.post|httpClient.post>("<https://api.sendinblue.com/v3/smtp/email>") {
                accept(ContentType.Application.Json)
                contentType(ContentType.Application.Json)
                header("api-key", apiKey)
    But this mocking doesn't kick-in, rather the real thing.
    a
    • 2
    • 8
  • j

    Joakim Forslund

    05/10/2022, 8:04 AM
    I've reported two, what I believe are memory leak issues for Native ktor network, https://youtrack.jetbrains.com/issue/KTOR-4298/embeddedServer-CIO-for-Native-Linux-with-ContentNegotiation-and- and https://youtrack.jetbrains.com/issue/KTOR-4297/aSocket-for-Native-Linux-seems-to-be-leaking-if-host-and-port-is Is there anything that can be done to mitigate or wrap the memory created manually (cleaning up the memory)?
    r
    n
    • 3
    • 2
  • r

    ribesg

    05/10/2022, 9:57 AM
    Is there no easier way to make a redirect to a different Resource when using the Resources plugin in Ktor 2 ?
    post<V1.OldPath> {
            val resources = application.plugin(Resources)
            val path = resources.resourcesFormat.encodeToPathPattern(V2.NewPath.serializer())
            call.respondRedirect(path, permanent = true)
        }
    a
    r
    • 3
    • 2
  • m

    martmists

    05/10/2022, 11:29 AM
    How do I disable ktor (2.0.1) from sending the content-length header? It seems to be breaking tools like XRebel which add HTML code, causing the page to be truncated as result. (for reference, XRebel hooks into the Tomcat engine, not ktor directly) My current solution is to append a tag hidden in production in thymeleaf of the exact size that's truncated but it's not a great solution as I'd need to append this to every template
    </html>
    <p th:remove="${config.IS_DEVELOPMENT} ? none : all" class="filler">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam sit amet lacus felis. Praesent vitae dapibus metus. Phasellus vel ornare nunc. Suspendisse potenti. Nulla cursus lacus nisl, eu accumsan velit consequat id. Proin vel mollis nulla. Aliquam fermentum elit erat, vitae imperdiet mi gravida vehicula. Cras eu dui ex. Nam pretium nulla egestas turpis eleifend porta. In pellentesque, lorem at rhoncus gravida, odio jus</p>
    a
    • 2
    • 5
  • r

    ribesg

    05/10/2022, 11:42 AM
    Can’t you make the client of a testApplication follow redirects?
    a
    • 2
    • 20
  • j

    Julius

    05/10/2022, 12:07 PM
    Hey! I'm trying to do the same thing as this stackoverflow post: https://stackoverflow.com/questions/71154171/is-there-any-way-to-drop-request-inside-plugin Meaning I want to reject a request inside a plugin (I want to implement verify firebase authentication https://firebase.google.com/docs/auth/admin/verify-id-tokens). The way described in the post doesn't work because of this error:
    Cannot access 'pipeline': it is internal in 'PluginBuilder'
    Is there a workaround for this or an overall better way to implement this?
    r
    u
    t
    • 4
    • 6
  • o

    Orhan Tozan

    05/10/2022, 12:53 PM
    Hi, a user of ours is getting the following exception when performing a HTTP request
    Caused by java.nio.channels.UnresolvedAddressException
    at <http://sun.nio.ch.Net|sun.nio.ch.Net>.checkAddress(Net.java:107)
    at <http://sun.nio.ch|sun.nio.ch>.SocketChannelImpl.connect(SocketChannelImpl.java:663)
    at io.ktor.network.sockets.SocketImpl.connect$ktor_network(SocketImpl.kt:32)
    at io.ktor.network.sockets.ConnectUtilsJvmKt.connect(ConnectUtilsJvm.kt:19)
    at io.ktor.network.sockets.TcpSocketBuilder.connect(TcpSocketBuilder.kt:38)
    at io.ktor.client.engine.cio.ConnectionFactory.connect(ConnectionFactory.kt:24)
    at io.ktor.client.engine.cio.Endpoint$connect$2$connect$1.invokeSuspend(Endpoint.kt:179)
    at io.ktor.client.engine.cio.Endpoint$connect$2$connect$1.invoke(Endpoint.kt:8)
    at io.ktor.client.engine.cio.Endpoint$connect$2$connect$1.invoke(Endpoint.kt:4)
    at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturnIgnoreTimeout(UndispatchedKt.java:100)
    at kotlinx.coroutines.TimeoutKt.setupTimeout(Timeout.kt:146)
    at kotlinx.coroutines.TimeoutKt.withTimeoutOrNull(Timeout.kt:103)
    at io.ktor.client.engine.cio.Endpoint.connect(Endpoint.kt:187)
    at io.ktor.client.engine.cio.Endpoint.access$connect(Endpoint.kt:21)
    at io.ktor.client.engine.cio.Endpoint$makeDedicatedRequest$1.invokeSuspend(Endpoint.kt:99)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
    at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)
    Anyone knows how to solve this?
    d
    a
    r
    • 4
    • 5
  • d

    dodalovic

    05/10/2022, 3:28 PM
    Is CIO engine main in ktor 2.0.1 something to be avoided
    e
    • 2
    • 4
  • d

    dodalovic

    05/10/2022, 3:29 PM
    Or better to ask, should one dare to change anything on this screen
    e
    • 2
    • 1
  • m

    Muhammad Talha

    05/11/2022, 3:23 AM
    Are internal redirects/route forwarding possible in Ktor? E.g. if I get a request to /path1 I want to forward it to the /path2 handler. It'd also be great if data could be modified on the request before forwarding.
    a
    • 2
    • 2
  • c

    charleskorn

    05/11/2022, 9:00 AM
    I am building a Kotlin/Native library, and just added a reference to
    ktor-client-curl
    to my Windows target (I’m using CIO for other targets). However, when I try to build and run the tests for Windows on a Windows runner on GitHub Actions, I get compilation errors (in thread) about missing symbols… any ideas on what I’m missing?
    • 1
    • 2
  • p

    Paul Woitaschek

    05/11/2022, 10:06 AM
    println(Url("<https://www.google.com/unicorns>").pathSegments)
    Is it a bug that this returns a list of two strings, where the first is empty and the second one is unicorns? Imo this should only contain
    unicorns
    a
    g
    • 3
    • 10
  • j

    Jan

    05/11/2022, 12:06 PM
    When making a custom plugin for Ktor Client, is it possible the modify the actual url the client requests to itself?
    • 1
    • 1
  • s

    Sam

    05/12/2022, 9:07 AM
    After upgrading to from ktor 1.5.1 to 2.0.1 I had some requests start failing because they couldn't connect. Initial indications are that it was trying to connect on port 80 even though it was a HTTPS URL. I'm using the Apache engine on JVM. Does this ring any bells for anyone?
    p
    • 2
    • 5
  • r

    ribesg

    05/12/2022, 11:19 AM
    There is a missing
    call.
    in the second code block here https://ktor.io/docs/responses.html#status
    d
    • 2
    • 1
  • h

    Hamza GATTAL

    05/12/2022, 10:35 PM
    Any clean code for response exception handling? -_-
    n
    a
    +2
    • 5
    • 4
  • o

    Okan Yıldırım

    05/14/2022, 9:21 PM
    Heyy, can I use JPA in Ktor? I tried many orms like Exposed or Ktorm, I didn't like any of them like Spring Data JPA. I was just simply creating a class with annotations and a repository, thats all. I am looking for something similar for Ktor
    f
    s
    +4
    • 7
    • 15
  • s

    Samwel Otieno

    05/16/2022, 9:14 AM
    I am building a Ktor application, for security I use jwt, how can I set up the refresh token flow for this? The documentation doesn't cover that bit. I would appreciate any pointers.
    a
    • 2
    • 1
  • m

    Marcello Galhardo

    05/16/2022, 5:19 PM
    Hey folks, I have a question about Ktor Http Client (Android). I have a
    post
    request where the body is always the same:
    @Serializable
    internal data class IgnoreRequest(val status: String = "IGNORE")
    And I send it like this:
    <http://httpClient.post|httpClient.post><Unit>(urlString = "whatever/${id.value}") { body = IgnoreRequest() }
    The idea is that you are updating the status of item to “IGNORE”. However, it looks like Ktor simple “does not send the body” when you have only default parameters:
    19:06:37.052  I  HttpClient: CONTENT HEADERS
    19:06:37.052  I  HttpClient: -> Content-Length: 3
    19:06:37.055  I  HttpClient: -> Content-Type: application/json; charset=utf-8
    19:06:37.055  I  HttpClient: BODY Content-Type: application/json; charset=utf-8
    19:06:37.056  I  HttpClient: BODY START
    19:06:37.056  I  HttpClient: {
    19:06:37.056  I  }
    19:06:37.056  I  HttpClient: BODY END
    That feels wrong. The parameter is not optional (nullable). It simply has a default parameter where for this particular case won’t change… and Ktor is not sending anything (API fails for missing body). Here is my question: is the Ktor’s behaviour by design? If yes, do you mind elaborating a little or letting me know where I can find details? If no, should I open a bug ticket for that? Thanks.
    a
    • 2
    • 2
  • j

    Jorge Bo

    05/16/2022, 8:40 PM
    Hi, is it possible to configure netty access log with ktor through logback.xml? Any suggestion?
    a
    • 2
    • 1
Powered by Linen
Title
j

Jorge Bo

05/16/2022, 8:40 PM
Hi, is it possible to configure netty access log with ktor through logback.xml? Any suggestion?
a

Aleksei Tirman [JB]

05/17/2022, 1:40 PM
Unfortunately, no. There is only some logging provided by Ktor. I’ve created a feature request.
👍 1
View count: 5