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

    neil

    11/01/2019, 11:37 PM
    curl -X GET -I <http://internal-sedna-LoadB-LZRRIJ6EII57-813909172.us-west-2.elb.amazonaws.com:8000/indexer/2019-11-01/_status|internal-sedna-LoadB-LZRRIJ6EII57-813909172.us-west-2.elb.amazonaws.com:8000/indexer/2019-11-01/_status>
    HTTP/1.1 200 OK
    Date: Fri, 01 Nov 2019 23:36:51 GMT
    Content-Type: application/json; charset=UTF-8
    Content-Length: 53
    Connection: keep-alive
    Server: Application/debug ktor/debug
    • 1
    • 2
  • c

    coder82

    11/04/2019, 11:31 AM
    I want to Cbor.dump a class and I need to pass TestClass.serializer(), but the type I receive is Any, is there a way to get that TestClass.serializer() at runtime without testing the type with when/is? But it looks like to me there is no way to do that as .dump requires the <T> at compile time
    d
    • 2
    • 36
  • n

    Nikky

    11/05/2019, 12:46 PM
    i am trying to use kotlin-frontend in a multiplatform project and ktor seems to be blocking it because it tries to find it in npm.. is there any way around this?
    npm ERR! No valid versions available for ktor-ktor-client-core
    s
    • 2
    • 2
  • s

    sendoav

    11/06/2019, 8:30 AM
    some calls are correctly received in the API and the HTTPMethod is correctly processed as GET Method, but other times the same call is catched in the API and the HttpMethod is “T”
    e
    • 2
    • 4
  • b

    bitkid

    11/07/2019, 12:47 PM
    hi! did anyone try using https://github.com/derveloper/kotlin-openapi3-dsl with ktor? any other attempts to generate openapi specs from the location API?
    • 1
    • 1
  • j

    JoakimForslund

    11/07/2019, 2:47 PM
    What is the recommended way to forward http/https trafic from ktor server to another server?
    • 1
    • 1
  • m

    martin.petrulak

    11/08/2019, 11:01 AM
    When i call both endpoins and my serializer looks like this (check order )
    register(CocktailIngredientMatrix.serializer().list)
    register(Ingredient.serializer().list)
    I get error from
    /cocktailIngredientMatrix
    endpoint
    RESPONSE <http://10.0.2.2:8080/cocktailIngredientMatrix> failed with exception: kotlinx.serialization.json.JsonDecodingException: Invalid JSON at 23: Encountered an unknown key cocktailID
    When i change thh order to :
    register(Ingredient.serializer().list)
     register(CocktailIngredientMatrix.serializer().list)
    I get following error :
    RESPONSE <http://10.0.2.2:8080/ingredients> failed with exception: kotlinx.serialization.json.JsonDecodingException: Invalid JSON at 41: Encountered an unknown key name
    e
    • 2
    • 5
  • t

    tylerwilson

    11/08/2019, 3:42 PM
    I am using Ktor on the client side, using
    Parameters.apply { append(key, value) }
    issue is that it is encoding spaces as ‘+’, whereas I need then as ‘%20’. Anybody know if there is a way to adjust this? Or perhaps (like Retrofit) there could be an ‘appendEncoded()’ type call? Thank you!
    • 1
    • 1
  • s

    Shan

    11/11/2019, 12:11 AM
    Has anyone implemented a mp project that handles offline errors/timeout errors (not http status codes) in a result type with Ktor?
    j
    f
    • 3
    • 7
  • n

    nrobi

    11/11/2019, 11:17 AM
    Hey, I’m using https://github.com/orangy/squash/tree/master/squash-core/src/org/jetbrains/squash for the db connection. I didn’t find any documentation regarding foreign keys, could anyone pin-point me in the right direction?
    a
    o
    a
    • 4
    • 4
  • j

    JoakimForslund

    11/11/2019, 9:22 PM
    Hi, tried to add ktor 1.2.5 in a multiplatform project(Using kotlin 1.3.50), which uses common, jvm and js targets and has the ktorClient attached as dependency. Now, I'm using dceJS to make everything small and neat. In order to make any sort of headroom with the
    kotlinNpmInstall
    , I had to add:
    implementation(npm("bufferutil", "4.0.1"))
    implementation(npm("utf-8-validate", "5.0.2"))
    implementation(npm("text-encoding", "0.7.0"))
    and add an file in the webpack.config.d folder containing:
    config.node = { fs: 'empty' };
    Now dceJs complains about: error: duplicate target file will be created for 'E:\gloot\glootxr\build\js\node_modules\node-gyp-build\index.js' and 'E:\gloot\glootxr\build\js\node_modules\bufferutil\index.js' The code using ktor is being written in common Any pointers on how to fix this?
    • 1
    • 1
  • k

    Kurt Renzo Acosta

    11/13/2019, 8:16 AM
    Hello. Anyone experiencing issues with the default response validator? Ktor can't seem to catch my 404 errors.
    e
    • 2
    • 3
  • j

    jeggy

    11/13/2019, 8:58 PM
    are there any examples on how to create a ktor
    Feature
    which would add a route to the RoutingFeature?
    b
    • 2
    • 4
  • w

    wilyarti

    11/15/2019, 7:56 AM
    I want to launch 10 concurrent http client requests at a time similar to this: https://ktor.io/clients/index.html But I am having problems with errors killing the parent coroutine and all the children. Does anyone have an example of a work/children coroutines with error handling?
    m
    • 2
    • 2
  • j

    Jørund Amsen

    11/15/2019, 8:54 AM
    Is there a possibility to allow several connectors on the MainEngine-configs? As it is now, they only allows one https and one http connector. However we use a different port for our metrics so that we don't need to expose it outside Kubernetes. The way it's been solved now is a full-copy of the EngineMain-class and
    commandLineEnvironment()
    as we use almost all the default config there. Or differently asked; is there a particular reason why you don't support several connectors in the MainEngine/commandLineEnvironment? 🙂
    m
    • 2
    • 1
  • r

    rocketraman

    11/15/2019, 6:56 PM
    The behavior of HTTP servers in the presence of these half-closed connections is... undefined {1], and most clients do not do it. [1] https://github.com/httpwg/http-core/issues/22
    • 1
    • 2
  • k

    kevin.cianfarini

    11/16/2019, 6:38 PM
    any idea why the ktor client would be messing with a URL encoded param list? My request looks like this
    <https://torrent.ubuntu.com/announce?uploaded=0&downloaded=0&compact=1&info_hash=%65%14%5e%d4%d7%45%cf%c9%3f%5f%fe%34%92%e9%cd%e5%4b%55%7d%9f&peer_id=-CR0001-012345678901&port=6998&left=2082816000>
    but when I inspect the request in ktor via
    HttpClientCall#request#url
    it shows this
    <https://torrent.ubuntu.com/announce?uploaded=0&downloaded=0&compact=1&info_hash=e%14%5E%EF%BF%BD%EF%BF%BDE%EF%BF%BD%EF%BF%BD%3F_%EF%BF%BD4%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BDKU%7D%EF%BF%BD&peer_id=-CR0001-012345678901&port=6998&left=2082816000>
    e
    • 2
    • 2
  • p

    PHondogo

    11/16/2019, 7:43 PM
    Hello! What is the best practice to use HttpClient? Is it normal to create singelton instanse of it and use for the application lifecycle? Or I should create one for each call?
    e
    • 2
    • 2
  • a

    Animesh Sahu

    11/17/2019, 2:24 PM
    How to start embedded server without blocking the thread? Using coroutines
    e
    • 2
    • 2
  • j

    Jonathan Mew

    11/18/2019, 2:29 PM
    Ktor client (Apache) seems to have got into a bad state - any likely causes? Stacktrace attached.
    r
    e
    • 3
    • 19
  • r

    Ran Magen

    11/19/2019, 12:19 AM
    Hey, has anyone implemented graceful shutdowns with Ktor? I'm looking for a way to "drain" ongoing requests before the process shuts down after being sent a
    SIGTERM
    . I can implement this myself, though if there's already a commonly used feature, I'd opt to not re-invent the wheel. My general idea is to set some boolean like
    stopRequested
    when getting a
    SIGTERM
    and maintain another
    var active: Int
    with the current number of active requests similar to https://github.com/ktorio/ktor/blob/master/ktor-features/ktor-metrics/jvm/src/io/ktor/metrics/dropwizard/DropwizardMetrics.kt#L22 so when that number hits 0 and
    stopRequested
    is true, only then finish the process.
    n
    • 2
    • 8
  • d

    darkmoon_uk

    11/19/2019, 5:29 AM
    Any word on the imminence of a Ktor companion release to 1.3.60?
    r
    • 2
    • 1
  • d

    darkmoon_uk

    11/19/2019, 5:29 AM
    Ktor 1.2.5 + Kotling 1.3.60 = 😞
    😢 3
    r
    t
    • 3
    • 6
  • h

    Hexa

    11/19/2019, 6:32 PM
    anyone seen this error before?
    Caused by: java.lang.IllegalArgumentException: Response pipeline couldn't transform 'class java.util.Collections$SingletonMap' to the OutgoingContent
    	at io.ktor.server.engine.BaseApplicationResponse$Companion$setupSendPipeline$1.invokeSuspend(BaseApplicationResponse.kt:271)
    	at io.ktor.server.engine.BaseApplicationResponse$Companion$setupSendPipeline$1.invoke(BaseApplicationResponse.kt)
    	at io.ktor.util.pipeline.SuspendFunctionGun.loop(PipelineContext.kt:268)
    	at io.ktor.util.pipeline.SuspendFunctionGun.access$loop(PipelineContext.kt:67)
    	at io.ktor.util.pipeline.SuspendFunctionGun.proceed(PipelineContext.kt:141)
    	at io.ktor.util.pipeline.SuspendFunctionGun.execute(PipelineContext.kt:161)
    	at io.ktor.util.pipeline.Pipeline.execute(Pipeline.kt:27)
    n
    s
    • 3
    • 3
  • t

    Thomas

    11/20/2019, 8:52 PM
    How can you read the response in the
    scope.receivePipeline.intercept
    lambda without closing the original, so the pipeline can continue as normal?
    • 1
    • 1
  • n

    nrobi

    11/21/2019, 7:30 AM
    Hey, when adding
    kodein
    to
    ktor
    , :gradle: fails to resolve
    kodein-di-framework-ktor-server-jvm:6.3.4
    . However it doesn’t have any problem with
    kodein-di-generic-jvm
    . Anyone with a similar issue?
    m
    • 2
    • 2
  • d

    darkmoon_uk

    11/21/2019, 7:46 AM
    Does Ktor CI publish to any pre-release repository where I can access,
    1.3.0-beta-2-SNAPSHOT
    - which master was upgraded to around 12 hours ago? It's not listed on their VCS page as far as I can see.
    • 1
    • 2
  • m

    Matthias R

    11/21/2019, 4:59 PM
    Hey guys, I am basically doing a post request with ktor httpClient and I get back a HttpResponse successfully. With that I can see the response status and headers but I cannot see the body. How can I find the body?
    j
    • 2
    • 2
  • a

    Animesh Sahu

    11/22/2019, 11:16 AM
    Somebody tried build today, i'm having some issues building my app https://github.com/ktorio/ktor/issues/1455
    c
    • 2
    • 3
  • j

    Jørund Amsen

    11/22/2019, 11:28 AM
    So I'm trying to adapt some javax.servlet.Filter to be used in a interceptor. However it uses thing such as ServletRequest/Response. Are these available somehow? Or does ktor build on someting different?
    c
    • 2
    • 51
