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

    Alexandre Brown

    08/23/2021, 12:45 PM
    [SOLVED] Hello, I'm getting a 404 error when using
    @Location
    on Ktor 1.6.0, anybody had similar issue?
    dependencies { 
        implementation("io.ktor:ktor-locations:$ktorVersion")
    }
    
    tasks.withType<KotlinCompile> {
        kotlinOptions.freeCompilerArgs += listOf("-Xuse-experimental=io.ktor.locations.KtorExperimentalLocationsAPI")
    }
    import io.ktor.locations.Location
    
    @Location("/mylocation")
    class MyLocation
    fun Application.someFun() {
        routing {
            route("/my-root") {
                post<MyLocation> {
    ł
    • 2
    • 4
  • d

    Didier Villevalois

    08/23/2021, 1:07 PM
    Hey! I have yet some other questions about
    ktor-network
    : • Why is
    TcpSocketBuilder.connect(...)
    suspending while
    TcpSocketBuilder.bind(...)
    is not ? • Would it be in the project scope to accept a contribution for a
    UnixDomainSocketBuilder
    ?
    a
    e
    • 3
    • 5
  • a

    Alexandre Brown

    08/23/2021, 5:14 PM
    [SOLVED] Hello, I am getting some errors when running a Ktor server that uses the Location feature, the ktor app was compiled into a GraalVM native image and upon running it I get the following :
    Exception in thread "DefaultDispatcher-worker-2" kotlin.reflect.jvm.internal.KotlinReflectionInternalError: Unresolved class: class applications.web.routes.roadclassification.MyLocation
    import <http://io.ktor.locations.post|io.ktor.locations.post>
    
    ...
    fun Routing.myFun() {
    	route("/my-route") {
    		post<MyLocation> {
    			call.respondText { "hello" }
    		}
    	}
    }
    import io.ktor.locations.Location
    
    @Location("/mylocation")
    class MyLocation
    The app works when not running the native image (regular jar) or when running the native image without using the Location feature. Thanks
    r
    • 2
    • 13
  • j

    Jonathan Hollingsworth

    08/23/2021, 7:07 PM
    Hello. I'm trying to deserialize into a LocalDate object from a JSON ISO string (e.g. "2021-10-01"). I'm using
    kotlinx.serializable
    On the way out (i.e. serializing) it works fine with this
    @Serializable
    data class Task(
        var id: Int? = null, val title: String, val detail: String? = null,
        @Contextual
        val dueDate: LocalDate? = null
    )
    But when I try to
    val task = call.receive<Task>()
    in route, then I get an
    Serializer for class 'LocalDate' is not found.
    I've been through the kotlinx.serialization docs, but I can't see find anything to help.
    b
    a
    • 3
    • 8
  • p

    Piotr Krzemiński

    08/24/2021, 6:44 AM
    is it only me? 😅 just noticed over 100 run configurations for Ktor
    e
    l
    +4
    • 7
    • 12
  • h

    hfhbd

    08/24/2021, 12:48 PM
    Hey, why is
    streamProvider
    only available for
    PartData.FileItem
    and not for all
    PartData
    subclasses? It is only a shortcut for
    provider().asStream()
    https://github.com/ktorio/ktor/blob/1bd92eaa4974dc0b09757c635895ce0e38474a95/ktor-http/jvm/src/io/ktor/http/content/MultipartJvm.kt
    a
    • 2
    • 2
  • a

    Andre Stefanov

    08/24/2021, 1:50 PM
    hello guys, is there any documentation or example (or even a lib/framework) how to share ktor routes between server and client? i am building a multiplatform application with ktor jvm server, android app and a shared module. but jvm only example would already help a lot.
    c
    n
    k
    • 4
    • 6
  • a

    albrechtroehm

    08/24/2021, 4:13 PM
    Hello everyone, does any of you use the space platform for code hosting & automation? I was wondering if there is a channel here but couldn't find one. Maybe one of guys could point me somewhere? Thanks!
    a
    • 2
    • 1
  • c

    CLOVIS

    08/25/2021, 2:01 PM
    After migrating to Ktor 1.6.2, it appears that
    StringValuesBuilder.append
    has been marked as internal. However, it is necessary to create multipart requests:
    builder.append(FormPart(name, data, Headers.build {
    	append(HttpHeaders.ContentType, mime) // this is now marked as internal
    }))
    I didn't see anything explaining how we should migrate our code.
    a
    • 2
    • 2
  • h

    hfhbd

    08/26/2021, 8:11 AM
    No Kotlin 1.5.30 update in Ktor 1.6.3? Do we have to wait til next month?
    e
    ł
    • 3
    • 6
  • e

    edenman

    08/26/2021, 8:25 AM
    I just found this line in the Ktor EAP announcement blog post: “Important – EAP artifacts will not be kept indefinitely. We’ll be cleaning them up on a frequent basis.” Could we get this information added to https://ktor.io/eap/ please? Really frustrating that it’s not more aggresively warned about.
    a
    h
    • 3
    • 6
  • j

    jdoneill

    08/26/2021, 5:23 PM
    Is there an
    ktor-auth
    dependency setup document for mulitplatform android/ios/web? I am running into this error:
    No matching variant of io.ktor:ktor-auth:1.6.3 was found. The consumer was configured to find a usage of 'kotlin-runtime' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'js', attribute 'org.jetbrains.kotlin.js.compiler' with value 'ir' but:
              - Variant 'jvmApiElements-published' capability io.ktor:ktor-auth:1.6.3:
                  - Incompatible because this component declares an API of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm' and the consumer needed a usage of 'kotlin-runtime' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'js'
                  - Other compatible attribute:
                      - Doesn't say anything about org.jetbrains.kotlin.js.compiler (required 'ir')
    Using Kotlin 1.5.30, Ktor 1.6.3, applying the
    ktor-auth
    in common and mixing in
    ktor-client-auth-js
    in common and/or jsMain and continue to get this error building/running web This worked with previous versions but having issues getting it to work now on web/js, anyone seen this?
    a
    • 2
    • 3
  • r

    Rafał Kuźmiński

    08/26/2021, 7:31 PM
    Hello. I wanted to respond with file, but by default, downloaded file is named by route. How can it be changed? Example:
    get("someRoute"){
        call.respondFile(someFile)
    }
    Downloaded file will be named "someRoute". Can I change it?
    n
    a
    • 3
    • 3
  • r

    rnett

    08/26/2021, 9:50 PM
    KTOR-2977 (make the client available in
    refreshTokens
    ) does not seem to have actually made it into the release, see my comment on the issue for details
    a
    h
    • 3
    • 2
  • d

    Dazai

    08/28/2021, 1:16 AM
    is it possible to build a typesafe kotlin web api that works on client using kotlinjs & server with jvm? something kinda like servant in haskell where you only have to write one api for the client & server
    r
    c
    +2
    • 5
    • 7
  • j

    JuanDocal

    08/30/2021, 5:11 AM
    Hello everyone, I’ve been looking for a bit and couldn’t find anything regarding the support of arm64 for macos. Does anyone know anything about it?
    h
    j
    • 3
    • 3
  • m

    MyCodeFlow

    08/30/2021, 5:39 AM
    Hello everyone. I have recently tried to install WebSocket feature on my Ktor Server (Ktor version 1.6.2) and implement simple chat example from ktor docs (Btw when following tutorial from chat example from docs i got 'Web socket feature is not installed Error' because in tutorial it recommends to open routing function before closing the Websocket feature install bracket, which is incorrect according to the answer i found in google - 'you should close install bracket before start writing routing for webScoket'. Anyway, when got rid of the previous error, when deploying on Heroku platform and trying to open my cloud server i got it crashed with the next Error: Exception in thread "main" java.lang.LinkageError: loader constraint violation: when resolving method "io.ktor.application.ApplicationEvents.subscribe(Lio/ktor/application/EventDefinition;Lkotlin/jvm/functions/Function1;) Lkotlinx/coroutines/DisposableHandle;" the class loader (instance of io/ktor/server/engine/OverridingClassLoader$ChildURLClassLoader) of the current class, io/ktor/websocket/WebSockets$Feature, and the class loader (instance of sun/misc/Launcher$AppClassLoader) for the method's defining class, io/ktor/application/ApplicationEvents, have different Class objects for the type kotlinx/coroutines/DisposableHandle used in the signature I guess it is kinda bug or problem with installing WebSocket feature on Server which is further deployed on Heroku platform. Is there any altrenative how can i implement WebSocket feature on my Server which is gonna be deployed on a Cloud based platform? P.S: When deleting code connected with installing and configuration of WebScoket feature, server runs well without crash when deployed on Heroku. My Application class code looks like:
    fun main(args: Array<String>): Unit = io.ktor.server.netty.EngineMain.main(args)
    
    fun Application.module(testing: Boolean = false) {
    
        //initialization of the Database
        DataBaseFactory.init()
        val userDb = UserDataBaseDao() //Users Database
        val loveCardDb = LoveCardsDataBaseDao()
        val hashFunction = { s: String -> hash(s) }
        val jwtService = JwtService()
    
        //installing content receive/respond functionality
        install(ContentNegotiation) {
            json() //converter for serialization of kotlin classes
        }
        //installing authentication
        install(Authentication){
            jwt("jwt") {
                verifier(jwtService.varifier)
                realm = "Lovecard server"
                validate {
                    val payload = it.payload
                    val email = payload.getClaim("email").asString()
                    val user = userDb.findUserByEmail(email)
                    user
                }
            }
        }
    
        //installing WebSocket
        install(WebSockets) {
            pingPeriod = Duration.ofSeconds(15)
            timeout = Duration.ofSeconds(15)
            maxFrameSize = Long.MAX_VALUE
            masking = false
        }
        routing {
            //basic route on connection to server
            get("/") {
                call.respondText("Hello world!", contentType = ContentType.Text.Plain)
            }
            //echo unit of websocket
            webSocket("/echo") {
                send("Please enter your name")
                for (frame in incoming) {
                    when (frame) {
                        is Frame.Text -> {
                            val receivedText = frame.readText()
                            if (receivedText.equals("bye", ignoreCase = true)) {
                                close(CloseReason(CloseReason.Codes.NORMAL, "Client said BYE"))
                            } else {
                                send(Frame.Text("Hi, $receivedText!"))
                            }
                        }
                    }
                }
            }
            //Websocket for data exchange
            val connections = Collections.synchronizedSet<Connection?>(LinkedHashSet())
            webSocket("/connection") {
                val thisConnection = Connection(this)
                connections += thisConnection
                send("You've logged in as [${thisConnection.name}]")
    
                for (frame in incoming) {
                    when (frame) {
                        is Frame.Text -> {
                            val receivedText = frame.readText()
                            val textWithUsername = "[${thisConnection.name}]: $receivedText"
                            connections.forEach {
                                it.session.send(textWithUsername)
                            }
                        }
                    }
                }
            }
    
            //register Authentication routes
            authRouting(hashFunction, jwtService)
            //register User routes
            userRouting(userDb, jwtService, hashFunction)
            //register LoveCards routes
            loveCardsRouting(loveCardDb)
        }
        
        class Connection(val session: DefaultWebSocketSession) {
    
          companion object{
              var lastId = AtomicInteger(0)
          }
        val name = "User ${lastId.getAndIncrement()}"
        }
    }
    :thread-please: 4
    a
    • 2
    • 2
  • h

    Hien Nguyen

    08/30/2021, 7:32 AM
    I want to upload image to the amazon S3 server
    <http://httpClient.post|httpClient.post><Unit> {
                    val bucket = it.fields.bucket
                    url {
                        encodedPath = bucket
                    }
                    body = MultiPartFormDataContent(
                        formData {
                            append("bucket", bucket)
                            append("Policy", it.fields.policy)
                            append("X-Amz-Date", it.fields.date)
                            append("X-Amz-Algorithm", it.fields.algorithm)
                            append("X-Amz-Signature", it.fields.signature)
                            append("X-Amz-Security-Token", it.fields.securityToken)
                            append("X-Amz-Credential", it.fields.credential)
                            append("acl", it.fields.acl)
                            append("key", it.fields.key)
                            appendInput(
                                key = "file",
                                headers = Headers.build {
                                    append(HttpHeaders.ContentDisposition, "filename=uuid.jpg")
                                    append(HttpHeaders.ContentType, "image/jpeg")
                                }) {
                                    buildPacket { writeFully(input.imageByteArray) }
                                }
                        }
                    )
                }
    but I meet the below error
    javax.net.ssl.SSLException: Write error: ssl=0xcbc0b608: I/O error during system call, Broken pipe
    😞 If I upload the image to another server (not S3 anymore), the upload is successfully anyone help me 😞 ?
    t
    a
    • 3
    • 3
  • j

    james

    08/30/2021, 8:42 AM
    hello, help me please. Why is it 400? Works fine using browser or retrofit2 REQUEST: https://restaurant-api.wolt.fi/v3/venues?lat=60.170187&amp;lon=24.930599 METHOD: HttpMethod(value=GET)  COMMON HEADERS  Accept: application/json Accept-Charset: UTF-8 CONTENT HEADERS Content-Length: 0 BODY Content-Type: null BODY START BODY END RESPONSE: 400 BAD_REQUEST
    suspend fun getAllVenues(lat: Double, lon: Double): VenueResponse {
        return client.get(BuildConfig.API_URL + "venues") {
            parameter("lat", lat)
            parameter("lon", lon)
        }
    }
    
    single {
            HttpClient(Android) {
                install(JsonFeature) {
                    serializer = GsonSerializer {
                        setPrettyPrinting()
                        disableHtmlEscaping()
                    }
                }
                expectSuccess = false
                install(Logging) {
                    logger = Logger.DEFAULT
                    level = LogLevel.ALL
                }
            }
        }
    a
    • 2
    • 1
  • o

    oletjens

    08/30/2021, 1:11 PM
    OAuth2: Why does OAuth2.kt not use the return value from the NonceManager verify method? : https://github.com/ktorio/ktor/blob/main/ktor-features/ktor-auth/jvm/src/io/ktor/auth/OAuth2.kt#L170
    a
    • 2
    • 1
  • c

    christophsturm

    08/31/2021, 8:48 AM
    why is the api to add headers marked as internal?
    <http://ktor.post|ktor.post>(url) {
        body = ...
        headers {
            append("Content-Type", "application/json")
            append("Authorization", "Bearer $bearer")
        }
    “This API is internal in ktor and should not be used. It could be removed or changed without notice.”
    a
    • 2
    • 1
  • m

    Michal Harakal

    08/31/2021, 9:54 AM
    Its already Impressive how many native targets ktor-client already supports. With 1.5.30 and an initial support for Apple Silicon we have some more (like iosSimulatorArm64). Are there particular plans to add them? I didn’t find anything specific in roadmap or on github. Reason behind -> it will make possible to develop also with simulators in Apple M1 computers.
    a
    r
    • 3
    • 2
  • s

    Sebastian Owodzin

    08/31/2021, 1:53 PM
    Has anyone ever seen something like this when building release variant of the Android app that uses KTOR client through multiplatform module?
    Execution failed for task ':app-android:mobile:minifyReleaseWithR8'.
    > Could not resolve all files for configuration ':app-android:mobile:releaseRuntimeClasspath'.
       > Failed to transform ktor-client-core-jvm-1.6.2.jar (io.ktor:ktor-client-core-jvm:1.6.2) to match attributes {artifactType=android-asm-instrumented-jars, asm-transformed-variant=release, org.gradle.libraryelements=jar, org.gradle.status=release, org.gradle.usage=java-runtime, org.jetbrains.kotlin.platform.type=jvm}.
          > Execution failed for AsmClassesTransform: /Users/sowodzin/.gradle/caches/transforms-3/f7fb63019a1553b70833efe63d6a881f/transformed/jetified-ktor-client-core-jvm-1.6.2.jar.
             > Index -1 out of bounds for length 0
    Koltin version: 1.5.21 Android Gradle Plugin 7.0.1 (everything is fine when I switch back to 4.1.3)
    a
    • 2
    • 3
  • l

    landon burch

    08/31/2021, 8:27 PM
    okay.. I am looking at documentation my http client to make a call server that is using OAuth and responding with bearer token. I am looking at https://github.com/ktorio/ktor-documentation/blob/main/codeSnippets/snippets/client-auth-oauth-google/src/main/kotlin/com/example/Application.kt and for inspiration. But it seems that I am having some syntax errors it seems that the bearer { loadTokens { blocks are not resolvable.. I am using ktor versions "1.5.3" .. does anyone have any experience in getting this to work in 1.5.3?
    a
    • 2
    • 3
  • k

    keishi kubo

    09/01/2021, 3:45 AM
    I want to separate e2e test and unit test. How does everyone set up ??
    a
    • 2
    • 4
  • p

    Patrick Ramsey

    09/01/2021, 6:25 AM
    question about testing in ktor-client: So, runBlockingTest {} (from kotlin-test) creates a TestDispatcher and runs its block on said dispatcher, and then fails if any work is left running at the end of the test (say, on another dispatcher). I’d assume that the ktor MockEngine is meant to be used in tests as well (where best practice seems to be to use runBlockingTest {} instead of runBlocking {}). But MockEngine creates its own dispatcher (by calling Dispatchers.clientDispatcher()), and calls to client.request() end up scheduling work on that dispatcher, which seems to cause tests that rely on a TestCoroutineDispatcher to fail. Am I understanding this correctly, or am I missing something obvious?
    a
    e
    • 3
    • 13
  • s

    shusek

    09/01/2021, 9:43 AM
    Does anyone use classes in ktor client like
    <http://io.ktor.utils.io|io.ktor.utils.io>.core.Input
    or
    <http://io.ktor.utils.io|io.ktor.utils.io>.core.Output
    ? I can't find a description for them and i am affraid it is internal classes which will be deleted. My problem is that ByteReadChannel is malformed on receive but
    io.ktor.utils.i.core.Input
    works fine. Can i use
    Input
    class without fear?
    val channel: Input = httpResponse.receive() //works fine
    val channel: ByteReadChannel = httpResponse.receive() // throw exception MalformedInputException: Input length = 1
    a
    r
    e
    • 4
    • 6
  • p

    ptsiogas

    09/01/2021, 10:01 AM
    Hi there, how can I pass a cookie at Ktor client headers? I am trying the below code
    header("Cookie", cookie)
    but Ktor seems to ignore it.
    a
    h
    • 3
    • 17
  • u

    Undervoid

    09/02/2021, 7:22 AM
    Hello there, is there any way to get all route path on service startup ? I found someone talked about this, however I’m not sure it’s the best practice to do it https://github.com/ktorio/ktor/issues/1252#issuecomment-551304202
    fun Application.ktorMain() {
        // set up omitted
        val root = feature(Routing)
        val allRoutes = allRoutes(root)
        val allRoutesWithMethod = allRoutes.filter { it.selector is HttpMethodRouteSelector }
        allRoutesWithMethod.forEach {
            <http://logger.info|logger.info>("route: $it")
        }
    }
    
    fun allRoutes(root: Route): List<Route> {
        return listOf(root) + root.children.flatMap { allRoutes(it) }
    }
    is there another approach to do it ?
    👀 1
    👍 1
    a
    r
    • 3
    • 3
  • m

    Matthieu Stombellini

    09/02/2021, 12:31 PM
    Hi, how can I use
    Parameters.build
    now that
    StringValuesBuilder
    is internal? My use case is sending a request that has
    application/x-www-form-urlencoded
    data. Using this:
    FormDataContent(Parameters.build {
        append("some", "thing")
    })
    results in a warning (and an error in my case since I'm using
    -Werror
    ) on the
    append
    call.
    This API is internal in ktor and should not be used. It could be removed or changed without notice.
    This is because
    StringValuesBuilder
    is marked with
    @InternalAPI
    , andd using it is required for doing basically any building for parameters. Is it now impossible to use
    FormDataContent
    without relying on Ktor's internals?
    l
    a
    • 3
    • 2
Powered by Linen
Title
m

Matthieu Stombellini

09/02/2021, 12:31 PM
Hi, how can I use
Parameters.build
now that
StringValuesBuilder
is internal? My use case is sending a request that has
application/x-www-form-urlencoded
data. Using this:
FormDataContent(Parameters.build {
    append("some", "thing")
})
results in a warning (and an error in my case since I'm using
-Werror
) on the
append
call.
This API is internal in ktor and should not be used. It could be removed or changed without notice.
This is because
StringValuesBuilder
is marked with
@InternalAPI
, andd using it is required for doing basically any building for parameters. Is it now impossible to use
FormDataContent
without relying on Ktor's internals?
l

Lars Toft Jacobsen

09/02/2021, 1:09 PM
Not quite sure why you need the
FormDataContent
- but anyway it looks like you can use
Parameters
factories now i.e.
parametersOf()
a

Aleksei Tirman [JB]

09/02/2021, 2:39 PM
@Matthieu Stombellini just add
@OptIn(InternalAPI::class)
for now. For more information please read https://youtrack.jetbrains.com/issue/KTOR-3001#focus=Comments-27-5105259.0-0.
View count: 30