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

    brabo-hi

    12/27/2021, 11:48 PM
    Hi all, when using websocket client on ktor , how to listen when the connection is closed?
    a
    1 reply · 2 participants
  • h

    Hexa

    12/28/2021, 1:36 AM
    When using ktor client is it recommended to close the client after each request?
    a
    1 reply · 2 participants
  • s

    Sam Michael

    12/28/2021, 3:47 PM
    Having trouble updating to new Ktor dependencies, getting close by importing from plugins instead of features, but still having trouble installing contentNegotiation and json serialization, even following docs didn't seem to work as described there, :(
    Untitled.txt
    t
    a
    3 replies · 3 participants
  • c

    Chris C

    12/29/2021, 10:28 AM
    Hi all, I’m trying to use ktor 2.0.0-beta-1 to build a native server targeting Linux and Macos. All seems to work well until I try to include
    ktor-server-content-negotiation
    , then Gradle tells me
    No matching variant of io.ktor:ktor-server-content-negotiation:2.0.0-beta-1 was found
    . Looking at Maven Central, there doesn’t seem to be native versions of this library. Am I missing something?
    a
    e
    5 replies · 3 participants
  • j

    Jan

    12/29/2021, 6:48 PM
    Hello, I'm using ktor for Discord Bot stuff. But somehow sending requests sometimes takes over 5s seconds, and I'm not sure what I am doing wrong. I have a picture of a request log in the thread
    c
    8 replies · 2 participants
  • l

    Lucas Milotich

    12/29/2021, 8:05 PM
    Hello, does anyone know how to limit open connections with ktor-netty? currently I have a rate limiter but on route level but i’m still opening new connections for every new incoming request
    a
    2 replies · 2 participants
  • a

    Alex Styl

    12/30/2021, 12:08 PM
    How can I set the allowed upload size to ktor?
    1 reply · 1 participant
  • a

    Alexandre Brown

    12/30/2021, 3:31 PM
    Hello, is there a public roadmap for ktor 2.0? Should we expect the final release to be in January or what is the rough timeline?
    e
    7 replies · 2 participants
  • j

    Jan

    12/30/2021, 3:59 PM
    I don't know if my approach is wrong but I wrote a requester + ratelimiter for http requests but the problems is it is pretty CPU intense on my Raspberryp Pi I get like 100% CPU and on Windows (of course better cpu) also like 10%: https://www.toptal.com/developers/hastebin/vaxayabohi.kotlin
    3 replies · 1 participant
  • o

    Ovsyannikov Alexey

    12/31/2021, 11:04 AM
    Hello everybody and happy new year :) I wished to aks: is there any way to reduce result application size in JS? Currently I am getting 4 mb project with dce and included coroutines and serialization (and, of course, ktor)
    t
    a
    3 replies · 3 participants
  • j

    John O'Reilly

    01/01/2022, 2:20 PM
    Is there any "compatibility" type mode/option to use existing plugins with Ktor 2.0 or do they have to be migrated first? Am currently using
    KGraphQL
    (https://github.com/aPureBase/KGraphQL) but get following when updating to use Ktor
    2.0.0-beta-1
    Type mismatch.
    Required:
    Plugin<TypeVariable(P), TypeVariable(B), TypeVariable(F)>
    Found:
    GraphQL.Feature
    e
    a
    2 replies · 3 participants
  • m

    Morgan Pittkin

    01/01/2022, 11:02 PM
    I'm trying to add a requestId to my application log, and it seems using a combination of slf4j’s MappedDiagnosticContext and ThreadContextElement might do the trick. Does anyone know how I might configure ktor so that I can customize the coroutine context for handling requests? Thanks!
    r
    1 reply · 2 participants
  • i

    Igor Kolomiets

    01/02/2022, 4:48 AM
    Happy New Year everybody, I have surprising issue (code compiles!) with reified function in Ktor (Kotlin 1.6.10, Ktor 1.6.7, jvmTarget = “1.8”): https://gist.github.com/ikolomiets/689519a10f6f0a289a2ab2c06df710c1
    @Serializable
    data class Age(val value: Int)
    
    @Serializable
    data class Update<T>(val old: T, val new: T)
    
    fun main() {
        embeddedServer(Netty, port = 8080) {
            install(ContentNegotiation) {
                json()
            }
            routing {
                update<Age>()
            }
        }.start(wait = true)
    }
    
    inline fun <reified T> Route.update() {
        post("/") {
            val update = call.receive<Update<T>>()
            <http://application.log.info|application.log.info>("XXX update={}", update)
            call.respond(HttpStatusCode.OK, "OK")
        }
    }
    Trying
    % curl -v -H "Content-Type: application/json" -POST <http://localhost:8080/|http://localhost:8080/> -d '{"old":{"value":1},"new":{"value":2}}'
    makes Ktor throw:
    java.lang.UnsupportedOperationException: This function has a reified type parameter and thus can only be inlined at compilation time, not called directly.
    I found similar issue https://youtrack.jetbrains.com/issue/KTOR-582 that was identified as Kotlin compiler’s issue and eventually resolved as Fixed. Could this be regression with Kotlin compiler again? If not, can somebody advise how to avoid this exception? My project really needs such generic
    Route.update()
    function. Thank you!
    a
    2 replies · 2 participants
  • a

    Artem Chepurnoy

    01/04/2022, 11:00 AM
    Hello, Using the
    ktor:2.0.0-beta-1
    on Android 5.0 I'm getting a crash:
    java.lang.NoSuchMethodError: No virtual method position(I)Ljava/nio/ByteBuffer; in class Ljava/nio/ByteBuffer; or its super classes (declaration of 'java.nio.ByteBuffer' appears in /system/framework/core-libart.jar)
            at io.ktor.utils.io.bits.MemoryJvmKt.sliceSafe(MemoryJvm.kt:212)
            at io.ktor.utils.io.bits.Memory.slice-87lwejk(MemoryJvm.kt:48)
    explained here https://jira.mongodb.org/browse/JAVA-2559 Is the ktor 2.0 still compatible with Android 5.0+ or not anymore?
    a
    a
    2 replies · 3 participants
  • p

    phldavies

    01/04/2022, 11:12 AM
    Is there any way to still obtain the
    TestApplicationEngine
    when using the new
    testApplication
    API (and is there any link to the 2.0 docs anywhere? I can’t seem to find anything to help navigating the new APIs)
    d
    r
    10 replies · 3 participants
  • e

    edwinRNDR

    01/04/2022, 1:16 PM
    Is there a way to set
    cookie.extensions["SameSite"] = "None; Secure"
    without the semicolon being escaped in the cookie output?
    h
    2 replies · 2 participants
  • n

    nordiauwu

    01/04/2022, 2:59 PM
    Why isn't ktor-client using Dispatchers.IO?
    r
    h
    9 replies · 3 participants
  • e

    Elliot Barlas

    01/04/2022, 7:56 PM
    Hi folks, I think I found my issue. Thanks for being a sounding board!
    j
    5 replies · 2 participants
  • b

    brabo-hi

    01/05/2022, 8:25 AM
    Hi, where could we find the doc of ktor 2.0
    m
    l
    3 replies · 3 participants
  • r

    Rescribet

    01/05/2022, 8:47 AM
    Previously I built ktor docker images by using the installDist task, but after switching to multiplatform the
    lib/<projectname>-<version>.jar
    file has disappeared and running fails with an error:
    Exception in thread "main" java.lang.IllegalArgumentException: Neither port nor sslPort specified. Use command line options -port/-sslPort or configure connectors in application.conf
    I’ve tried reproducing by using the (CIO) ‘full stack web application’ project generator which basically fails with the same error, since it doesn’t use HOCON:
    Caused by: java.lang.ClassNotFoundException: com.test.fullstack.application.ServerKt
    b
    14 replies · 2 participants
  • b

    bsimmons

    01/05/2022, 10:48 PM
    Hey all, I'm wondering if there is a drop a connection call for a malformed request on ktor server? Like complete drop, I don't even want to send a 404 response back. Is this possible?
    j
    a
    5 replies · 3 participants
  • c

    Chris C

    01/06/2022, 5:41 PM
    Just found this bug in beta-1 (also applies to
    appendIfNameAndValueAbsent()
    )
    public fun StringValuesBuilder.appendIfNameAbsent(name: String, value: String): StringValuesBuilder = apply {
        if (!contains(name)) return@apply
        append(name, value)
    }
    I think that
    if
    should be inverted
    h
    r
    6 replies · 3 participants
  • b

    brabo-hi

    01/06/2022, 10:50 PM
    Hi, when using
    install(Logging)
    how can we log request and response body
    i
    2 replies · 2 participants
  • c

    Chris C

    01/07/2022, 12:21 PM
    Hi, the below test is throwing
    java.lang.IllegalArgumentException: List has more than one element
    because there are two values in the Accept header. Removing jackson fixes it, but I was hoping to use the same client for json responses too. Is this possible? I’m using 2.0.0-beta-1.
    class AcceptTest {
        private val readmeContentType = ContentType.parse("application/vnd.github.v3.html")
    
        @Test
        fun acceptTest() {
            val client = HttpClient() {
                install(ContentNegotiation) {
                    jackson {  }
                }
            }
            val readme: String = runBlocking {
                client.get("<https://api.github.com/repos/ktorio/ktor/readme>") {
                    header(HttpHeaders.Accept, readmeContentType)
                }.body()
            }
            println(readme)
        }
    }
    ➕ 1
    r
    10 replies · 2 participants
  • j

    jozefdransfield

    01/07/2022, 1:43 PM
    Can anyone advise if there is a clean way to get a publisher<bytebuffer> from a ktor call object? I have kotlinx.coroutines.reactive and it can turn a flow into a publisher but I can't find anything for a channel?
    a
    2 replies · 2 participants
  • j

    Jan

    01/07/2022, 11:39 PM
    What happens to this when it can't connect to the websocket? Does it throw an exeption or something?
    socket = http.webSocketSession(
                    generateWebsocketURL(
                        config.encoding,
                        config.compression
                    )
                ) { timeout { this.connectTimeoutMillis = 5000; this.socketTimeoutMillis = 2 * 60 * 1000 } }
    4 replies · 1 participant
  • s

    saket

    01/08/2022, 1:00 AM
    Has anyone tried running a ktor server on android with v2.0? I'm seeing that ktor isn't able to server any incoming requests on my side.
    n
    4 replies · 2 participants
  • r

    Rahul Rawat

    01/08/2022, 3:35 PM
    Been trying to make a ktor server but unable to understand why the response is escaping string values like the following
    {
      "address": {
        "id": 1,
        "firstname": "\"Rahul\"",
        "lastname": "\"Rawat\"",
        "address1": "\"Address1\"",
        "address2": "\"Address2\"",
        "city": "\"City\"",
        "zipCode": "\"ZipCode\"",
        "phone": "\"80808080\"",
        "state_name": "\"State\"",
        "alternative_phone": "\"Alternative\"",
        "company": "\"Company\"",
        "state_id": 1,
        "country_id": 2
      }
    }
    My server looks like the following
    install(ContentNegotiation) {
                json(Json {
                    prettyPrint = true
                    isLenient = true
                })
            }
    Please someone help.
    d
    7 replies · 2 participants
  • a

    Arnab

    01/10/2022, 1:57 PM
    Is there anyone who knows of a guide on how to build a readiness/liveness endpoint for your ktor application? Is it as simple as configuring a singleton to respond with
    200
    or
    503
    ?
    s
    2 replies · 2 participants
  • r

    Rescribet

    01/11/2022, 4:11 PM
    Minor nuisance still present in ktor 2:
    Url
    vs
    URLBuilder
    😕
    ➕ 3
    m
    b
    8 replies · 3 participants
Powered by Linen
Title
r

Rescribet

01/11/2022, 4:11 PM
Minor nuisance still present in ktor 2:
Url
vs
URLBuilder
😕
➕ 3
Though I certainly get the major nuisance it’ll be to refactor this in large code bases 😅
m

Matteo Mirk

01/11/2022, 5:03 PM
Do the two classes coexist?
r

Rescribet

01/12/2022, 12:04 AM
@Matteo Mirk Yes,
URLBuilder
produces
Url
objects
m

Matteo Mirk

01/12/2022, 11:03 AM
I see, so you would like to have just one class to build and represent URLs?
The builder could be an usual companion object inside
Url
probably…
b

Ben Woodworth

01/12/2022, 10:22 PM
I think he means the casing, URL vs Url. (At least I think that's a nuisance. Kotlin's coding conventions suggests UrlBuilder casing I'm pretty sure)
m

Matteo Mirk

01/13/2022, 9:06 AM
Oh I see, thanks
r

Rescribet

01/15/2022, 6:20 PM
Oh, yeah I meant the casing inconsistency
👍 1
View count: 3