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

    Laurent SOULET

    06/07/2022, 3:58 PM
    The Ktor 2.0 tests environment and its testApllicationn and externalServices is a great improvment ! Unfortunately I have a problem to test external services with timeouts. I don't know if I miss something or if it is a bug.
    package com.example
    
    import io.ktor.client.*
    import io.ktor.client.plugins.*
    import io.ktor.client.request.*
    import io.ktor.http.*
    import io.ktor.server.application.*
    import io.ktor.server.response.*
    import io.ktor.server.routing.*
    import io.ktor.server.testing.*
    import kotlin.test.Test
    import kotlin.test.assertEquals
    
    
    fun Application.configureRouting(httpClient: HttpClient) {
        routing {
            get("/test") {
                httpClient.get("<http://fake.site.io/toto>") {
                    timeout {
                        requestTimeoutMillis = 100
                    }
                }
                call.respondText("Hello World!")
            }
        }
    }
    
    
    class ApplicationTest {
        @Test
        fun testRoot() = testApplication {
    
            val myClient = createClient {
                install(HttpTimeout)
            }
    
            application {
                configureRouting(myClient)
            }
    
            externalServices {
                hosts ("<http://fake.site.io>") {
                    routing {
                        get("/toto") {
                            call.respond(HttpStatusCode.OK)
                        }
                    }
                }
            }
    
            myClient.get("/test").apply {
                assertEquals(HttpStatusCode.OK, status)
            }
        }
    }
    When I execute this code, I receive this exception.
    Engine doesn't support io.ktor.client.plugins.HttpTimeout$Plugin@3db8b930
    java.lang.IllegalArgumentException: Engine doesn't support io.ktor.client.plugins.HttpTimeout$Plugin@3db8b930
    	at io.ktor.client.engine.HttpClientEngine$DefaultImpls.checkExtensions(HttpClientEngine.kt:101)
    	at io.ktor.client.engine.HttpClientEngine$DefaultImpls.access$checkExtensions(HttpClientEngine.kt:23)
    	at io.ktor.client.engine.HttpClientEngine$install$1.invokeSuspend(HttpClientEngine.kt:64)
    	at io.ktor.client.engine.HttpClientEngine$install$1.invoke(HttpClientEngine.kt)
    	at io.ktor.client.engine.HttpClientEngine$install$1.invoke(HttpClientEngine.kt)
    	at io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:123)
    	at io.ktor.util.pipeline.SuspendFunctionGun.proceed(SuspendFunctionGun.kt:81)
    	at io.ktor.util.pipeline.SuspendFunctionGun.execute$ktor_utils(SuspendFunctionGun.kt:101)
    	at io.ktor.util.pipeline.Pipeline.execute(Pipeline.kt:77)
    	at io.ktor.client.plugins.HttpSend$DefaultSender.execute(HttpSend.kt:135)
    	at io.ktor.client.plugins.HttpRedirect$Plugin$install$1.invokeSuspend(HttpRedirect.kt:61)
    	at io.ktor.client.plugins.HttpRedirect$Plugin$install$1.invoke(HttpRedirect.kt)
    	at io.ktor.client.plugins.HttpRedirect$Plugin$install$1.invoke(HttpRedirect.kt)
    	at io.ktor.client.plugins.HttpSend$InterceptedSender.execute(HttpSend.kt:113)
    	at io.ktor.client.plugins.HttpCallValidator$Companion$install$3.invokeSuspend(HttpCallValidator.kt:147)
    	at io.ktor.client.plugins.HttpCallValidator$Companion$install$3.invoke(HttpCallValidator.kt)
    	at io.ktor.client.plugins.HttpCallValidator$Companion$install$3.invoke(HttpCallValidator.kt)
    	at io.ktor.client.plugins.HttpSend$InterceptedSender.execute(HttpSend.kt:113)
    	at io.ktor.client.plugins.HttpSend$Plugin$install$1.invokeSuspend(HttpSend.kt:101)
    	at io.ktor.client.plugins.HttpSend$Plugin$install$1.invoke(HttpSend.kt)
    	at io.ktor.client.plugins.HttpSend$Plugin$install$1.invoke(HttpSend.kt)
    	at io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:123)
    	at io.ktor.util.pipeline.SuspendFunctionGun.proceed(SuspendFunctionGun.kt:81)
    	at io.ktor.util.pipeline.SuspendFunctionGun.proceedWith(SuspendFunctionGun.kt:91)
    	at io.ktor.client.plugins.HttpCallValidator$Companion$install$1.invokeSuspend(HttpCallValidator.kt:126)
    	at io.ktor.client.plugins.HttpCallValidator$Companion$install$1.invoke(HttpCallValidator.kt)
    	at io.ktor.client.plugins.HttpCallValidator$Companion$install$1.invoke(HttpCallValidator.kt)
    	at io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:123)
    	at io.ktor.util.pipeline.SuspendFunctionGun.proceed(SuspendFunctionGun.kt:81)
    	at io.ktor.client.plugins.HttpRequestLifecycle$Plugin$install$1.invokeSuspend(HttpRequestLifecycle.kt:35)
    	at io.ktor.client.plugins.HttpRequestLifecycle$Plugin$install$1.invoke(HttpRequestLifecycle.kt)
    	at io.ktor.client.plugins.HttpRequestLifecycle$Plugin$install$1.invoke(HttpRequestLifecycle.kt)
    	at io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:123)
    	at io.ktor.util.pipeline.SuspendFunctionGun.proceed(SuspendFunctionGun.kt:81)
    	at io.ktor.util.pipeline.SuspendFunctionGun.execute$ktor_utils(SuspendFunctionGun.kt:101)
    	at io.ktor.util.pipeline.Pipeline.execute(Pipeline.kt:77)
    	at io.ktor.client.HttpClient.execute$ktor_client_core(HttpClient.kt:187)
    	at io.ktor.client.statement.HttpStatement.executeUnsafe(HttpStatement.kt:107)
    	at io.ktor.client.statement.HttpStatement.execute(HttpStatement.kt:46)
    	at io.ktor.client.statement.HttpStatement.execute(HttpStatement.kt:61)
    🧵 2
    a
    • 2
    • 4
  • t

    Tim Abil

    06/07/2022, 5:56 PM
    I know official swagger support is on the horizon but, in the mean time, I made this plugin to generate route definitions automatically https://github.com/tabilzad/ktor-docs-plugin
    👍 2
    👀 1
    l
    r
    d
    • 4
    • 12
  • s

    Satyam Agarwal

    06/08/2022, 10:45 AM
    Hei, Just curious why content is marked as internal ? When used together with ResponseObserver, Then I have to use OptIn internal api annotation. I use ResponseObserver to log response body. I donot want to use bodyAsChannel, as it may contain modified response. https://github.com/ktorio/ktor/blob/main/ktor-client/ktor-client-core/common/src/io/ktor/client/statement/HttpResponse.kt#L55-L56
    a
    r
    • 3
    • 12
  • b

    Benjamin Deroche

    06/08/2022, 4:13 PM
    Hello, just a quick question did the CIO Client got moved in 2.0? I just migrated from 1.6.7, and the import
    import io.ktor.client.engine.cio.CIO
    now show an error. I have
    implementation("io.ktor:ktor-client-core:2.0.2")
    in the commonMain dependencies of my KMM app, but after looking into the related jar downloaded by Gradle it appear to now be empty.
    a
    • 2
    • 9
  • v

    Viktor Orlyk

    06/09/2022, 10:19 AM
    hello, maybe someone can help me with understanding how to send templates via apache commons email here are details https://stackoverflow.com/questions/72558558/ktor-send-email-with-html-template Thanks in advance!
    a
    • 2
    • 1
  • a

    Anders Sveen

    06/09/2022, 10:41 AM
    I am trying to upgrade our code to ktor-client 2.0.2, but getting into a weird situation. ContentNegotiation works and sends JSON (setBody(someMap)) on a POST, but the server rejects it (works fine in previous version 1.x). I have turned on full logging, and the only difference I can see is that in the new version the Content-Length header is not set... Any idea why? I think this migt be the issue, but can't really find a way to "trigger" or set it...
    a
    r
    • 3
    • 26
  • a

    Andi J

    06/09/2022, 7:03 PM
    Hi, I'm working with WebSockets at the moment and can't manage to detect closing frames. This is what the documentation says:
    When handling a session, you can check a frame type, for example:
    • Frame.Text is a text frame. For this frame type, you can read its content using Frame.Text.readText().
    • Frame.Binary is a binary frame. For this type, you can read its content using Frame.Binary.readBytes().
    • Frame.Close is a closing frame. You can call Frame.Close.readReason() to get a close reason for the current session.
    Use the close function to send a close frame with the specified reason.
    I need to remove my Connection instance from a set, when the channel is closed. But in this code the cleanup is never called, when the other side uses the close function:
    try {
        for (frame in session.incoming) {
            when (frame) {
                is Frame.Text -> {
                    // ...
                }
                is Frame.Close -> {
                    // Do cleanup
                }
                else -> {}
            }
        }
    } catch (e: ClosedReceiveChannelException) {
        println("onClose ${session.closeReason.await()}")
        // Do cleanup
    } catch (e: Throwable) {
        println("onError ${session.closeReason.await()}")
        // Do cleanup
    }
    So how do I react to closing frames correctly?
    a
    • 2
    • 3
  • j

    Julius

    06/10/2022, 1:09 AM
    Hey! 🙂 I'm wondering how I can iterate over incoming websocket messages while using serialization as shown here?
    for (frame in incoming) {
                val data = receiveDeserialized<Data>()
                println(data)
            }
    This is pretty much what I'd like to do, but the
    for (frame in incoming)
    part already consumes data from the queue, so I'm kinda confused how to properly iterate over it
    d
    a
    • 3
    • 7
  • a

    Arnab

    06/10/2022, 9:35 AM
    This has me confused. I just started a new ktor project and this was amongst the things that I got as part of the ktor project generator page. Apparently intellij doesn’t recognize
    startsWith
    as a method that can be called on a string 😮 Any clues?
    e
    a
    • 3
    • 13
  • b

    Benjamin Deroche

    06/10/2022, 3:07 PM
    How can I disable hostname verification with Ktor CIO Client ? With Okhttp I could just do this but haven't found the solution for CIO:
    HttpClient(OkHttp) {
                engine {
                    config {
                        hostnameVerifier {
                                _, _ -> true
                        }
                    }
                }
            }
    a
    • 2
    • 1
  • m

    Mikhail

    06/12/2022, 10:10 AM
    Hi folks. I want to upload a huge multipart file to my server via Ktor Client. Any ideas or tips? The file is considered to be larger than 2GB.
    f
    t
    +2
    • 5
    • 12
  • k

    kevin.cianfarini

    06/13/2022, 3:51 AM
    What is the default request timeout for a Ktor client instance which does not have the timeout feature installed?
    a
    • 2
    • 1
  • i

    IsaacMart

    06/13/2022, 6:12 AM
    Hello guys i use koin for my depedency injection.i have heard that there is an issue with ktor 2.0, has the issue been resolved or i should stick to ktor 1.6.8?
    s
    • 2
    • 2
  • s

    Stefan Oltmann

    06/13/2022, 3:04 PM
    I use Ktor 1.6.8 and to work in parallel (multiple NSThreads) on iOS I call my httpClient.get() inside a
    CoroutineWorker.withContext(Dispatchers.Default) {}
    block. I use the
    IosClientEngine
    for my HttpClient. In normal conditions it works fine, but in a CoroutineWorker context I get
    kotlin.native.concurrent.FreezingException: freezing of InvokeOnCompletion@e9e588[job@149d2c8] has failed, first blocker is BlockingCoroutine{Completing}@e5b248
    Because it's not production ready I can't really use the new memory model yet. So I need to solve it with the old one and CoroutineWorker. How do I need to wrap my KTor HttpClient calls?
    ✅ 1
    e
    • 2
    • 5
  • m

    MarkRS

    06/13/2022, 4:48 PM
    The migration docs for 2.x say that I can receive an arbitrary object with (something like)
    val customer: Customer = client.get("<http://localhost:8080/customer/3>").body()
    and I'm assuming this works for post too, but whatever I do I can't find a way to do this in commonMain of a KMM app. Does this need to be platform specific? I've got the content negotiation plugin loaded into the HttpClient, and imported into the class making the call, it just complains that "body" is an unresolved reference. Can someone point me in the right direction, please.
    r
    • 2
    • 3
  • t

    Tucker Barbour

    06/14/2022, 12:46 PM
    I’m curious how to potentially have “nested” authentication configurations. The use-case is a user authenticates with OAuth2 and then store the session information. Then within a session authenticated route, allow the user to authenticate with OAuth2 using a different provider to perform actions on their behalf. The only way I’ve found is to manually perform the OAuth2 flow with a session authenticated route rather than being able to use the oauth2 authentication plugin.
    • 1
    • 1
  • b

    Big Chungus

    06/14/2022, 4:40 PM
    Which kotlin version is ktor-client:2.0.2 compatible with? Getting weird linxX64 curl engine linking errors with K1.7.0
    a
    j
    • 3
    • 5
  • j

    Júlio Santos

    06/14/2022, 9:25 PM
    Are you having memory leakage problems with ktor?
    ❓ 1
    a
    • 2
    • 11
  • m

    Mikhail

    06/15/2022, 2:07 PM
    is there any convenient way to download a huge file with Ktor using OutputStream? The file is considered to be larger than 2GB. I previously asked almost the same question
    a
    • 2
    • 3
  • j

    jmfayard

    06/15/2022, 5:19 PM
    Hello friends I'm writing my first ktor plugin for GraphQL Kotlin which is very nice, apart from the initial setup which is very not nice. It's my first ktor plugin, any feedback ? https://github.com/jmfayard/graphql-kotlin/blob/ktor-plugin/examples/server/ktor-s[…]/com/expediagroup/graphql/examples/server/ktor/GraphQLModule.kt
    👀 3
    :kotlin-intensifies: 1
    m
    • 2
    • 4
  • b

    bbaldino

    06/15/2022, 10:00 PM
    Is there a good pattern anyone uses to test mocking both successful and error responses from a server when testing a client? So you’d normally have something like:
    val mockHttpClient = HttpClient(MockEngine) {
        engine {
            addHandler { request -> {
                when (request.url.encodedPath) {
                    "url1" -> respond(someSuccessResponse)
                }
            }
        }
    }
    val client = MyClient(mockHttpClient)
    ...
    but I want to be able to test how
    MyClient
    handles different kinds of responses when hitting
    url1
    , but the mock engine config is fixed…is there a good way to be able to change it to simulate different responses?
    a
    • 2
    • 3
  • h

    Helio

    06/16/2022, 7:09 AM
    Hello team, While upgrading another of our projects from Ktor V1 to Ktor V2, we noticed that a couple of our integration tests were failing... After doing an investigation and comparing the behaviour between Ktor V1 and Ktor V2 we noticed that some of the mockks are no longer working as expected. I wonder if this is an issue with Ktor or if there was any behaviour change that I couldn’t find. Apparently the
    testApplication
    starts a separate Classloader where the mocked classes/objects are not visible. Is this expected?
    a
    • 2
    • 25
  • i

    IsaacMart

    06/16/2022, 2:17 PM
    Hello team, am new to mongodb and am using it for my ktor project. How can i return the inserted document back to client after insertion. I need the doc to store it in room
    a
    • 2
    • 3
  • d

    dodalovic

    06/17/2022, 6:11 AM
    Hi, after trying to upgrade from
    2.0.1
    to
    2.0.2
    my tests using
    externalServices
    started failing. Any experience of that kind?
    e
    a
    r
    • 4
    • 16
  • j

    Joakim Forslund

    06/17/2022, 1:48 PM
    Hi, I reported this https://youtrack.jetbrains.com/issue/KTOR-4297/aSocket-for-Native-Linux-is-leaking-if-host-and-port-is-unreachable and this https://youtrack.jetbrains.com/issue/KTOR-4298/embeddedServer-CIO-for-Native-Linux-with-[…]-serialization-kotlinx-json-seems-to-be-leaking-for-every regarding memory leaks some time ago, I can't publish my code into production, because the host also declines hosting the docker images because of leak detection as well, is something being done about this? Can I supply more information to help out?
    a
    n
    e
    • 4
    • 7
  • r

    rrva

    06/18/2022, 6:58 PM
    If I have a length-prefixed protocol, how can I use bytepacketbuilder to first build a temp packet, then count the length and then really write it ?
    a
    • 2
    • 2
  • m

    Matt Nelson

    06/19/2022, 9:09 PM
    Trying to run KTor server on Android setup to use a Unix Domain Socket so that I can expose it as a Tor HiddenService. It's working now using HTTPS, but it looks like unix domain sockets are Java16+ only? Any chance there could be some wedge in there to use either
    android.net.LocalSocket
    -OR-
    java.net.UnixDomainSocketAddress
    ?
    a
    • 2
    • 2
  • d

    dodalovic

    06/20/2022, 7:22 AM
    One question for the team: our vulnerabilities scanner reports that we have quite some libs in
    2.0.1
    that are very outdated, and that impose security risks. Will this be addressed?
    h
    a
    • 3
    • 6
  • r

    robin

    06/20/2022, 10:51 AM
    After updating our Ktor webservice from Ktor 1.6 to 2.0, we've been having troubles to get the CORS plugin to handle preflight requests correctly. Basically, OPTIONS requests will always be answered with a 405 Method Not Allowed no matter what you do, unless you explicitly specify the options route in your routing plugin. This seems to not be a problem with the CORS plugin itself, but rather a side effect of this issue being solved, which prevents the CORS plugin from ever being called for OPTIONS requests to a route where no options handler is installed, but another method handler exists. Is there a recommended workaround for that? The only solution I've found so far that fixes this for all routes without specifying an explicit options handler for each one individually is adding this generic catch-all handler to the top level routing:
    options("{...}") { }
    But that feels like a hack, and I'm not even sure it doesn't produce unwanted side effects, even though CORS seems to work correctly with it. Isn't there a way to let CORS handle preflight requests fully automatically without having to add this?
    a
    • 2
    • 8
  • p

    Partho Paul

    06/20/2022, 4:28 PM
    Hi everyone, I’m trying to fetch an application from dynamodb using latest aws sdk. I’m doing it as below:
    getDynamoDbClient().getItem {
    
                    tableName = TABLE_NAME
                    key = request
                }
    When I’m running this piece of code, I’m getting VerifyError Exception. Can someone please help me figuring out what I’m doing wrong? Attached in thread is the full error message. Kotlin version: 1.7.0, Ktor version: 2.0.2, aws version: 0.16.0 TIA
    a
    • 2
    • 3
Powered by Linen
Title
p

Partho Paul

06/20/2022, 4:28 PM
Hi everyone, I’m trying to fetch an application from dynamodb using latest aws sdk. I’m doing it as below:
getDynamoDbClient().getItem {

                tableName = TABLE_NAME
                key = request
            }
When I’m running this piece of code, I’m getting VerifyError Exception. Can someone please help me figuring out what I’m doing wrong? Attached in thread is the full error message. Kotlin version: 1.7.0, Ktor version: 2.0.2, aws version: 0.16.0 TIA
Bad type on operand stack
Exception Details:
  Location:
    Generated_for_debugger_class$generated_for_debugger_fun$1$1.invoke(Laws/sdk/kotlin/services/dynamodb/model/GetItemRequest$Builder;)V @8: getfield
  Reason:
    Type 'Generated_for_debugger_class$generated_for_debugger_fun$1$1' (current frame, stack[1]) is not assignable to 'Generated_for_debugger_class$generated_for_debugger_fun$1'
  Current Frame:
    bci: @8
    flags: { }
    locals: { 'Generated_for_debugger_class$generated_for_debugger_fun$1$1', 'aws/sdk/kotlin/services/dynamodb/model/GetItemRequest$Builder' }
    stack: { 'aws/sdk/kotlin/services/dynamodb/model/GetItemRequest$Builder', 'Generated_for_debugger_class$generated_for_debugger_fun$1$1' }
  Bytecode:
    0000000: 2b12 2db8 0033 2b2a b400 37b6 003d 1221
    0000010: 123f b600 4559 1210 b600 4b5a 575b 575f
    0000020: 5d58 b600 4f2b 2ab4 0051 b400 5512 2112
    0000030: 57b6 0045 5912 10b6 004b 5a57 5b57 5f5d
    0000040: 58b6 004f b1
a

Aleksei Tirman [JB]

06/20/2022, 5:57 PM
Could you please explain how this problem is related to the Ktor framework?
p

Partho Paul

06/21/2022, 4:40 AM
@Aleksei Tirman [JB] Posted here since I couldn’t find any channel for aws. Let me know if there’s a channel for this query.
View count: 21