Powered by Linen
Title
j

Jørund Amsen

11/22/2019, 11:28 AM
So I'm trying to adapt some javax.servlet.Filter to be used in a interceptor. However it uses thing such as ServletRequest/Response. Are these available somehow? Or does ktor build on someting different?
c

cy

11/22/2019, 11:30 AM
It is available but not recommended because you loose portability
j

Jørund Amsen

11/22/2019, 11:31 AM
Yeah, I was afraid of that. Are there any known ways to work with javax Filters?
c

cy

11/22/2019, 11:31 AM
(call.request as ServletApplicationRequest).servletRequest
same for response
What filter do you need to adopt?
j

Jørund Amsen

11/22/2019, 11:32 AM
In this case it's an internally made logging and access filter. We've mostly used Spring for now, and a lot of former work would be unusable with Ktor
c

cy

11/22/2019, 11:32 AM
Ah, may be it is slightly more difficult because of routing...
j

Jørund Amsen

11/22/2019, 11:32 AM
How so?
c

cy

11/22/2019, 11:36 AM
Right, routing wraps application calls to provide
route
property so the original call is hidden
However, it you intercept before routing, the code above should work well. Otherwise, you need more tricks
j

Jørund Amsen

11/22/2019, 11:38 AM
Yeah, that was my intention at least. I'll see if I can get it to work. Still way out on a limb when it comes to my understanding of Ktor. Thanks for the quick respons!
c

