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

    Antero Duarte

    07/30/2018, 9:33 AM
    Hi all, I've been working on a project where I'm using ktor and I'm implementing Oauth. I've implemented my own login system in the back of it and I'm using [ory/hydra](https://github.com/ory/hydra) as an oauth flow manager. My problem is that I've followed the Oauth implementation [tutorials](https://ktor.io/features/authentication/oauth.html) and have read the whole code for the Google Oauth example, but my principal from
    call.authentication.principal
    is always null and I don't know where to start in debugging it...
    d
    • 2
    • 21
  • k

    kluck

    07/31/2018, 8:54 AM
    Hello, I'm trying to authenticate via Active Directory using
    ldapAuthenticate
    , but I don't understand how I can use my "manager" binding along with a user search. In ktor, there seems to be only a
    userDNFormat
    String to configure the lookup. What am I doing wrong?
    📝 1
    ✅ 1
    c
    • 2
    • 2
  • t

    tipsy

    08/01/2018, 12:05 AM
    i don't really know ktor, but you could solve it by extracting the lambda to a function?
    get("/", ::dualHandler)
    post("/", ::dualHandler)
    ☝️ 1
    h
    • 2
    • 1
  • d

    dave08

    08/01/2018, 7:32 AM
    Can I use the Ktor client to receive a file with a simple
    get
    ?
    📝 1
    ✅ 1
    d
    e
    • 3
    • 30
  • c

    cy

    08/02/2018, 8:09 AM
    📣
    0.9.4-alpha-2
    has been published with experimental multiplatform (MPP) HTTP client (android + ios) support. See the reply for details. ❗ This is pre-release version
    🎉 14
    e
    k
    • 3
    • 3
  • m

    Matt

    08/02/2018, 8:56 AM
    val UnsupportedMediaType = HttpStatusCode(415, "Unsupported Media Type")
            val RequestedRangeNotSatisfiable = HttpStatusCode(416, "Requested Range Not Satisfiable")
            val ExceptionFailed = HttpStatusCode(417, "Exception Failed")
            val UpgradeRequired = HttpStatusCode(426, "Upgrade Required")
            val TooManyRequests = HttpStatusCode(429, "Too Many Requests")
            val RequestHeaderFieldTooLarge = HttpStatusCode(431, "Request Header Fields Too Large")
    I was wanting to use "422 Unprocessable Entity", but there isn't a constant for it in
    io.ktor.http.HttpStatusCode
    yet. Is it a case of "PRs welcome", or is there a deliberate reason not to include certain codes?
    c
    o
    • 3
    • 8
  • m

    Matt

    08/02/2018, 7:01 PM
    I guess this might do the job:
    get("*") {
                call.respond(HttpStatusCode.NotFound, etc)
            }
    Only matches if there is no more specific route, if I understand it correctly?
    o
    • 2
    • 5
  • b

    bdawg.io

    08/02/2018, 10:14 PM
    Does ktor come with a mechanism for properly building
    application/x-www-form-urlencoded
    strings from a map?
    ✅ 1
    📝 1
    o
    d
    • 3
    • 9
  • b

    bdawg.io

    08/02/2018, 10:15 PM
    I see that Parameters can be received from the
    request
    , but I’m trying to build and write them as a
    respond
    o
    • 2
    • 15
  • e

    enleur

    08/03/2018, 2:48 PM
    Is there any way to catch blocking code on Netty/CommonPool?
    b
    • 2
    • 1
  • b

    bdawg.io

    08/03/2018, 9:16 PM
    inline fun <T> T.scope(block: T.() -> Unit) {
        block()
    }
    it’s `T.run`/`T.apply` without a return value Edit: moved examples to thread to clean up channel feed Edit: renamed extension function from
    unit
    to
    scope
    👍 1
    • 1
    • 3
  • h

    Hamza

    08/04/2018, 12:11 AM
    is there anything on the install function and the list of “plugins” available? I want to read up on them
    a
    d
    • 3
    • 4
  • d

    Deactivated User

    08/07/2018, 12:27 AM
    📣 New Ktor Blog: https://ktor.io/blog
    🎉 8
    i
    • 2
    • 3
  • h

    hallvard

    08/07/2018, 6:16 AM
    Cool, @Deactivated User. But maybe you should change the title? Or is «Blog Template for Bootstrap» meant to be adequate?
    d
    • 2
    • 2
  • v

    vincent.brule

    08/07/2018, 11:11 AM
    Ok perfect, thank for your answers ! Do you think it’s possible to build my react project in the gradle build in ktor ?
    ✅ 1
    v
    a
    +2
    • 5
    • 7
  • n

    Nikky

    08/07/2018, 11:55 PM
    actually thats what i ended up doing.. not sure how well this will work..
    launch {
            while(true) {
               //do Work
                <http://log.info|log.info>("work complete")
                delay(4, TimeUnit.HOURS)
            }
        }
    a
    • 2
    • 4
  • h

    Hamza

    08/08/2018, 2:15 AM
    Any stuff on using ktor with native? No idea where to start
    d
    • 2
    • 3
  • d

    dave08

    08/08/2018, 6:26 AM
    Is there any reason why IDEA expression evaluator doesn't see
    call
    or
    this
    inside a Ktor route? Any workaround?
    g
    • 2
    • 7
  • a

    Albert

    08/08/2018, 8:41 AM
    I am trying to enable debug logging with Ktor but witout success. It stays on info:
    embeddedServer(Netty, 8080) {
            install(CallLogging) {
                level = Level.DEBUG
            }
            routing {
                get("/") {
                    println(log.isDebugEnabled)
                }
           }
    }.start(wait = true)
    log.isDebugEnabled is always returning
    false
    . Should
    install
    be invoked somewhere else? can't really find this in the documentation
    d
    • 2
    • 10
  • d

    dave08

    08/08/2018, 9:27 AM
    Is there an easy way to choose which logback.xml to use depending on Ktor Hocon configs or env. vars?
    • 1
    • 1
  • n

    nbdam

    08/08/2018, 4:04 PM
    how to load setup from application.conf when using embeddedServer ?
    f
    • 2
    • 1
  • z

    zpearce

    08/08/2018, 4:35 PM
    hey, ktor noob here. I'm thinking about adding a custom feature that will validate rest api dtos. I've read about pipelines and interceptors, but what I'm unclear on is the fact that this feature would be pretty dependent on coming after the content negotiation feature, since that's when deserialization happens. so two questions: 1) how do I make sure my interceptor happens at the correct time and 2) are there problems with receiving the request body twice (i.e. is there a stream involved somewhere that would need to be reset?)
    • 1
    • 1
  • h

    Hamza

    08/09/2018, 5:08 AM
    Can someone please give me a more beginner oriented explanation for CORS? I read up on it and watched some stuff but I just don't get it :*
    r
    f
    t
    • 4
    • 7
  • v

    vonox7

    08/09/2018, 3:45 PM
    Because 1 / 2 = 0, and we need at least one thread
    c
    • 2
    • 2
  • m

    Mohit Gurumukhani

    08/09/2018, 6:26 PM
    The latest update has android and ios clients for version 0.9.4-alpha-2. However, jvm client is available only in version 0.9.0-alpha-1. Is there a plan to support jvm version in the future?
    e
    • 2
    • 2
  • n

    nbdam

    08/10/2018, 11:48 AM
    ApplicationCall.respondBytes takes a single ByteArray. Is it possible to do 'vector' write by providing multiple array which should be written. I am trying to avoid buffer copying...
    📝 1
    ✅ 1
    e
    d
    • 3
    • 3
  • a

    Albert

    08/10/2018, 1:45 PM
    Anyone knows an OpenID (or OAuth2) provider (server) implementation/module for ktor? It seems if I want to use one now I always need a seperate service build in Spring Boot or Vert.X to accomplish this.
    a
    • 2
    • 3
  • a

    Antero Duarte

    08/10/2018, 2:03 PM
    Hi there, I'm using ktor with the apache async http client, and I'm sending some POST requests to a server that kept failing because they said the body was empty. After enabling debug logging, I can see the http client is sending the request in this format:
    DEBUG org.apache.http.wire - http-outgoing-0 >> "POST /the/endpoint HTTP/1.1[\r][\n]"
    DEBUG org.apache.http.wire - http-outgoing-0 >> "Content-Type: x-www-form-urlencoded[\r][\n]"
    DEBUG org.apache.http.wire - http-outgoing-0 >> "Accept: */*[\r][\n]"
    DEBUG org.apache.http.wire - http-outgoing-0 >> "Content-Length: 201[\r][\n]"
    DEBUG org.apache.http.wire - http-outgoing-0 >> "Host: localhost:8888[\r][\n]"
    DEBUG org.apache.http.wire - http-outgoing-0 >> "Connection: Keep-Alive[\r][\n]"
    DEBUG org.apache.http.wire - http-outgoing-0 >> "User-Agent: Apache-HttpAsyncClient/4.1.3 (Java/1.8.0_172)[\r][\n]"
    DEBUG org.apache.http.wire - http-outgoing-0 >> "[\r][\n]"
    DEBUG org.apache.http.wire - http-outgoing-0 >> "url_encoded=form_params&which_are=fine"
    Everything seems fine, but for some reason, the client is prepending a line before the form body, with just
    \r\n
    , which for some reason is tripping the server on the other end. I don't control the server I'm sending the request to, I don't know if an empty line before the body conforms to the HTTP Spec, but my question is, is there any way to avoid it? For completeness sake, the way I'm creating the request is as follows:
    ApacheHttpClient.request<HttpResponse> {
                            method = <http://HttpMethod.Post|HttpMethod.Post>
                            url { takeFrom("<http://some.url/the/endpoint>") }
                            headers.append("Content-Type", ContentType.Application.FormUrlEncoded.contentSubtype)
                            this.body = body.formUrlEncode()
                        }
    body is a
    List<Pair<String,String>>
    and
    .formUrlEncode
    is the extension method from ktor HttpUrlEncode.kt
    e
    c
    • 3
    • 25
  • m

    mp

    08/10/2018, 2:04 PM
    Isn't the extra
    \r\n
    what separates headers from the body?
    :yes: 1
    e
    • 2
    • 1
  • y

    Yuri

    08/10/2018, 9:05 PM
    @orangy yes, thanks. Any plans to add such
    ContentConverter
    as maven artifact similar to jackson one in the future?
    o
    • 2
    • 6
Powered by Linen
Title
y

Yuri

08/10/2018, 9:05 PM
@orangy yes, thanks. Any plans to add such
ContentConverter
as maven artifact similar to jackson one in the future?
o

orangy

08/10/2018, 9:08 PM
Is there any evidence that protobuf is frequently used like this?
y

Yuri

08/10/2018, 9:24 PM
like serialization format for client-server communication without using grpc?
o

orangy

08/10/2018, 9:44 PM
Nope, as a content type format for direct web requests. As far as I understand, it’s mostly used for some longer running connections, like Web Sockets or direct TCP connection, but I may be missing some important use case.
y

Yuri

08/10/2018, 10:18 PM
It is quite common usecase to migrate from Json to Proto in mobile projects in case of large amount of small objects passing to requests/responses. The reasons are simple - improved parsing performance, lower CPU usage than gson/jackson, fixed protocol, api versioning etc.
For example Retrofit (popular Android networking library) supported Proto3 converter more than a year ago
So it would be nice to be able to use (kotlin + retrofit + protobuf) on client side and (ktor + protobuf) on server side out of the box
View count: 2