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

    Lucas León

    02/22/2022, 3:17 AM
    I’m trying to add ktor client to an Spring Boot Maven Project but IntelliJ does not detect the dependency. This is my pom
    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="<http://maven.apache.org/POM/4.0.0>" xmlns:xsi="<http://www.w3.org/2001/XMLSchema-instance>"
             xsi:schemaLocation="<http://maven.apache.org/POM/4.0.0> <https://maven.apache.org/xsd/maven-4.0.0.xsd>">
        <modelVersion>4.0.0</modelVersion>
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.6.3</version>
            <relativePath/> <!-- lookup parent from repository -->
        </parent>
        <groupId>com.example</groupId>
        <artifactId>demoproject</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <name>demoproject</name>
        <description>demoproject</description>
        <properties>
            <java.version>1.8</java.version>
            <kotlin.version>1.6.10</kotlin.version>
            <ktor.version>1.6.7</ktor.version>
        </properties>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-webflux</artifactId>
            </dependency>
            <dependency>
                <groupId>com.fasterxml.jackson.module</groupId>
                <artifactId>jackson-module-kotlin</artifactId>
            </dependency>
            <dependency>
                <groupId>io.projectreactor.kotlin</groupId>
                <artifactId>reactor-kotlin-extensions</artifactId>
            </dependency>
            <dependency>
                <groupId>org.jetbrains.kotlin</groupId>
                <artifactId>kotlin-reflect</artifactId>
            </dependency>
            <dependency>
                <groupId>org.jetbrains.kotlin</groupId>
                <artifactId>kotlin-stdlib-jdk8</artifactId>
            </dependency>
            <dependency>
                <groupId>org.jetbrains.kotlinx</groupId>
                <artifactId>kotlinx-coroutines-reactor</artifactId>
            </dependency>
            <dependency>
                <groupId>io.ktor</groupId>
                <artifactId>ktor-client-core</artifactId>
                <version>${ktor.version}</version>
            </dependency>
            <dependency>
                <groupId>io.ktor</groupId>
                <artifactId>ktor-client-cio</artifactId>
                <version>${ktor.version}</version>
            </dependency>
            <dependency>
                <groupId>io.ktor</groupId>
                <artifactId>ktor-client-serialization</artifactId>
                <version>${ktor.version}</version>
            </dependency>
    
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>io.projectreactor</groupId>
                <artifactId>reactor-test</artifactId>
                <scope>test</scope>
            </dependency>
        </dependencies>
    
        <build>
            <sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
            <testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
                <plugin>
                    <groupId>org.jetbrains.kotlin</groupId>
                    <artifactId>kotlin-maven-plugin</artifactId>
                    <configuration>
                        <args>
                            <arg>-Xjsr305=strict</arg>
                        </args>
                        <compilerPlugins>
                            <plugin>spring</plugin>
                        </compilerPlugins>
                    </configuration>
                    <dependencies>
                        <dependency>
                            <groupId>org.jetbrains.kotlin</groupId>
                            <artifactId>kotlin-maven-allopen</artifactId>
                            <version>${kotlin.version}</version>
                        </dependency>
                    </dependencies>
                </plugin>
            </plugins>
        </build>
    
    </project>
    An this is what I get :
    i
    a
    • 3
    • 4
  • a

    André Martins

    02/22/2022, 10:51 AM
    Hey, I’m using ktor-client-cio and trying to figure out if there is anyway to change dns resolver instead of using java network, I need to setup a timeout for the resolution and a retry count. Any ideias on where to look? (Seen this)
    a
    • 2
    • 10
  • r

    Richie Bresnan

    02/22/2022, 5:29 PM
    With ktor logging headers (
    LogLevel.HEADERS
    ) application/customer secrets in the auth header are logged as below. I’d like to redact these secrets, as
    ******
    . Has anyone found a non-invasive way of doing this?
    [***] 2022-02-22 08:59:45.641 [main] INFO  io.ktor.client.HttpClient - METHOD: HttpMethod(value=GET)
      [***] 2022-02-22 08:59:45.641 [main] INFO  io.ktor.client.HttpClient - COMMON HEADERS
      [***] 2022-02-22 08:59:45.641 [main] INFO  io.ktor.client.HttpClient - -> Accept: application/json
      [***] 2022-02-22 08:59:45.641 [main] INFO  io.ktor.client.HttpClient - -> Accept-Charset: UTF-8
      [***] 2022-02-22 08:59:45.641 [main] INFO  io.ktor.client.HttpClient - -> Authorization: token my_super_secret_token_that_I_want_to_redact
    m
    • 2
    • 3
  • d

    dany giguere

    02/22/2022, 9:07 PM
    which returns something like :
    "errors": {
       "title": ["The title must contain at least 20 characters"],
       "body": ["The body must contain at least 20 characters"]
    }
    m
    • 2
    • 10
  • j

    J Man

    02/22/2022, 11:40 PM
    When I add a watch to my application.conf I get an error.
    a
    • 2
    • 1
  • j

    J Man

    02/23/2022, 12:47 AM
    a
    • 2
    • 3
  • h

    hhariri

    02/23/2022, 10:25 AM
    Something we’re working on to make it even easier for folks new to Ktor and the ecosystem. https://twitter.com/hhariri/status/1496430175332048896
    👍 6
    c
    • 2
    • 1
  • a

    André Martins

    02/23/2022, 12:17 PM
    Hello, does Ktor client reuse connections?
    a
    • 2
    • 3
  • j

    Javier

    02/23/2022, 2:44 PM
    is it possible to get the
    expectedType
    in request or send pipelines?
    a
    • 2
    • 1
  • w

    Werner Guttmann

    02/23/2022, 3:08 PM
    HI; Ktor (1.6.7) provides a url {} dsl to facilitate building new urls based on e.g. incoming requests, etc. Unfortunately, this only returns the url as String; would it be possible to allow returning a Url instead of the String ?
    a
    • 2
    • 12
  • b

    Bartłomiej Gaweł

    02/23/2022, 5:44 PM
    Hi, anyone use Valiktor or Konform for request validation? I saw that the projects were updated a long time ago and I wonder it's still worth using them
    d
    • 2
    • 1
  • d

    dany giguere

    02/23/2022, 9:45 PM
    I’m creating a middleware and I’m wondering if I could make
    call
    available from it ? :
    fun Application.hasSignedUrlMiddleware() {
        routing {
            val uri = call.request.uri
    //        if(url doesn't have a signed url) {
    //            throw AuthorizationException("Sorry you are not authorized")
    //        }
        }
    }
    get("/posts") {
                hasSignedUrlMiddleware()
                call.respond(mapOf("posts" to postDAO.all()))
            }
    a
    • 2
    • 4
  • k

    Kiet

    02/24/2022, 3:34 AM
    Hey folks, I posted a multiplayer demo a few days ago which uses ktor websockets, I noticed that the memory usage goes up slowly overtime on google cloud run for some reason. From looking at my code, it's unclear to me where the memory leak is coming from, I was wondering if someone could please review my code? https://github.com/Kietyo/KorgeMultiplayerDemo/tree/master/Server
    e
    • 2
    • 3
  • i

    ishitatsuyuki

    02/24/2022, 10:42 AM
    Why was the single page plugin removed in https://github.com/ktorio/ktor/pull/2824? Does that mean it's not ready for inclusion in EAP yet?
    e
    d
    • 3
    • 10
  • i

    ishitatsuyuki

    02/24/2022, 12:40 PM
    The SPA plugin doesn't actually work 😞 opened https://youtrack.jetbrains.com/issue/KTOR-3944
    e
    • 2
    • 1
  • i

    ishitatsuyuki

    02/24/2022, 2:05 PM
    just realized that ktor eap-310+ depends on Kotlin nightly? didn't realize this until I ditched spring since it force downgrades the dependency
    Could not find org.jetbrains.kotlin:kotlin-stdlib-common:1.6.20-M1-106.
    and things like this for a full screen spam.
    a
    • 2
    • 2
  • j

    jean

    02/24/2022, 3:13 PM
    I’m declaring my server with the following :
    fun main() {
        embeddedServer(
            factory = CIO,
            environment = applicationEngineEnvironment {
                config = HoconApplicationConfig(ConfigFactory.load())
                connector {
                    port = 8080
                }
                module(Application::module)
            },
        ).start(wait = true)
    }
    
    fun Application.module() {
        val jwtValues = jwtValues(environment)
        val pbkdf2Values = pbkdf2Values(environment)
        val database = SamkjoringDatabase()
    
        configureRouting(jwtValues, pbkdf2Values, database)
        configureSerialization()
        configureSecurity()
        configureTemplate()
    }
    and my
    resources/application.conf
    jwt {
        secret = "7lgeBk06UhkLRLFDhQn3"
        issuer = "<http://0.0.0.0:8080/>"
        audience = "<http://0.0.0.0:8080/login>"
        realm = "Access to 'login'"
    }
    pbkdf2 {
        salt = "qdQk4P2TNvHc"
        iterations = "10000"
        keyLength = "512"
    }
    But I get the error
    Exception in thread “main” io.ktor.config.ApplicationConfigurationException: Property jwt.secret not found.
    at io.ktor.config.HoconApplicationConfig.property(HoconApplicationConfig.kt:15)
    at no.samkjoring.plugins.auth.JwtKt.jwtValues(jwt.kt:27)
    What am I missing here?
    a
    • 2
    • 4
  • n

    Nikky

    02/25/2022, 2:29 AM
    trying to use ktor-server on kotlin-native.. got everything i care about working .. but StatusPages seems to not work the callbacks for handling exceptions get executed.. but
    call.respondText(text = cause.message, status = HttpStatusCode.InternalServerError)
    seems to not trigger a http response and the request is just hanging
    a
    • 2
    • 3
  • j

    Jason Han

    02/25/2022, 7:16 AM
    Hi all, I'm hoping there's a way to do this, but is there any way to authenticate all routes in an application without wrapping authenticate everywhere? We have an application that's structuring the routes
    routing {
      someRoute1()
      someRoute2()
      ...
      someRoute100()
    }
    with each group of routes in it's own file
    fun Application.someRoute1() {
      routing {
        route('/some/{place}') {
          head {
          }
          get {
          }
        }
      }
    }
    however, we now want to add authentication to all routes, but if we add the authenticate function to the first example,
    routing {
      authenticate {
        someRoute1()
        someRoute2()
        ...
        someRoute100()
      }
    }
    it doesn't seem like the individual route functions get the authenticate function. Is there a way to do this without manually editing each individual route file?
    i
    h
    • 3
    • 4
  • i

    ishitatsuyuki

    02/25/2022, 8:27 AM
    Has anyone managed to do auto-reload with
    embeddedServer
    ? There are two serious issues: 1. The documentation doesn't mention that the reloader only works if the
    module
    parammeter to
    embeddedServer
    refers to a function (if you use the lambda in attempt for simplicity, it doesn't work). 2. The server appears to break and start giving empty responses under some race condition, maybe if another HTTP request arrive during the restart? (still debugging)
    a
    • 2
    • 5
  • n

    Nikky

    02/25/2022, 3:25 PM
    can i define a custom logger for ktor ? specifically on native i would like to make this align:

    https://nikky.catgirl.host/i/x00fif8f.png▾

    it seems like i will have to copy the
    embeddedServer
    call chain and add a custom
    KtorSimpleLogger
    implementation
    a
    • 2
    • 3
  • r

    robnik

    02/25/2022, 10:18 PM
    I started a new project in IntelliJ - "multiplatform full stack web application". By default, it has a ktor route
    static("/static") { resources() }
    , which serves the compiled JS. Problem is: it serves all resources! Insecure, no? How do I change the gradle file to copy the compiled JS into a subdir? (More in thread)
    a
    • 2
    • 4
  • k

    Kedar

    02/27/2022, 1:43 AM
    I'm implementing authentication using JWT and new requirement of supporting Google/Facebook/Apple login may come very soon. Is there any easy way to build these using OAuth by keeping the existing JWT authentication for normal email/password login flows?
    i
    • 2
    • 1
  • j

    Joakim Forslund

    02/27/2022, 10:43 AM
    a
    • 2
    • 12
  • n

    Nikky

    02/27/2022, 12:22 PM
    in kotlin-native .. what is the correct way to start ktor so that i can shut it down from a signal handler? seems like doing
    server.start(wait = true)
    will just block my application completely when i call
    server.stop(500, 500)
    not sure why.. could it be that joining the jobs is blocking ? for now i am using this..
    server = embeddedServer(...)
    
    server.start(wait = false)
    
    while (true) {
        sleep(1)
    }
    and in the signal handler i call
    server.stop(500, 500)
    if anybody knows a cleaner solution.. would like to make this work better i also noticed.. if i use
    delay
    instead of sleep it will also continue to block..?
    h
    e
    • 3
    • 6
  • d

    dleuck

    02/28/2022, 4:10 AM
    We are about to start a financial news and analytics app project. The client is going to be Flutter, which we've successfully used before, and we've decided to use Kotlin for the backend. We are contemplating wether to use Ktor or Spring Boot + Kotlin. We are leaning toward Ktor because its idiomatically aligned with Kotlin and has a simple, consistent and concise set of APIs, but there is a larger community and more written about Spring Boot. Any advice on this decision (Ktor vs. Spring Boot + Kotlin)? There is a short but interesting conversation about this choice on Reddit: https://www.reddit.com/r/Kotlin/comments/pgfuhn/ktor_vs_spring_for_creating_an_api/
    i
    k
    • 3
    • 5
  • a

    Amin Bahiraei

    02/28/2022, 12:29 PM
    Hello, I’m trying to set contentType in
    defaultRequest
    but it crashesh in iOS, and when I wanna set
    contentType
    in post request, this exception raise
    I have also installed `ContentNegotation` and `json`
    Fail to serialize body. Content has type: class org.metatude.paxfa.auth.login.LoginEmailRequestDto, but OutgoingContent expected.
    If you expect serialized body, please check that you have installed the corresponding plugin(like `ContentNegotiation`) and set `Content-Type` header.
    a
    • 2
    • 3
  • b

    Bridgette Powell

    02/28/2022, 8:41 PM
    Hey is anyone here using the latest Intellij IDEA with the Ktor plugin? I’m using the 30 day trial that gives access to Ultimate, but it wont let me install the Ktor plugin b/c of a compatibility issue (see images)…If this is the case, where do I find the older build version?
    e
    v
    d
    • 4
    • 11
  • b

    Barry Fawthrop

    03/01/2022, 1:28 AM
    I have ktor client in an Android codebase. I have a single apiclient = HttpClient(okhttp) with multiple install() like install(logging). How can I turn logging on and off with a variable passed to apiclient. Like apiclient(true).post(url), thanks
    i
    • 2
    • 2
  • a

    Ankit Dubey

    03/01/2022, 6:00 AM
    Hi all, Wondering if we can call API synchronously using Ktor Engine. Actually, whenever I'm getting 401 Authorization Token Expired error, I've to call Login API implicitly from Authenticator. Now this api call need to be called synchronously as after getting login API response, i've to update the header with Auth Token and return the request again from authenticate method. Thanks
    i
    • 2
    • 2
Powered by Linen
Title
a

Ankit Dubey

03/01/2022, 6:00 AM
Hi all, Wondering if we can call API synchronously using Ktor Engine. Actually, whenever I'm getting 401 Authorization Token Expired error, I've to call Login API implicitly from Authenticator. Now this api call need to be called synchronously as after getting login API response, i've to update the header with Auth Token and return the request again from authenticate method. Thanks
i

ishitatsuyuki

03/01/2022, 6:15 AM
You don't have to call the APIs in a blocking way. Ktor interceptor can take suspend functions, see how AuthProvider does it. https://github.com/ktorio/ktor/blob/b5b59ca3ae61601e6175f334e6a1252609638e61/ktor-client/ktor-client-plugins/ktor-client-auth/common/src/io/ktor/client/plugins/auth/Auth.kt#L39 You also might want to block all other requests until the login is complete (and not send duplicate login requests), see https://github.com/ktorio/ktor/commit/9ea85698bca94113a71c65677ef6a1e1de379a07.
a

Ankit Dubey

03/01/2022, 6:15 AM
Thanks , let me check
View count: 1