cy

11/22/2019, 11:38 AM
The idea is to hide the underlying engine details, so you can run your app on any engine
j

Jørund Amsen

11/22/2019, 11:38 AM
Oh, one more thing, while I have you here, heh. https://kotlinlang.slack.com/archives/C0A974TJ9/p1573808069261300 Could I possibly open an issue on this? Multiple connectors support, that is
c

cy

11/22/2019, 11:39 AM
for example, run on netty locally and deploy as war to Tomcat for prod
j

Jørund Amsen

11/22/2019, 11:39 AM
Yeah, that makes sense..
But are these servlet-classes engine-spesific?
c

cy

11/22/2019, 11:40 AM
Yes, of course
This is why you need to cast to adopt to javax.servlet
j

Jørund Amsen

11/22/2019, 11:40 AM
Oh shit, yeah I just checked the inheritance. My bad
c

cy

11/22/2019, 11:40 AM
You don't have these classes with no ktor-server-servlet dependency
j

Jørund Amsen

11/22/2019, 11:41 AM
Thanks, that actually clears things up a lot
c

cy

11/22/2019, 11:42 AM
Regarding connectors.. I see no reason for not supporting multiple connectors in config. We just provided two for plain and TLS/SSL since it is the most useful case
j

Jørund Amsen

11/22/2019, 11:43 AM
I don't mind attempting a PR or issue, whatever is best for you. Is there anything in particular I should consider?
c

