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

    kevin.cianfarini

    02/12/2020, 11:36 PM
    is there any way we can get this PR/issue some eyes? https://github.com/ktorio/ktor/pull/1352
    e
    • 2
    • 5
  • s

    Sourabh Rawat

    02/14/2020, 7:46 AM
    how to injection ktor
    Application
    when using koin.
    t
    • 2
    • 2
  • r

    ribesg

    02/14/2020, 2:16 PM
    There’s a new issue on K/N when upgrading from 1.3.0 to 1.3.1, I’m opening an issue
    :tnx: 1
    • 1
    • 4
  • a

    Austin

    02/14/2020, 5:43 PM
    Are there any examples of doing HTTP2 full duplex examples using KTor client?
    j
    • 2
    • 5
  • s

    Sourabh Rawat

    02/14/2020, 6:20 PM
    how do you handle env based configuration for ktor?
    e
    • 2
    • 1
  • j

    Jaxon Du

    02/15/2020, 7:59 AM
    Very new to Ktor and Kotlin. Can I use kotlinx serialization in a ktor rest api server? I installed the ktor plugin in IntelliJ IDEA, when creating a new ktor project, there is no Serialization under “Content Negotiation”, it has GSON, Jackson and ContentNegotiation. I just need to convert between class object and Json. Thought of using serialization as already tested it in KMP mobile app. Is serialization not suitable on server? Or I just need to manually add the dependency to my ktor server project?
    t
    g
    • 3
    • 5
  • r

    rrader

    02/15/2020, 11:34 AM
    Is someone using https://github.com/vincentlauvlwj/Ktorm ?
    k
    • 2
    • 1
  • c

    CLOVIS

    02/15/2020, 2:15 PM
    Is there something in Ktor to access GraphQL APIs? Or some other KMP library that can?
    m
    r
    • 3
    • 2
  • t

    twisterrob

    02/15/2020, 3:54 PM
    Hi, I get this message when doing tests:
    [Test worker] ktor.test(ApplicationEngineEnvironmentReloading.kt:135) No
    ktor.deployment.watch
    patterns specified, automatic reload is not active
    This is how I use tests (ktor 1.3.1):
    private fun endpointTest(test: TestApplicationEngine.() -> Unit) {
       withTestApplication(
          { /* I apply my `fun Application.module()` setup here */ },
          test
       )
    }
    How can I fix that message?
    c
    • 2
    • 7
  • g

    Grantas33

    02/15/2020, 7:52 PM
    Hello, does follow redirects feature work in CIO HttpClient? My HttpResponse returns 303 "See Other" with a Location header. If I try to read the text of the response it throws an
    io.ktor.client.features.RedirectResponseException: Unhandled redirect
    b
    • 2
    • 2
  • b

    Ben Woodworth

    02/15/2020, 8:05 PM
    I'm using kotlinx.serialization (JVM) for JSON deserialization, and I'm getting this error when I make a GET request:
    java.lang.UnsupportedOperationException: The only generic classes supported for now are standard collections, got class class ResponseEnvelope
    It looks like the solution to this was to use
    KotlinxSerializer.setMapper(...)
    in the
    HttpClientConfig
    , but that's been deprecated. Here is the erroring line of code: https://github.com/BenWoodworth/GroupMe.kt/tree/63b918c8d5a6c0a4aa3316ab76214beb72986e3d/src/main/kotlin/net/benwoodworth/groupme/GroupMe.kt#L75 Here is ResponseEnvelope, the class I want to deserialize: https://github.com/BenWoodworth/GroupMe.kt/tree/63b918c8d5a6c0a4aa3316ab76214beb72986e3d/src/main/kotlin/net/benwoodworth/groupme/ResponseEnvelope.kt Here is the ktor HttpClient declaration: https://github.com/BenWoodworth/GroupMe.kt/tree/63b918c8d5a6c0a4aa3316ab76214beb72986e3d/src/main/kotlin/net/benwoodworth/groupme/GroupMe.kt#L53-L61 And here is my build.gradle: https://github.com/BenWoodworth/GroupMe.kt/tree/63b918c8d5a6c0a4aa3316ab76214beb72986e3d/build.gradle Any idea how I might be able to fix this?
    d
    • 2
    • 2
  • l

    Leon K

    02/16/2020, 4:26 PM
    Hey, i've got a strange Exception using ktor-client:
    io.ktor.client.features.SendCountExceedException: Max send count 20 exceeded
    This appears when i use the basic auth feature, give it the wrong username and password and then try to get data from a backend. When i manually add the
    Authorization: Basic
    header, it works fine Any Ideas what causes this and how i could solve it? I'm using ktor 1.3.0
    r
    • 2
    • 5
  • a

    Arkangel

    02/16/2020, 10:20 PM
    hey guys ...any one used Ktor with Prisma before
    p
    e
    • 3
    • 2
  • m

    MrPowerGamerBR

    02/16/2020, 10:41 PM
    Hello everyone! Is there's any way to track and log how much time it took to process a request? Thanks!
    • 1
    • 1
  • m

    MrPowerGamerBR

    02/17/2020, 11:06 AM
    I found a bug (not really a bug, but maybe an "undesirable feature"?): If you are using sessions with cookies, ktor will always send a
    Set-Cookie
    header on static files, even if the session wasn't changed. While this isn't a super huge issue, it also sends the
    Set-Cookie
    header for assets (like css, js, etc) and that breaks Cloudflare's cache (it always bypasses the cache)
    s
    • 2
    • 7
  • t

    Tamas

    02/17/2020, 7:57 PM
    hello I would like to receive a generic list
    val updates = call.receive<List<PositionPatch>>()
    however I receive
    List<LinkedHashMap
    . when I send / receive just one object, then it works like a charm. is there a way to influence the binding?
    e
    • 2
    • 29
  • n

    napperley

    02/17/2020, 8:56 PM
    Nikolay Igotti mentioned that Ktor has its own testing infrastructure ( https://kotlinlang.slack.com/archives/C3SGXARS6/p1581939600402100?thread_ts=1581915720.390500&amp;cid=C3SGXARS6 ). Is there a document/example that shows how Ktor is being tested (especially the Ktor Client library for the linuxX64 target)?
    e
    • 2
    • 2
  • v

    vitaly

    02/18/2020, 2:13 PM
    Does anybody know how to configure ktor client for case-insensitive json deserialization? I have a DTO (data class) which has enum property. All enum values are in upper case but data is in lower case.
    m
    • 2
    • 4
  • t

    Thomas

    02/18/2020, 8:45 PM
    I would like to retry HTTPS requests with HTTP requests if there is a
    ConnectException
    . Is the code below correct or is there a better way to do this?
    client.install("HttpsToHttp") {
        requestPipeline.intercept(HttpRequestPipeline.Before) {
            val requestBuilder = this.context
            try {
                proceedWith(it)
            } catch (exception: ConnectException) {
                if (requestBuilder.url.protocol == URLProtocol.HTTPS) {
                    requestBuilder.url.protocol = URLProtocol.HTTP
                    proceedWith(requestPipeline.execute(requestBuilder, it)) // not sure if this is correct
                } else {
                    throw exception
                }
            }
        }
    }
    e
    • 2
    • 23
  • g

    Gyuhyeon

    02/19/2020, 9:07 AM
    Is there a way to
    .receive()
    response using ktor client to access
    HttpResponse
    while also accessing the response body as a type? What I mean is,
    ktorClient.request<HttpStatement> {...}.receive<HttpResponse>()
    seems to be one way to receive responses while
    ktorClient.request<HttpStatement> {...}.receive<MyJsonModel>()
    seems to be a way to receive the body as a predefined data class. However, due to needs in highly customized logging and whatnot, I need a way to access HttpResponse along with parsing it into MyJsonModel. What I would've preferred is something along the lines of
    val response = ktorClient.request<HttpStatement> {...}.receive<HttpResponse>()
    // do things with response and then...
    return response.parseBodyAs(MyJsonModel::class.java)
    but there doesn't seem to be a way to do so. Do I have to parse myself using serializers manually if I decide to receive as
    HttpResponse
    ?
    c
    j
    • 3
    • 3
  • p

    pandawarrior

    02/20/2020, 11:04 AM
    Do you guys know what is the default timeout of Ktor requests? :)
    c
    • 2
    • 1
  • c

    cy

    02/20/2020, 12:19 PM
    ❓ 📣 We are going to develop and expand ktor Locations (Type-Safe routing https://ktor.io/servers/features/locations.html). One of the directions to improve is Kotlin Multiplatform. The most obvious way of migration to MPP is to use kotlinx.serialization in locations. Due to the limited reflection capabilities of non-JVM targets, there are things that not so easy to implement. On the other hand, there are questionable features that may lead to issues. One of the problematic features is nested location classes and nested location objects.  What we are thinking of to change: • a nested location class should always have a property of the outer class or object • nested objects in objects are not allowed The motivation for the first point is the fact that a location class nested to another, makes no sense without the ability to refer to the outer class. Consider the following example:
    @Location("/api/{version}")
    class Api(val version: Int) {
       @Location("/user/{id}")
       class User(val id: String, val api: Api = Api(1)) {
         // here API presence looks required, 
         // otherwise, there is no way to find a version value
         // so now we demand the api parameter to exist
       }
    }
    The other point is that one can't just move a nested class outside without additional manual changes:
    @Location("/root")
    class Outer {
       @Location("/child")
       class Child // it is tied to /root/child path
    }
    
    @Location("/child")
    class Child // this is tied to just /child
    
    @Location("/child2")
    class Child2(val outer: Outer) // -> /root/child2
    The cause of the second change is that objects should be symmetric with classes, and one can't add a constructor property to an object. The unfortunate consequence is that one can't write like this anymore:
    @Location("/api")
    object Api {
       @Location("/info")
       object Info 
    }
    Should be migrated to the following:
    @Location("/api")
    object Api {
       @Location("/info")
       class Info(val api: Api = Api)
       // the api parameter is required, weird isn't it
    }
    The question is: do these changes affct many, does anybody use structured locations with nested objects?
    s
    c
    • 3
    • 7
  • s

    Smith

    02/20/2020, 1:04 PM
    I can also use Attributes, but they have a per-call lifetime
    c
    • 2
    • 1
  • s

    Slackbot

    02/20/2020, 8:31 PM
    This message was deleted.
    s
    l
    +2
    • 5
    • 6
  • a

    altavir

    02/21/2020, 8:45 AM
    I am trying to migrate
    plotly.kt
    to newer ktor version and encountered a problem. I need to get a host name from request in order to send a data request to the same server but with different address. Previously I was using
    call.request.host()
    for that, but now for some reason on localhost it returns IP6 adress 0.0.0.0.0.0.0.0, which is not friendly with JS backward requests. Are there any better way to treat this situation?
    c
    s
    • 3
    • 19
  • j

    Jaxon Du

    02/21/2020, 2:08 PM
    Started a new project, from ktor plugin I select “GradleKotlinDsl”. Select a few options such as Location, Sessions. Then there is red bar with error “Project ‘xxxxx’ isn’t linked with Gradle”. I’m brand new to ktor, also IntelliJ, just follow tutorial on the web, encounter this error on step 0. Begin to doubt if I’m too stupid to learn. I’m using the latest IntelliJ IDEA CE. Will the paid version have lesser such error?
    c
    m
    • 3
    • 4
  • s

    Smith

    02/22/2020, 2:03 PM
    Can I do an internal redirect from one route to another?
    c
    • 2
    • 1
  • l

    Leon K

    02/22/2020, 4:52 PM
    "lost in ambiguity tie" sounds like maybe there is another route that matches too, so it doesn't know what to do?
    ➕ 1
    e
    c
    • 3
    • 3
  • j

    JoakimForslund

    02/24/2020, 12:25 PM
    I'm not sure if this is my own implementation or not, but i'm having a really weird experience using latest ktor 1.3.0.
    var result: T? = null
            try {
                println("FFFFFFFfffff - 2")
                result = httpClient?.request(httpRequestBuilder)
            } catch (e: Exception) {
                println("FFFFFFFfffff - 3: ${e.cause} -> ${e.message}")
                throw e.cause!!
            } finally {
                println("FFFFFFFfffff - 4: ${result}")
                return result
            }
    Essentially the result ends up with null, which is not weird because it is initially set as such, however the httpClient?.request does not throw an error and the result is still null The httpClient is initialized, and the engine is also initialized. I'm confused as to why
    r
    l
    • 3
    • 26
  • s

    Saood

    02/24/2020, 1:39 PM
    How to set URLSession delegate in below code for certificate validation?
    Ios.create {
        configureRequest {
    
        }
    }
    i have delegate method for certificate validation
    func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Swift.Void)
    is Anyone tried ?
    t
    • 2
    • 2
Powered by Linen
Title
s

Saood

02/24/2020, 1:39 PM
How to set URLSession delegate in below code for certificate validation?
Ios.create {
    configureRequest {

    }
}
i have delegate method for certificate validation
func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Swift.Void)
is Anyone tried ?
t

Thomas

02/24/2020, 2:48 PM
I am interested in this as well (see: https://kotlinlang.slack.com/archives/C0A974TJ9/p1582039786270400)
Apart from editing the Ktor source code (or copying the Ios engine and editing it) I have not found a solution yet.
View count: 9