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

    dave08

    11/11/2018, 12:20 PM
    Does anyone have a more real-world example of the use of the HTML-DSL? Preferable with twitter bootstrap and for CRUD purposes.
    👍 1
    a
    • 2
    • 3
  • d

    dave08

    11/11/2018, 2:23 PM
    Also, when using
    withTestApplication
    and multiple connectors (and testing on port), how will the test know how to request from a particular port?
    c
    • 2
    • 7
  • c

    cy

    11/12/2018, 12:47 PM
    📣
    1.0.0-beta-4
    has been published - kotlinx.coroutines 1.0.1 - ktor client improvements - per-call memory consumption optimizations - eliminated I/O errors logging in Netty - fixed hanging compression feature with HTML/writeTo - MockEngine improvements, moved to
    ktor-client-mock
    - cookies handling fixes - other minor bugfixes and improvements
    🎉 14
    l
    e
    • 3
    • 9
  • m

    Marc Knaup

    11/12/2018, 5:26 PM
    Wow, the relationship between ktor and kotlinx-coroutines is really fragile. Just updated to beta 4 and was surprised that my server is now dead. Nothing in the logs, no responses to endpoints. Once I've noticed that I must also update kotlinx-coroutines from 1.0.0 to 1.0.1 everything worked again 😮
    e
    • 2
    • 1
  • d

    Dima Avdeev

    11/13/2018, 2:09 AM
    Does Ktor client for JavaScript support web-socket?
    🇳🇴 1
    e
    • 2
    • 2
  • j

    jeggy

    11/13/2018, 9:40 AM
    Someone that could help me get CORS to work? I'm getting a OPTIONS request and I want to allow it, but ktor keeps returning 403 Forbidden. I have installed the CORS module, but most likely configured it wrong.
    • 1
    • 1
  • r

    russhwolf

    11/14/2018, 3:14 AM
    I’m excited that http-client-mock went multiplatform, but I can’t make it work in my ios tests. Instead it just hangs forever. See sample repo here: https://github.com/russhwolf/ktor-demo, and specifically this test when running on iOS https://github.com/russhwolf/ktor-demo/blob/master/app/src/commonTest/kotlin/sample/KtorClientTest.kt
    t
    e
    • 3
    • 6
  • l

    Lucas Borges

    11/14/2018, 10:28 AM
    Hi, I’m begginer with Ktor…I’m trying to increase the response timeout in my dev enviroment but when I try to compile the project I’ve the follow error: `Exception in thread "main" com.typesafe.config.ConfigException$Parse: application.conf @ file😕Users/prosegur/IdeaProjects/GenesisMobileApi/build/resources/main/application.conf: 19: Expecting end of input or a comma, got '{' (if you intended '{' to be part of a key or string value, try enclosing the key or value in double quotes)`…this is my application.conf…
    o
    • 2
    • 1
  • s

    Sergio Casero

    11/14/2018, 6:54 PM
    Hi guys! Is there any way to set a custom timeout for ktor common client?
    e
    • 2
    • 5
  • d

    dave08

    11/15/2018, 5:00 PM
    I think there's an inconsistancy with these two definitions I think:``` /** * Builds a route to match
    POST
    requests with specified [path] receiving request body content of type [R] */ @ContextDsl @JvmName("postTyped") inline fun <reified R : Any> Route.post( path: String, crossinline body: suspend PipelineContext<Unit, ApplicationCall>.(R) -> Unit ): Route { return route(path, HttpMethod.Post) { handle { body(call.receive()) } } } /** * Builds a route to match
    POST
    requests */ @ContextDsl fun Route.post(body: PipelineInterceptor<Unit, ApplicationCall>): Route { return method(HttpMethod.Post) { handle(body) } } ``` Shouldn't the second also do
    call.receive()
    ?
    c
    • 2
    • 4
  • s

    serebit

    11/16/2018, 3:10 AM
    Yeah, so, on my discord library, if I use the CIO backend, the requests get slower and slower until the receive channel closes. But if I swap to OkHttp, it's completely fine.
    e
    • 2
    • 2
  • r

    rocketraman

    11/17/2018, 4:06 PM
    Posted this in #coroutines then realized its probably a ktor question... I've got a JVM process using ktor 1.0.0-beta-3 and coroutines 1.0.0 that has a thread like this that appears to be in a tight loop and using 100% CPU -- notice the ktor frames in the stack:
    "DefaultDispatcher-worker-5" - Thread t@95
       java.lang.Thread.State: RUNNABLE
    	at sun.nio.ch.EPollArrayWrapper.epollWait(Native Method)
    	at sun.nio.ch.EPollArrayWrapper.poll(EPollArrayWrapper.java:269)
    	at sun.nio.ch.EPollSelectorImpl.doSelect(EPollSelectorImpl.java:93)
    	at sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:86)
    	- locked <1c724d56> (a sun.nio.ch.Util$3)
    	- locked <2daa5d57> (a java.util.Collections$UnmodifiableSet)
    	- locked <69cba374> (a sun.nio.ch.EPollSelectorImpl)
    	at sun.nio.ch.SelectorImpl.selectNow(SelectorImpl.java:105)
    	at io.ktor.network.selector.ActorSelectorManager.process(ActorSelectorManager.kt:76)
    	at io.ktor.network.selector.ActorSelectorManager$process$1.invokeSuspend(ActorSelectorManager.kt)
    	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:32)
    	at kotlinx.coroutines.DispatchedTask$DefaultImpls.run(Dispatched.kt:235)
    	at kotlinx.coroutines.DispatchedContinuation.run(Dispatched.kt:81)
    	at kotlinx.coroutines.scheduling.Task.run(Tasks.kt:94)
    	at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:586)
    	at kotlinx.coroutines.scheduling.CoroutineScheduler.access$runSafely(CoroutineScheduler.kt:60)
    	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:732)
    
       Locked ownable synchronizers:
    	- None
    
    "DefaultDispatcher-worker-5" - Thread t@78
       java.lang.Thread.State: TIMED_WAITING
    	at sun.misc.Unsafe.park(Native Method)
    	at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:338)
    	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.doPark(CoroutineScheduler.kt:835)
    	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.cpuWorkerIdle(CoroutineScheduler.kt:813)
    	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:721)
    
       Locked ownable synchronizers:
    	- None
    It isn't executing any application code, just continuously parking/unparking, AFAICT. How can I tell what is going on here and why this has happened?
    c
    • 2
    • 3
  • g

    gabin

    11/17/2018, 4:56 PM
    how to add win 1251 support to ktor http client?
    b
    c
    • 3
    • 8
  • f

    frellan

    11/19/2018, 8:53 AM
    @ketilsan Yes, I was confused by that at the start too. You dont return anything like a response object, you just call call.respond and passalong what you want returned.
    k
    d
    o
    • 4
    • 19
  • e

    enleur

    11/19/2018, 4:08 PM
    something is coming… 👀
    1️⃣ 1
    🤫 2
    🕵️‍♂️🏻 2
    🤐 1
    🚀 4
    :yes: 4
    n
    m
    c
    • 4
    • 5
  • e

    enleur

    11/19/2018, 6:28 PM
    Improved performance
    where can I read more about this?
    c
    • 2
    • 2
  • s

    serebit

    11/19/2018, 8:17 PM
    Hopefully the two issues I've been having with ktor will be resolved soon, so I can fully integrate it into my project
    o
    • 2
    • 10
  • s

    steamstreet

    11/19/2018, 11:15 PM
    Am I correct in believing that the Http client doesn't support relative calls from the browser? So, you can't make a call to say
    /api/something
    and it will automatically resolve from the page's host?
    e
    • 2
    • 1
  • a

    anidotnet

    11/20/2018, 4:56 AM
    Is there any built-in oauth2 authorization server available in ktor like spring-oauth2? I was checking the documentation but only found third party integrations.
    🧐 1
    o
    k
    a
    • 4
    • 3
  • t

    Tim Büthe

    11/20/2018, 8:46 AM
    https://kotlinlang.slack.com/archives/C0B8RC352/p1542703370141300
    e
    r
    f
    • 4
    • 15
  • s

    shopodg

    11/20/2018, 9:12 AM
    Hello everyone ,Are there any performance comparisons between netty and CIO?
    l
    o
    +2
    • 5
    • 7
  • h

    hdarritchon

    11/20/2018, 1:21 PM
    It’s possible to do it with Metrics using metrics-servlet but nothing with metrics in Ktor.
    d
    • 2
    • 24
  • s

    Saša Šijak

    11/20/2018, 5:17 PM
    is kotlinx.serialization fast? I expect it to be much faster than annotation based libraries
    s
    t
    • 3
    • 2
  • d

    dave08

    11/20/2018, 5:23 PM
    I guess I'm not the only one @orangy 😃... the work is even done. Any chance it'll squeeze into the next Ktor version?
    👌 1
    o
    • 2
    • 3
  • r

    robin

    11/21/2018, 9:29 AM
    I've noticed the "Documentation"-link for the DataConversion feature on the start.ktor.io page is pointing to the documentation page for the CachingHeaders feature - is this already known, and if not, what's the proper channel to report this so that it can be fixed?
    s
    • 2
    • 2
  • h

    hdarritchon

    11/21/2018, 10:57 AM
    In this response, the jvm.file has a value (Int) where as in fact, it is an object with other fields
    Response_serialized_by_Jackson.js
    m
    • 2
    • 5
  • n

    Nir Golan

    11/21/2018, 11:45 AM
    hi guys, need some help, first try with ktor, getting the sample template from intellij plugin and with the starter code the app crash.
    package com.example
    
    import io.ktor.application.*
    import io.ktor.response.*
    import io.ktor.request.*
    import io.ktor.routing.*
    import io.ktor.http.*
    import io.ktor.gson.*
    import io.ktor.features.*
    import io.ktor.client.*
    import io.ktor.client.features.json.*
    import io.ktor.client.request.*
    import java.net.URL
    import kotlinx.coroutines.*
    
    fun main(args: Array<String>): Unit = io.ktor.server.netty.EngineMain.main(args)
    
    @Suppress("unused") // Referenced in application.conf
    @kotlin.jvm.JvmOverloads
    fun Application.module(testing: Boolean = false) {
        install(ContentNegotiation) {
            gson {
            }
        }
    
        val client = HttpClient() {
            install(JsonFeature) {
                serializer = GsonSerializer()
            }
        }
        runBlocking {
    //         Sample for making a HTTP Client request
    //        /*
    //        val message = <http://client.post|client.post><JsonSampleClass> {
    //            url(URL("<http://127.0.0.1:8080/path/to/endpoint>"))
    //            contentType(ContentType.Application.Json)
    //            body = JsonSampleClass(hello = "world")
    //        }
    //        */
        }
    
        routing {
            get("/") {
                call.respondText("HELLO WORLD!", contentType = ContentType.Text.Plain)
            }
    
            get("/json/gson") {
                call.respond(mapOf("hello" to "world"))
            }
        }
    }
    
    data class JsonSampleClass(val hello: String)
    when i'm commenting out the client its working, can any one help?
    c
    • 2
    • 5
  • v

    v79

    11/21/2018, 1:19 PM
    Is it possible to define routes across multiple classes/files? Reading the docs https://ktor.io/servers/structure.html#deployment-and-applicationconf I think I'd have to create multiple top-level Routing functions, e.g
    fun Routing.customer() { get("/customer") {... } }
    and
    fun Routing.admin() { get("/admin") {...} }
    and then call each of them inside
    Application.mainModule() ...
    ? Any way of using classes instead of top-level functions?
    h
    m
    • 3
    • 7
  • a

    arocnies

    11/21/2018, 3:05 PM
    Anyone else seeing a 404 error on the Ktors Samples? https://ktor.io/samples/other/fullstack-mpp.html
    s
    o
    c
    • 4
    • 3
  • g

    gabin

    11/21/2018, 4:17 PM
    Thats bad that ktor client supports followsRedirects only for apache client. I’d love it to have multiplatform
    c
    e
    • 3
    • 33
Powered by Linen
Title
g

gabin

11/21/2018, 4:17 PM
Thats bad that ktor client supports followsRedirects only for apache client. I’d love it to have multiplatform
c

cy

11/21/2018, 4:18 PM
It should be
HttpRedirect
feature
https://ktor.io/clients/http-client/features/http-redirect.html
Most likely we need to improve it somehow to get it clear, deprecate or rename this parameter
// cc @e5l
g

gabin

11/21/2018, 4:20 PM
Sergey, I’ve tried val client = HttpClient() { followRedirects = true } but it doesn’t work.
c

cy

11/21/2018, 4:21 PM
Hm, followRedirects = false should disable it
g

gabin

11/21/2018, 4:21 PM
Exception in thread “main” io.ktor.client.features.SendCountExceedException: Max send count 20 exceeded
followRedirects = true
c

cy

11/21/2018, 4:22 PM
This means that you have infinite redirect somewhere
This feature is installed by default so you don't need to touch
followRedirects
setting
The documentation page need to be updated
g

gabin

11/21/2018, 4:26 PM
In postman I’m getting 301 Moved Permanently for my url, and if AutoRedirect is enabled I get 200 OK (as expected). Ktor gives me a crash https://pastebin.com/deaTEr44
c

cy

11/21/2018, 4:27 PM
This error means that there was too many redirects
g

gabin

11/21/2018, 4:27 PM
The crash leads to “runBlocking {” line
I’m wondering how Postman works then
c

cy

11/21/2018, 4:28 PM
Some sessions? cookies?
g

gabin

11/21/2018, 4:29 PM
yeah I see cookies in response. Might be a reason.
so I have to add cookie support to my client
e

e5l

11/21/2018, 4:33 PM
Maybe we should install the Cookies feature by default and provide the switch.
g

gabin

11/21/2018, 4:33 PM
Sergey, I took a page with test status https://httpstat.us/301 and ktor crashes on it also
it works in browser and in Postman
e

e5l

11/21/2018, 4:35 PM
Probably it triggers the ExpectSuccess feature. Could you provide the request example?
g

gabin

11/21/2018, 4:35 PM
Sure.
pasted to main chat
e

e5l

11/21/2018, 4:43 PM
Yep. If you use get<String> it expects the success status to convert the response
You could catch the exception to handle unusual situation, or use get<HttpResponse> to manually check the status code and receive body
g

gabin

11/21/2018, 4:48 PM
Ok, will try HttpResponse. The guide uses get<String> , that’s why I had it. https://ktor.io/clients/http-client/calls/requests.html
still no luck with status code http://take.ms/qYo7c
e

e5l

11/21/2018, 4:52 PM
Could you install HttpCookies?
val client = HttpClient {
    ...
    install(HttpCookies)
}
g

gabin

11/21/2018, 4:54 PM
Same. Crashes
👀 1
e

e5l

11/22/2018, 6:00 AM
Hi, @gabin. I've found out that it's a bug in the URL parser 🙂. The host was overridden, but the empty path is not. We fix it soon in ktor
1.0.1
release
g

gabin

11/22/2018, 8:23 AM
Hi Leonid. Thanks, will be waiting for new release 🎉 !
View count: 2