cy

11/22/2019, 11:44 AM
If you think of PR, a change should be backward-compatible so older configuration files should keep working
j

Jørund Amsen

11/22/2019, 11:45 AM
Yep. Would a "unlimited" amount of connectors be allowed, or are there specific types of connectors, similar to TLS(or metrics?) that should be allowed?
c

cy

11/22/2019, 12:00 PM
There is no limit, only two kinds are supported: pure HTTP and HTTPS
j

Jørund Amsen

11/22/2019, 12:00 PM
Yeah, it was more a question of "a metrics port", or "however many more ports you want"
c

cy

11/22/2019, 12:02 PM
Of course you may configure a dedicated connector for the specific purpose such as administration
However, you need to configure your routing to filter by port, otherwise all ports will behave the same
j

Jørund Amsen

11/22/2019, 12:04 PM
Yep, I kind of already adapted the EngineMain in our app to do something similar. From what I understand, the port under
deployment{}
seems to be the default if I don't use any
port(){}
Is that correct?
c

cy

11/22/2019, 12:09 PM
This is no longer true. Either port or sslPort should be specified
https://github.com/ktorio/ktor/blob/master/ktor-server/ktor-server-host-common/jvm/src/io/ktor/server/engine/CommandLine.kt#L129
j

Jørund Amsen

11/22/2019, 12:09 PM
Oh, is this a recent change?
Oh, no I mean
When I just do a normal routing
Similar to...
fun Routing.metrics() {
    port(8181) {
        get("/prometheus") {
            call.respondText { prometheusMeterRegistry.scrape() }
        }
    }
In this case, I spesify the port. However, if I don't spesify the port here, it defaults to the port in
deployment {
    port = 8080
}
So it seems there is a "default" connector, however many connectors I have
Does that make sense?
c

cy

11/22/2019, 12:12 PM
These are irrelevant. The
port
function just adds a filter node
If no
port()
in routing then no filter applied so all ports are handled
j

Jørund Amsen

11/22/2019, 12:13 PM
Aaaah, okay yeah that makes a lot more sense
Thanks for being awesome Sergey! 😄 Keep rocking
c

cy

11/22/2019, 12:13 PM
irrelevant -> independent
So, if one deploy into a servlet container, you can't control connectors at all
j

Jørund Amsen

11/22/2019, 12:14 PM
Yeah
c

cy

11/22/2019, 12:14 PM
but you can add port routing anyway
j

Jørund Amsen

11/22/2019, 12:14 PM
That makes sense
c

cy

11/22/2019, 12:15 PM
So, a routing is a decision tree. Every node of that tree may have a predicate
So when a call is started, it comes though the pipeline, then a routing is called (if installed, it's actually optional). If routing finds a node that matches, the corresponding handler is invoked
j

Jørund Amsen

11/22/2019, 12:20 PM
I see
View count: 8