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

    dany giguere

    02/15/2022, 11:19 PM
    m
    a
    s
    • 4
    • 6
  • d

    dany giguere

    02/15/2022, 11:20 PM
    How can I import features.* ? and hopefully that will fix ContentNegotiation
    m
    • 2
    • 1
  • f

    fkrauthan

    02/16/2022, 12:26 AM
    If I have a
    ktor-client
    feature that has a
    sendPipeline
    and a
    receivePipeline
    intercept. How can I pass values from the sendPipeline intercept to the receivePipeline intercept (e.g. a class instance and/or some value)?
    a
    • 2
    • 4
  • r

    ribesg

    02/16/2022, 2:10 PM
    Does the normal version of Ktor support the new Kotlin Native Memory Management Model from 1.6.3+? I don’t see anything in the changelog
    b
    m
    +2
    • 5
    • 17
  • k

    Karl Azzam

    02/16/2022, 2:21 PM
    Nvm got it, u use the execute method
    r
    • 2
    • 1
  • m

    Michal Klimczak

    02/16/2022, 3:02 PM
    Anyone has a working config of ktor 2 client with json plugin and using new kotlin native memory model? For me it crashes with
    InvalidMutabilityException: mutation attempt of frozen kotlin.Array@249bab0
     in 
    kfun:io.ktor.client.plugins.json.serializer.SerializerInitializer.<init>#internal
    a
    • 2
    • 5
  • f

    fkrauthan

    02/16/2022, 8:46 PM
    Another quick
    ktor-client
    question. Is the
    scope.receivePipeline.intercept(HttpReceivePipeline.State) {
    always getting executed even if the API call failed (e.g. Invalid Host or Timeout)? If yes what value would
    context.response.status.value
    contain? And if not what pipeline do I need to adjust to to catch that?
    j
    a
    • 3
    • 5
  • t

    tateisu

    02/17/2022, 12:00 AM
    Question about ktor-client. How to know there is response boby or not, before calling
    HttpResponse.body()
    ?
    a
    • 2
    • 2
  • f

    Fabrizio Scarponi

    02/17/2022, 2:35 PM
    Hi there, I'm here to step up my kotlin specialization! I have a lot of questions to post! but for now, I'm looking for a good example of to how use properly ktor client response validation... can someone post me something? Thanks!
    a
    l
    • 3
    • 8
  • z

    zt

    02/17/2022, 11:20 PM
    I wanna make a value that only makes a network request when its read from. Using lazy delegate seemed like the solution but then I cant do that because the get method on the HTTP client is a suspending method. How would I be able to do this?
    r
    • 2
    • 1
  • p

    Piotr Krzemiński

    02/18/2022, 7:13 AM
    I found a small glitch on https://ktor.io/create/ - in Manual Configuration, choosing "Gradle Kotlin" displays Groovy, and vice versa. I wanted to contribute and fix it myself, but cannot find the source code.
    e
    a
    • 3
    • 3
  • c

    christophsturm

    02/18/2022, 12:28 PM
    the code example for streaming responses seems to be outdated, it does not compile: https://ktor.io/docs/response.html#streaming
    s
    • 2
    • 10
  • s

    sultanofcardio

    02/18/2022, 12:51 PM
    Yay 🤞
    :yes-black: 3
    🎉 1
    • 1
    • 1
  • a

    ansman

    02/18/2022, 5:28 PM
    I was under the impression that a
    WebSocketSession
    would be canceled (the coroutine that is) when both the incoming and outgoing channels are closed but this doesn’t seem to be the case. Can someone confirm that this is the intended behavior?
    • 1
    • 1
  • a

    André Martins

    02/18/2022, 5:42 PM
    Hello, whats the difference between Ktor-client features vs plugin? Will plugins replace features?
    a
    a
    • 3
    • 2
  • j

    Jorge Bo

    02/18/2022, 8:32 PM
    Hi, as part of a plugin that i am writing i need to change the http response body for not found error code. I understand that i should override ApplicationCallPipeline.Fallback phase, but don't sure how to change the response body. Any help?
    r
    • 2
    • 2
  • t

    Tobias Gronbach

    02/19/2022, 11:45 AM
    Hello, I tried to move to ktor version 2.0.0-beta-1 and now I have some problems. First question: Is there any documentation available? I couldn't find any.
    s
    • 2
    • 2
  • t

    Tobias Gronbach

    02/19/2022, 12:14 PM
    Still have some error I get after migrating to version 2.0.0-beta-1 that I do not understand (Ktor-Client). If I try to execute the following code:
    override suspend fun authenticateUser(userNameHash: String, passwordHash: String): UserAuthData? {
            return try {
                <http://client.post|client.post>(HttpRoutes.AUTHENTICATE_USER_FQDN) {
                    contentType(ContentType.Application.Json)
                    setBody {
                        UserRegistrationData(
                            userNameHash = userNameHash,
                            passwordHash = passwordHash
                        )
                    }
                }.body<UserAuthData>()
            } catch (e: Exception) {
     ...
               }
        }
    Data Class looks like this:
    @kotlinx.serialization.Serializable
    data class UserRegistrationData(
        val userNameHash: String,
        val passwordHash: String
    )
    HttpClient
    HttpClient(Android) {
    ....
            install(ContentNegotiation) {
                    json(Json {
                        ignoreUnknownKeys = true
                        isLenient = true
                    }
                    )
                }
    ....
    }
    Dependencies (for serialization)
    implementation("io.ktor:ktor-client-content-negotiation:$ktor_version")
    implementation("io.ktor:ktor-serialization-kotlinx-json:$ktor_version")
    Error Message: Line: 58, Method: authenticateUser: Serializer for class 'null' is not found. Mark the class as @Serializable or provide the serializer explicitly.
    s
    • 2
    • 4
  • t

    Tobias Gronbach

    02/19/2022, 1:10 PM
    I have another issue (hopefully last one). I load a list of quotes from an api. Everything worked fine before migration.
    override suspend fun getInspiringQuotes(): Resource<List<InspiringQuoteRemote>> {
            return try {
                val quotes = client.get {
                    url(WordpressRoutes.InspiringQuotes)
                }.body<List<InspiringQuoteRemote>>()
                Resource.Success(quotes)
            } catch (e: Exception) {
                Timber.e(e)
                Resource.Error(e.localizedMessage)
            }
        }
    This is the json-response I receive. I validated the response with an online tool that said it's a VALID (RFC 8259)
    [
       {
          "quote_author":"Oskar Wilde",
          "quote":"Unzufriedenheit ist der erste Schritt zum Erfolg."
       },
       {
          "quote_author":"Winston Churchill",
          "quote":"Erfolg haben heißt, einmal mehr aufstehen, als man hingefallen ist."
       },
       {
          "quote_author":"Henry Ford",
          "quote":"Erfolg besteht darin, dass man genau die Fähigkeiten hat, die im Moment gefragt sind."
       },
    
       {
          "quote_author":"Albert Einstein",
          "quote":"Der sicherste Ort für ein Schiff ist der Hafen. Doch dafür sind Schiffe nicht gemacht."
       }
    ]
    Still I get the following error. kotlinx.serialization.json.internal.JsonDecodingException: Expected start of the array '[', but had 'EOF' instead Any idea?
    s
    a
    • 3
    • 5
  • b

    brabo-hi

    02/20/2022, 4:03 AM
    hi all, i am having issue closing a client . i keep receiving messages event though i called
    client.close()
    client.wss() {
        incoming.consumeAsFlow().onCompletion{
              // never stops receiving even after closing connection with `client.close()`
        }
    }
    a
    • 2
    • 3
  • r

    Recca Chao

    02/20/2022, 12:10 PM
    https://ktor.io/create/ The "Manual Configuration" part placed the groovy config under the gradle tab, and gradle config under the groovy tab
    s
    d
    • 3
    • 2
  • s

    spierce7

    02/20/2022, 4:20 PM
    How would I configure my app using ktor client running Kotlin Native to only connect to a server using TLS 1.3?
    a
    • 2
    • 3
  • d

    dany giguere

    02/20/2022, 5:55 PM
    I’m learning Ktor and Kotlin. I’m trying to create a validation function for my Ktor 2 server app. I came up with :
    fun validate(title: String): Json {
            val errors: Json
            val titleArray: Array<String?>
            if(title.length < 20) {
                titleArray.add("The title must contain at least 20 characters")
            }
            if(title.length > 100) {
                titleArray.add("The title must contain no more than 100 characters")
            }
            if(titleArray.length > 0) {
                errors.title = titleArray
            }
            return Json {
                "errors": errors
            }
        }
    as it is, I get this error :
    Variable 'titleArray' must be initialized
    s
    • 2
    • 2
  • h

    Hien Nguyen

    02/21/2022, 4:22 AM
    actual class Test actual constructor() {
        actual val httpClientEngine: HttpClientEngineFactory<HttpClientEngineConfig>
            get() = OkHttp
    }
    I’m integrating the certificate pinning to the ktor kmm Does ktor use
    network_security_config
    file in android ?
    a
    • 2
    • 6
  • r

    rcd27

    02/21/2022, 5:51 AM
    Greetings, I'm trying to serve static files (from resources folder), it works properly according to the (guide)[https://ktor.io/docs/serving-static-content.html#defining-a-default-resource]. However, the filename is changed to
    download
    and I would like to keep the original one.
    routing {
            static("/download") {
                defaultResource("distributive/loottherun-desktop-0.10.29.zip")
            }
        }
    So when I go to
    localhost:8080/download
    I see that browser "downloads"
    download
    file. It is the same as my zip, but naming is wrong. How I can keep the right naming? Tried to play around arguments in defaultResource method, but didn't work.
    a
    r
    • 3
    • 3
  • o

    Omar Habash

    02/21/2022, 12:35 PM
    Hello everyone, is it possible to use ktor client for gRPC/protobuf and KMM (iOS/Android)? If someone could point me to a sample project/guide/docs that'd be great!
    a
    d
    e
    • 4
    • 10
  • s

    Satyam Agarwal

    02/21/2022, 2:11 PM
    Hei @Aleksei Tirman [JB] Is there a plan for this to be fixed in 2.0.0 https://youtrack.jetbrains.com/issue/KTOR-2435 ? Or atleast provide
    DoubleReceive
    feature for httpClients ?
    ➕ 1
    a
    r
    • 3
    • 3
  • d

    dany giguere

    02/21/2022, 11:27 PM
    How does it work for the application.conf locally vs in production. Do you create a application.conf.example, commit it on the repo but then add the application.conf in the .gitignore ? because the values in the fil will be different in production
    ktor {
        development = true
        deployment {
            port = 8080
            port = ${?PORT}
        }...
    a
    • 2
    • 1
  • k

    Kiet

    02/21/2022, 11:41 PM
    I'm not sure how it works, but when I use jib to build the container, it pushes the docker container to gcloud container registry where I run it. I don't have an application.conf at all it just somehow works.
    a
    • 2
    • 1
  • d

    dany giguere

    02/22/2022, 12:14 AM
    I’m using Ktor 2 and I’m trying to install the i18n package: https://github.com/aymanizz/ktor-i18n. I added the implementation in my build.gradle.kts file. But I have the impression it didn’t import the right package when I clicked import when I hovered over i18n. Anyhow I get these errors:
    a
    • 2
    • 1
Powered by Linen
Title
d

dany giguere

02/22/2022, 12:14 AM
I’m using Ktor 2 and I’m trying to install the i18n package: https://github.com/aymanizz/ktor-i18n. I added the implementation in my build.gradle.kts file. But I have the impression it didn’t import the right package when I clicked import when I hovered over i18n. Anyhow I get these errors:
a

Aleksei Tirman [JB]

02/22/2022, 11:17 AM
This plugin isn't migrated to Ktor 2.0.0 so it won't work.
👍 1
View count: 4