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

    Raymond Chan

    07/15/2022, 3:03 AM
    As per: https://kotlinlang.slack.com/archives/C0A974TJ9/p1654555064089159 We encountered similar problems too. We have included Ktor lib in our KMM project, however, we don’t invoke any Ktor related call in our iOS project. App crashed due to
    Strings.kt line 296
    EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000000000000
    We drilled down the logs on crashlytics a bit, and found that the app crashed during when our class
    AnalyticsTracker
    was initializing. However,
    AnalyticsTracker
    didn’t contain any Ktor related code, we are only accessing some constants defined in KMM. And what we found interesting is that we found stacktrace for
    com.apple.main-thread
    comes in with a little bit variation. You may check the attached stacktrace. Kotlin version: 1.5.31, Ktor version: 1.6.0
    Stacktrace for Thread #1
    Crashed: Thread
    0  9Gag                           0x55f634 kfun:kotlinx.cinterop#<get-cstr>__at__kotlin.String(){}kotlinx.cinterop.CValues<kotlinx.cinterop.ByteVarOf<kotlin.Byte>> + 296 (Strings.kt:296)
    1  9Gag                           0x6e595c kfun:io.ktor.utils.io.charsets.CharsetImpl.<init>#internal + 26 (CharsetNative.kt:26)
    2  9Gag                           0x6e5788 kfun:io.ktor.utils.io.charsets.Charsets#<init>(){} + 383 (CharsetNative.kt:383)
    3  9Gag                           0xa698ec InitSingletonStrict + 4325644524
    4  9Gag                           0x947104 __unnamed_2910 + 4324454660
    5  9Gag                           0xa74630 Kotlin_initRuntimeIfNeeded + 4325688880
    6  9Gag                           0xa7698c (anonymous namespace)::workerRoutine(void*) + 4325697932
    7  ???                            0x18251c2c0 (Missing)
    8  ???                            0x18251c220 (Missing)
    9  ???                            0x18251fcdc (Missing)
    com.apple.main-thread_3.txtcom.apple.main-thread_2.txtcom.apple.main-thread_1.txt
    a
    • 2
    • 3
  • o

    Omer Amiel

    07/15/2022, 5:05 AM
    Hi, How do I pass an instance of
    Gson
    in the
    ContentNegotiation
    block? This doesn’t work:
    val gsonInstance: Gson = ...
    
               install(ContentNegotiation) {
                    gson {
                        gsonInstance
                        setPrettyPrinting()
                        setLenient()
                    }
                }
    a
    • 2
    • 1
  • j

    John O'Reilly

    07/15/2022, 10:15 AM
    Writing a test using
    HttpClient
    and wondering if there should be way of specifying what version of TLS you want to use?
  • h

    Hamza GATTAL

    07/15/2022, 5:09 PM
    Hi everyone what is the main cause of this exception kotlinx.coroutines.JobCancellationException: Parent job is Completed; job=JobImpl{Completed}@6be308
  • j

    Jan

    07/15/2022, 5:50 PM
    whats a good way to access the location hash thing in a html (like: https://test.com/callback#arg=2, everything after #) in ktor? This doesn't seem to work:
    get("/") {
        call.respondText(ContentType.Text.Html) {
            """
                <!DOCTYPE html>
                <html lang="en">
                <head>
                    <title>Supabase In App Authentication</title>
                </head>
    
                <body>
                <script>
                    const pairs = location.hash.substring(1).split("&").map(pair => pair.split("="))
                </script>
                </body>
                </html>
            """.trimIndent()
        }
    }
    Is there a good way without using templates or something?
    e
    • 2
    • 4
  • m

    Mikhail

    07/17/2022, 6:11 PM
    Does Ktor client support
    text/event-stream
    ?
    a
    • 2
    • 3
  • h

    Helio

    07/18/2022, 7:25 AM
    Hello Ktor Team, I was wondering if you could shed some light regarding optimisations for Netty Server. More specifically regarding the number of available connections. We are currently running a Netty Server application within an EC2 instance (c5.large) and I noticed that whenever the upstream takes long to process some of the requests, it looks like Ktor run out of connections and therefore our application can’t receive more load, which results in 504's in the Load Balancer Level Having a look at this channel, I noticed that it was suggested to tweak the following parameters:
    /**
             * Size of the queue to store [ApplicationCall] instances that cannot be immediately processed
             */
            public var requestQueueLimit: Int = 16
    
            /**
             * Number of concurrently running requests from the same http pipeline
             */
            public var runningLimit: Int = 32
    I would like to know if you have any suggestion regarding what’s the best approach to test / update these parameters? We are currently running
    Ktor 2.0.3
    . Thanks for your help.
    e
    r
    • 3
    • 9
  • h

    Hamza Maqsood

    07/18/2022, 9:14 PM
    has anyone used ktor with pgbouncer?
    j
    • 2
    • 3
  • j

    Júlio Santos

    07/18/2022, 9:33 PM
    Guys, have you ever experimented with graalvm?
    a
    • 2
    • 2
  • d

    Dean Djermanović

    07/19/2022, 10:28 AM
    What are the differences between
    HttpClient(Android)
    and
    HttpClient(OkHttp)
    with regards to
    ktor-client
    ?
    b
    a
    • 3
    • 12
  • a

    Andrew Steinmetz

    07/20/2022, 12:16 AM
    Is there a way to configure the ContentNegotiation plugin on ktor to filter out a particular part of response body before trying to parse it? I'm running into an unusual api that decided to add a random string of characters before the actual json object so it keeps throwing an error trying to parse the object since the few characters before the JSON object make it an invalid structure.
    b
    e
    +2
    • 5
    • 13
  • o

    Omer Amiel

    07/20/2022, 9:26 AM
    Hi, I configured a
    CIO
    client, and able to use it against the server. issue is I can’t see any logs of those req in Charles/Network inspector, I guess it’s bcs I didn’t configure TLS for the engine. I followed this, but not sure how to provide the
    keystore
    file. is that the issue? any idea how to solve it? EDIT: I actually think it’s bcs I didn’t config proxy, but having issues there: I added this:
    engine {
    ...
        proxy = ProxyBuilder.http(URLBuilder(host = hostName, protocol = URLProtocol.HTTPS, port = 8080 ).build())
    ...
    }
    the req is triggered, but getting t/o, what am I doing wrong?
  • a

    Alexander Sysoev

    07/20/2022, 2:35 PM
    Hello! How can i read request body in MockEngine handler?
    a
    • 2
    • 8
  • i

    IsaacMart

    07/20/2022, 10:54 PM
    Hello guys, I am having a challenge with returning my response sealed class. I think is something to do with serialization but haven't been able to figure it out yet. My error: Problem retrieving User.Try again later! Serializer for class 'Success' is not found. Mark the class as @Serializable or provide the serializer explicitly.
  • i

    IsaacMart

    07/20/2022, 10:56 PM
    Hello guys, I am having a challenge with returning my response sealed class. I think is something to do with serialization but haven't been able to figure it out yet. My error: Problem retrieving User.Try again later! Serializer for class 'Success' is not found. Mark the class as @Serializable or provide the serializer explicitly. Here is my sealed class.
    @Serializable
    sealed class Resource<T>(
        val data: T? = null,
        val message: String? = null,
        val token: String? = null
    ) {
        class Success<T>(data: T?, message: String, token: String? = null) :
            Resource<T>(data, message, token)
    
        class Error<T>(message: String, data: T? = null, token: String? = null) :
            Resource<T>(data, message, token)
    }
    a
    p
    • 3
    • 2
  • j

    Javier

    07/21/2022, 12:37 PM
    I am getting an issue when combining
    MockEngine
    with
    Json
    , but the same exact logic is working when fetching from remote, more info in 🧵
    a
    • 2
    • 7
  • l

    Lidonis Calhau

    07/22/2022, 8:32 AM
    Is there somewhere an example with resources and JSON together? I could find https://github.com/ktorio/ktor-documentation/tree/2.0.3/codeSnippets/snippets/resource-routing and https://github.com/ktorio/ktor-documentation/tree/2.0.3/codeSnippets/snippets/json-kotlinx
    a
    • 2
    • 10
  • e

    eenriquelopez

    07/22/2022, 9:41 AM
    Hi Kotliners. Does Ktor support chunk content transmission? I am using
    HttpClient(CIO)
    , and my client speaks with a server that delivers a chunked JSON. I have been trying to change headers, response model, etc… But it does not seem to help. I am receiving the following error:
    NoTransformationFoundException: No transformation found: class io.ktor.utils.io.ByteBufferChannel -> class com.my.class
    I have seen this when trying ktor cannot serialize something in the data class, but right now I am using an empty class, which should be “serializable”
    • 1
    • 2
  • j

    Joe Altidore

    07/25/2022, 10:00 AM
    Hello Kotlin devs, I am trying to install "Koin" for DI. I have added the Koin dependency to my gradle but it doesn't seem to install.
    implementation("io.insert-koin:koin-core:3.2")
    
    implementation("io.insert-koin:koin-ktor:3.2")
    This block is having an error
    install(Koin) {
    /*logic here**/ } Unresolved reference: Koin
    j
    • 2
    • 2
  • p

    Piotr Krzemiński

    07/25/2022, 10:38 AM
    hi, I'm looking for someone with hands-on experience with both Spring/Spring Boot and ktor, willing to share their knowledge on a Tricity Kotlin User Group meetup, in a form of a talk around the beginning of September. Ideally we'd like to see some kind of comparison, strengths and weaknesses, experience from introducing it in production, other observations as well. The important aspect is to show how ktor solves certain problems of Spring and why it's worth to even consider trying it out. If you're interested, please reach out to me 🙂
  • h

    harry248

    07/25/2022, 1:31 PM
    Intercepting a request using HttpSend (like in https://ktor.io/docs/http-send.html) , what would be the recommended way to prevent the request from being sent. Throwing an exception?
    a
    • 2
    • 8
  • m

    MJegorovas

    07/25/2022, 2:45 PM
    Probably a bug, don't know for sure, but when you have request resource like this
    @Serializable
    @Resource("test/{id}.pdf")
    class GetPDF(val parent: Timestamp = Timestamp(), val id: String)
    The path parameter doesn't get filled and you get a request like
    ...test/{id}.pdf?id=1
    instead of
    .../test/1.pdf
    a
    • 2
    • 2
  • m

    Michael Waitt

    07/25/2022, 6:17 PM
    Hey folks 👋 Quick question on the new
    createApplicationPlugin
    API. More info in 🧵.
    a
    • 2
    • 4
  • p

    paw

    07/25/2022, 6:18 PM
    Hi Is there any way to change the way Ktor encodes spaces in query parameters? By default, it encodes spaces as
    +
    in query parameters, which I understand is the general convention. However, the API I have to work with is not particularly well-designed, and so it only accepts
    %20
    as a space, even in query parameters. Is there any way I can tell Ktor to always encode spaces as
    %20
    no matter the context? The only solution I’ve found so far is
    .encodeURLParameter(spaceToPlus = false)
    , but that doesn’t seem to be able to apply to globally apply that property in the ktor instance, as one might do with a user agent, it has to be done manually every time. Is there a better way?
  • s

    Susmitha Gudapati

    07/26/2022, 9:14 PM
    Hi, I’m using ktor’s
    ParametersBuilder
    to build params from JsonObject and I see that double quotes are added to my query params’ values. Can someone help me in correcting or handling this ?
    a
    • 2
    • 3
  • h

    hikamaeng

    07/27/2022, 7:06 AM
    ktor server template coroutine + R2DBC + and more https://github.com/doohochang/kotlin-server-template
  • d

    Didier Villevalois

    07/28/2022, 3:36 PM
    Hi all! It seems the gradle build of Ktor is configured to use a JDK 11. Therefore, the unix domain socket tests (requiring JDK 16+) are never run. How can I force the JDK used for tests to a particular JDK version?
    a
    • 2
    • 2
  • a

    Andrew Steinmetz

    07/28/2022, 4:50 PM
    Does anybody happen to know what the syntax is to grab the request information from a request already made in the
    HttpReceivePipeline.After
    to be able update this old plugin to Ktor 2.0? Looking at the old and new versions of Ktor, it looks as if
    context.request
    is no longer accessible since the type on the receive pipeline is now Unit instead of
    HttpClientCall
    ?
    a
    • 2
    • 3
  • n

    napperley

    08/01/2022, 1:12 AM
    A new issue has been created in the Ktor Issue Tracker on missing lifecycle APIs: https://youtrack.jetbrains.com/issue/KTOR-4704/Missing-Lifecycle-APIs-For-Ktor-Server
    s
    • 2
    • 4
Powered by Linen
Title
n

napperley

08/01/2022, 1:12 AM
A new issue has been created in the Ktor Issue Tracker on missing lifecycle APIs: https://youtrack.jetbrains.com/issue/KTOR-4704/Missing-Lifecycle-APIs-For-Ktor-Server
s

simon.vergauwen

08/01/2022, 6:51 AM
I’ve actually been working on something specifically for Ktor but it’s leveraging structured concurrency instead. I’m still in the process of writing documentation today, and will make a first stable release this week. https://github.com/arrow-kt/suspendapp There is several ways to leverage it, but together with this ticket it would be really nice since it would allow you to leverage the
emebeddedServer
on the
CoroutineScope
and it will cancel/shutdown gracefully on `SIGINT`/`SIGTERM` etc. Not just playing nice in the terminal, but also playing nice with Kubernetes and containers etc. https://youtrack.jetbrains.com/issue/KTOR-4427/CoroutineScopeembeddedServer-graceful-shutdown
You can also use abstraction such as
Resource
and reason about graceful shutdown in terms of structured concurrency. It’s being developed outside of the Ktor context, since it’s also interesting to use in combination with for example Kafka streaming if you want to guarantee offsets being committed before shutdown on
SIGINT
or another shutdown signal.
https://arrow-kt.io/docs/apidocs/arrow-fx-coroutines/arrow.fx.coroutines/-resource/
You can already try the
alpha
release which is published on Maven Central.
View count: 6