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

    wouterdoeland

    10/12/2018, 2:28 PM
    Hi, is it possible to use a format other than JKS for TLS/HTTPS in Ktor?
    c
    • 2
    • 6
  • b

    bdawg.io

    10/12/2018, 4:55 PM
    Will there be a
    0.9.6
    release or is the plan to go straight for
    1.0
    with the Kotlin
    1.3
    GA coming up?
    o
    • 2
    • 2
  • o

    otakusenpai

    10/12/2018, 11:00 PM
    val r = socket.openReadChannel()
        println(r.readASCIILine())
    This line in the raw sockets section is outdated @ http://ktor.io/servers/raw-sockets.html
    📝 1
    ✅ 1
    c
    • 2
    • 1
  • j

    jasoet

    10/13/2018, 8:53 AM
    [Ktor-Client] Is there a way to get String version of Request Body even the body is supplied from Object and using JsonFeature? I have need to get the body and create signature from it and send it as headers.
    e
    • 2
    • 13
  • s

    schlan

    10/13/2018, 11:33 AM
    I was told that maybe somebody in this channel knows what's the issue here? tl;dr Trying to build an iOS framework with kotlin native and ktor.
    👀 1
    e
    c
    • 3
    • 4
  • o

    otakusenpai

    10/13/2018, 3:46 PM
    I was trying out the newer api of ktor using raw sockets and am having trouble (I'm always getting timeout errors.)
    override suspend fun receiveUTF8Data(): String? {
            var data: String? = null
            var cB = StringBuilder(512)
            try {
                if(!input.readUTF8LineTo(cB,512))
                    throw Exception("BasicConnection.kt: Didn't receive data from connection!")
                else data = cB.toString()
            } catch (e: Throwable) {
                e.printStackTrace()
                socket.close()
                connected = false
                null
            }
            return data
        }
    And the call is lke this
    val job = GlobalScope.async { data = conn.receiveUTF8Data() }
    job.await()
    The errors are as follows:
    c
    • 2
    • 19
  • o

    otakusenpai

    10/13/2018, 4:39 PM
    Getting this exceptions for the ssl bit of my code
    constructor(Port: Int = 6697,Address: String): super() {
            runBlocking {
                try {
                    port = Port
                    address = Address
                    socket = aSocket(ActorSelectorManager(ioCoroutineDispatcher)).
                            tcp().connect(InetSocketAddress(address,port)).tls()
                    input = socket.openReadChannel()
                    output = socket.openWriteChannel(autoFlush = false)
                    connected = true
                } catch(e: Throwable) {
                    e.printStackTrace()
                    socket.close()
                    connected = false
                }
            }
        }
    c
    d
    e
    • 4
    • 27
  • c

    coletz

    10/13/2018, 9:20 PM
    Working with multiplatform project
    d
    e
    • 3
    • 17
  • j

    jcechace

    10/14/2018, 10:49 AM
    I expected it to require some config since I’m dealing with unreleased dependencies but only finding the repository were kotlin plugin for gradle is in last RC version took some time
    c
    d
    • 3
    • 7
  • v

    voddan

    10/15/2018, 9:36 AM
    I am expecting questions on why I want to do this, but anyways: https://stackoverflow.com/questions/52813746/state-in-ktor-intercepters
    n
    o
    • 3
    • 6
  • f

    frellan

    10/15/2018, 12:07 PM
    What would be the cleanest way to introduce cache for routes in ktor? Anyone using anything nice?
    s
    d
    • 3
    • 6
  • h

    hudsonb

    10/16/2018, 1:14 PM
    The HttpRequestBuilder.body property can be a subtype of OutgoingContent as well as a String instance:
    
    body = "HELLO WORLD!"
    body = TextContent("HELLO WORLD!", ContentType.Text.Plain)
    ...
    Got me excited that setter overrides had been added or something but
    body
    is just defined as
    Any
    . 😭
    📝 1
    d
    • 2
    • 5
  • z

    zachtib

    10/16/2018, 3:48 PM
    So what does the "js client engine" mean?
    e
    v
    • 3
    • 4
  • h

    hmole

    10/16/2018, 4:15 PM
    Is there a way to opt out of coroutines and use ktor as a simple synchronous client? I'm trying it for Ios and I don't know a thing about coroutines.
    d
    • 2
    • 2
  • l

    Lempere

    10/16/2018, 4:25 PM
    Are there any hacktoberfest issues to help this great project? 😄
    👍🏼 1
    e
    • 2
    • 3
  • s

    Sergio Casero

    10/16/2018, 4:26 PM
    Hello guys, I'm getting a really rare issue when deploying the backoffice. I only can deploy the module with the "run" task: - I've tried to configure a build configuration like this (Netty): https://ktor.io/servers/engine.html but the error is is
    No configuration setting found for key 'ktor'
    The application.conf is in resources directory, and "run" task configuration is based on it, so... I don't understand anything. I've also tried to create a new project like https://ktor.io/quickstart/faq.html#cannot-find-application-conf is suggesting, but I'm getting the same issue Also, If I try to run with "play button on main class" on IntelliJ, IntelliJ says "cannot find main class"
    d
    c
    • 3
    • 41
  • r

    russhwolf

    10/16/2018, 10:08 PM
    Is it possible to include the ktor http client in a project using the
    kotlin-multiplatform
    plugin? I see that the
    fullstack-mpp
    sample uses the new plugin, but the
    client-mpp
    sample uses the separate platforms plugins so I don't have an example gradle setup to compare to.
    d
    e
    • 3
    • 5
  • f

    franek

    10/17/2018, 6:37 AM
    Hello, I want to integrate google login from android app with Ktor server but I do not know where to start. I find this: https://ktor.io/quickstart/guides/oauth.html but I’m not sure if I need that So my questions: 1. I have clientId also secretId but what is this secretSignKey = hex(“00010”) // @TODO: Remember to change this! Where I can get secretSignKey? 2. With google login SDK I get TOKEN in android app, I need to send this key/token to the server and here I lost 😞 Is there any tutorial how do that? How connect token from google android sdk with oauth on ktor side?
    c
    t
    • 3
    • 4
  • h

    holgerbrandl

    10/17/2018, 8:10 AM
    Is this more likely to be an issue with the generator or my version of Intellij v2018.2.5?
    ✅ 1
    a
    c
    d
    • 4
    • 13
  • h

    holgerbrandl

    10/17/2018, 8:35 AM
    Is this a known problem? is there a workaround?
    c
    • 2
    • 7
  • d

    Dias

    10/17/2018, 9:43 AM
    Hi, I couldn't find info on the high level overview of how ktor works. I have case, where I need to install an http client feature, which caches, provides and refreshes authentication tokens, which will be used when making http calls. But I am not sure about lifetimes and coroutine scopes. What I understand is that feature is installed just once and not per request? Which means all the state in the feature is available during the lifetime of the application? And what happens if I have a coroutine that throws an error while handling request to the server? I presume each request to ktor is handled in some parent coroutine, so error will just cancel that coroutine right? (like when in jetty world, where each request creates a thread)
    c
    • 2
    • 7
  • d

    Dias

    10/17/2018, 9:43 AM
    (hence some of my questions here https://kotlinlang.slack.com/archives/C1CFAFJSK/p1539709589000100)
    c
    • 2
    • 5
  • h

    holgerbrandl

    10/17/2018, 9:45 AM
    How can I test the basic authentication in http://ktor.io/quickstart/guides/api.html#authentication using the IDE rest client? I’ve tried
    POST <http://user:password@localhost:8080/snippets>
    Content-Type: application/json
    WWW-Authenticate: Basic myrealm
    
    {
      "snippet": {
        "text": "heyho"
      }
    }
    which works, but I was wondering if I could also put the credentials into the request header in some way?
    c
    • 2
    • 5
  • j

    Jonas Bark

    10/17/2018, 2:20 PM
    Kotlin Native using 1.0.0-beta-1: I tried to create a customized version of the iOS HttpClientEngine. I copied the source code from the original IosClientEngine, added necessary annotations to make it compile but it rises compiler errors: https://gist.github.com/jonasbark/e37d535239ae28facc83bd4ff2c0772a Errors mentioned:
    > Task :common:linkDebugFrameworkIos
    Undefined symbols for architecture arm64:
      "_private_classes_<ktor-client-core-ios>_io.ktor.client.request.DefaultHttpRequest_94", referenced from:
          _kfun:com.stihl.app.module.connect.api.Ios2ClientEngine.execute(io.ktor.client.call.HttpClientCall;io.ktor.client.request.HttpRequestData)io.ktor.client.call.HttpEngineCall in combined.o
      "_private_functions_<ktor-client-core-ios>_kfun:io.ktor.client.request.DefaultHttpRequest.<get-content>()io.ktor.http.content.OutgoingContent_133", referenced from:
          _kfun:com.stihl.app.module.connect.api.Ios2ClientEngine.execute(io.ktor.client.call.HttpClientCall;io.ktor.client.request.HttpRequestData)io.ktor.client.call.HttpEngineCall in combined.o
      "_private_functions_<ktor-client-core-ios>_kfun:io.ktor.client.request.DefaultHttpRequest.<get-headers>()io.ktor.http.Headers_134", referenced from:
          _kfun:com.stihl.app.module.connect.api.Ios2ClientEngine.execute(io.ktor.client.call.HttpClientCall;io.ktor.client.request.HttpRequestData)io.ktor.client.call.HttpEngineCall in combined.o
      "_private_functions_<ktor-client-core-ios>_kfun:io.ktor.client.request.DefaultHttpRequest.<get-method>()io.ktor.http.HttpMethod_131", referenced from:
          _kfun:com.stihl.app.module.connect.api.Ios2ClientEngine.execute(io.ktor.client.call.HttpClientCall;io.ktor.client.request.HttpRequestData)io.ktor.client.call.HttpEngineCall in combined.o
      "_private_functions_<ktor-client-core-ios>_kfun:io.ktor.client.request.DefaultHttpRequest.<get-url>()io.ktor.http.Url_132", referenced from:
          _kfun:com.stihl.app.module.connect.api.Ios2ClientEngine.execute(io.ktor.client.call.HttpClientCall;io.ktor.client.request.HttpRequestData)io.ktor.client.call.HttpEngineCall in combined.o
    ld: symbol(s) not found for architecture arm64
    I suspect it's because of the DefaultHttpRequest but I have no clue how to work around this. Any idea?
    e
    • 2
    • 5
  • d

    Dias

    10/17/2018, 3:49 PM
    but not sure how will it play out with coroutines and stuff
    c
    d
    • 3
    • 15
  • r

    rocketraman

    10/17/2018, 5:10 PM
    For the ktor client with
    JsonFeature
    how do I deal with two possible response formats e.g. a normal response and an error response?
    j
    e
    • 3
    • 3
  • s

    Sergio Casero

    10/17/2018, 7:17 PM
    Hi guys, is there ktor client for JS? I can't find it
    d
    • 2
    • 9
  • g

    gaetan

    10/18/2018, 10:03 AM
    I’m trying to use the lastest version of ktor but have some problems with existing task using DCE
    * What went wrong:
    Could not determine the dependencies of task ':data2viz-client:runDceKotlinJs'.
    > Could not resolve all files for configuration ':data2viz-client:kotlinCompilerClasspath'.
       > Could not find org.jetbrains.kotlin:kotlin-compiler-embeddable:1.3.0-rc-131.
         Searched in the following locations:
             <https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/kotlin-compiler-embeddable/1.3.0-rc-131/kotlin-compiler-embeddable-1.3.0-rc-131.module>
             <https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/kotlin-compiler-embeddable/1.3.0-rc-131/kotlin-compiler-embeddable-1.3.0-rc-131.pom>
         Required by:
             project :data2viz-client
    Is there some modifications on DCE in 1.3?
    e
    b
    • 3
    • 3
  • e

    enleur

    10/18/2018, 10:42 AM
    any reasons to use groovy gradle in ktor builds? https://github.com/ktorio/ktor
    o
    m
    • 3
    • 3
  • d

    dave08

    10/18/2018, 10:43 AM
    Will some kind of
    ApplicationCall.receiveFile/s()
    be added to Ktor? Or is it too application specific?
    m
    e
    • 3
    • 10
Powered by Linen
Title
d

dave08

10/18/2018, 10:43 AM
Will some kind of
ApplicationCall.receiveFile/s()
be added to Ktor? Or is it too application specific?
m

mp

10/18/2018, 10:44 AM
You can
receiveMultipart()
e

enleur

10/18/2018, 10:44 AM
extension for this http://ktor.io/servers/uploads.html ?
d

dave08

10/18/2018, 10:45 AM
Right, it could be a nice convenience method for most cases...
m

mp

10/18/2018, 10:46 AM
Perhaps, though I'm not sure what it would do that receiveMultipart doesn't? It gives you access to each file's bytes, plus associated metadata (filename, content type, etc)
d

dave08

10/18/2018, 10:47 AM
Just an easy way to receive a file for most common cases without all the boilerplate code...
m

mp

10/18/2018, 10:48 AM
call.receiveMultipart().readAllParts().map { it.streamProvider().use { it.readAllBytes() } }
🤷‍♂️
d

dave08

10/18/2018, 10:49 AM
suspend fun ApplicationCall.receiveFile(uploadDir: String): File =
		receiveMultipart().readPart().let {
			if (it is PartData.FileItem) {
				val ext = File(it.originalFileName).extension
				val uploadName = "upload-${System.currentTimeMillis()}-${it.originalFileName!!.hashCode()}.$ext"

				File(uploadDir, uploadName).also { file ->
					withContext(CommonPool) {
						it.streamProvider().use { its -> file.outputStream().buffered().use { its.copyToSuspend(it) } }
					}
				}
			} else error("Error retreiving upload")
		}

suspend fun ApplicationCall.receiveFiles(uploadDir: String): Map<String, File> =
		receiveMultipart().readAllParts().map {
			if (it is PartData.FileItem) {
				it.name!! to File(uploadDir, it.originalFileName).also { file ->
					withContext(CommonPool) {
						it.streamProvider().use { its -> file.outputStream().buffered().use { its.copyToSuspend(it) } }
					}
				}
			} else error("Error retreiving upload")
		}.toMap()
m

mp

10/18/2018, 10:51 AM
It's possible, certainly, but you're making a lot of decisions for the consumer of that, including defaulting to letting an HTTP request dictate a filename used on the local filesystem, which is super dangerous
d

dave08

10/18/2018, 11:24 AM
That was my original question, if 80% of such needs could be covered with a nicely thought out implementation and a few parameters... it might still be nice 😉
m

mp

10/18/2018, 11:25 AM
Yep... perhaps as a standalone library
View count: 6