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

    James Black

    04/15/2022, 5:39 AM
    Why am I getting this error? Cannot access 'java.io.Closeable' which is a supertype of 'io.ktor.client.HttpClient'. Check your module classpath for missing or conflicting dependencies Cannot access 'java.lang.AutoCloseable' which is a supertype of 'io.ktor.client.HttpClient'. Check your module classpath for missing or conflicting dependencies My application still runs so I think the problem is that Android Studio can't find the class. I am using Kotlin 1.6.10 and this is a KMP subproject. I have tried both of these in my build.gradle.kts and neither solves the error the IDE is reporting.
    implementation("org.jetbrains.kotlin:kotlin-stdlib")
    And
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.10")
    I am using ktor 2.0.0 and I also have this in build.gradle.kts:
    java {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
    a
    • 2
    • 2
  • z

    zeugederunity

    04/15/2022, 6:24 AM
    Hey everyone, I'm using ktor 2.0.0 in a Kotlin-1.6.20 MPP subproject. I have a strange error where the JVM-ktor-dependencies do not only load the normal library versions like ktor-server-core:2.0.0 but also the ktor-server-core: jvmAndNixMain:2.0.0. Ktor is the only library causing this issue, so I think I either found a bug or did some misstake somewhere in my gradle buldscript. My build.gradle.kts looks basically like this:
    kotlin {
        val ktorVersion: String by project /* 2.0.0 */
        jvm { /* some blabla */ }
        js { /* some blabla */ }
        sourceSet {
            val commonMain by getting { /* some blabla */ }
            val jsMain by getting { /* some blabla */ }
            val jvmMain by getting {
                dependencies {
                    implementation("io.ktor:ktor-server-netty:$ktorVersion")
                    implementation("io.ktor:ktor-server-status-pages:$ktorVersion")
                    /*And some more */
                }
            }
            val jvmTest by getting {
                dependencies {
                    implementation("io.ktor:ktor-server-test-host:$ktorVersion")
                }
            }
        }
    }
    The external libraries look like this:
    /*ktor-server-auth has no jvmAndNixMain*/
    Gradle: io.ktor:ktor-server-auth-jvm:2.0.0
    Gradle: io.ktor:ktor-server-auth-jwt-jvm:2.0.0
    Gradle: io.ktor:ktor-server-auto-head-response:jvmAndNixMain:2.0.0
    Gradle: io.ktor:ktor-server-auto-head-respone:2.0.0
    
    /*Some more libs with the each the corresponding jvmAndNixMain */
    
    Gradle: io.ktor:ktor-server-core-jvm:jvmAndNixMain:2.0.0
    Gradle: io.ktor:ktor-server-core-jvm:2.0.0
    Is this a bug or does anyone know what I did wrong? Thank you for your help in advance!
    a
    h
    • 3
    • 11
  • r

    ribesg

    04/15/2022, 2:45 PM
    Re: Ktor 2 Resources documentation Does the
    "new"
    parameter value make any sense on this specific line? https://github.com/ktorio/ktor-documentation/blob/main/codeSnippets/snippets/resource-routing/src/main/kotlin/com/example/Application.kt#L19
    d
    • 2
    • 1
  • v

    Viktor Orlyk

    04/15/2022, 6:20 PM
    Hi is this website currently not working ? https://api.ktor.io/
    g
    a
    • 3
    • 5
  • s

    S.

    04/15/2022, 6:37 PM
    so
    get().body<List<Class>>()
    apparently also expects the json input to be an array and when it only returns one object I always run into
    kotlinx.serialization.json.internal.JsonDecodingException: Expected start of the array '[', but had 'EOF' instead
    is there a way around this other than catching the exception and
    .body<Class>
    ?
    a
    p
    p
    • 4
    • 5
  • v

    Viktor Orlyk

    04/17/2022, 8:10 AM
    Can someone please help me with understanding what is wrong with my response parsing in ktor https://stackoverflow.com/questions/71900269/ktor-failing-to-parse-response-no-transformation-found-class-io-ktor-utils-io-b
    val client = HttpClient(CIO) {
                install(ContentNegotiation) {
                    json(Json {
                        prettyPrint = true
                        isLenient = true
                    })
                }
            }
    my ide shows an error in there
    'fun <P : Pipeline<*, ApplicationCall>, B : Any, F : Any> Application.install(plugin: Plugin<Application, ContentNegotiationConfig, PluginInstance>, configure: ContentNegotiationConfig.() -> Unit = ...): PluginInstance' can't be called in this context by implicit receiver. Use the explicit one if necessary
    a
    • 2
    • 5
  • d

    David Stibbe

    04/17/2022, 3:08 PM
    We are mirgating to Ktor 2.0 and have a RoleAuthorization Feature (now Pluging) that is registered on the pipeline after the
    Authentication.Feature.AuthenticatePhase
    phase. However, this phase does not exist anymore. According to the documentation there is a
    CheckAuthentication
    phase. Is there a specific constant that identifies this phase so I can register our plugin after this specific phase?
    r
    d
    • 3
    • 8
  • n

    Nabil

    04/17/2022, 5:49 PM
    Is Ktor
    2.0.0
    compatible with coroutines
    1.6.1-native-mt
    using the old memory model? I'm under the impression only the new memory model is supported after this was merged https://github.com/ktorio/ktor/pull/2739 ? Using the old memory model throws
    kotlin.native.IncorrectDereferenceException: Trying to access top level value not marked as @ThreadLocal or @SharedImmutable from non-main thread
            at kotlin.Throwable#<init>(/Users/teamcity1/teamcity_work/6326934d18cfe24e/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/Throwable.kt:24)
            at kotlin.Exception#<init>(/Users/teamcity1/teamcity_work/6326934d18cfe24e/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/Exceptions.kt:23)
            at kotlin.RuntimeException#<init>(/Users/teamcity1/teamcity_work/6326934d18cfe24e/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/Exceptions.kt:34)
            at kotlin.native.IncorrectDereferenceException#<init>(/Users/teamcity1/teamcity_work/6326934d18cfe24e/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/native/Runtime.kt:34)
            at <global>.ThrowIncorrectDereferenceException(/Users/teamcity1/teamcity_work/6326934d18cfe24e/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/native/internal/RuntimeUtils.kt:105)
            at <global>.CheckGlobalsAccessible(Unknown Source)
            at io.ktor.client.plugins#<get-PLUGIN_INSTALLED_LIST>(/Users/administrator/Documents/agent/work/8d547b974a7be21f/ktor-client/ktor-client-core/common/src/io/ktor/client/plugins/HttpClientPlugin.kt:11)
            at io.ktor.client.HttpClientConfig.install$<anonymous>_1-3#internal(/Users/administrator/Documents/agent/work/8d547b974a7be21f/ktor-client/ktor-client-core/common/src/io/ktor/client/HttpClientConfig.kt:74)
            at io.ktor.client.HttpClientConfig.$install$<anonymous>_1-3$FUNCTION_REFERENCE$7.invoke#internal(/Users/administrator/Documents/agent/work/8d547b974a7be21f/ktor-client/ktor-client-core/common/src/io/ktor/client/HttpClientConfig.kt:122)
            at io.ktor.client.HttpClientConfig.$install$<anonymous>_1-3$FUNCTION_REFERENCE$7.$<bridge-UNNN>invoke(/Users/administrator/Documents/agent/work/8d547b974a7be21f/ktor-client/ktor-client-core/common/src/io/ktor/client/HttpClientConfig.kt:122)
            at io.ktor.client.HttpClientConfig#install(/Users/administrator/Documents/agent/work/8d547b974a7be21f/ktor-client/ktor-client-core/common/src/io/ktor/client/HttpClientConfig.kt:96)
            at io.ktor.client.HttpClient#<init>(/Users/administrator/Documents/agent/work/8d547b974a7be21f/ktor-client/ktor-client-core/common/src/io/ktor/client/HttpClient.kt:165)
            at io.ktor.client.HttpClient#<init>(/Users/administrator/Documents/agent/work/8d547b974a7be21f/ktor-client/ktor-client-core/common/src/io/ktor/client/HttpClient.kt:82)
            at io.ktor.client#HttpClient(/Users/administrator/Documents/agent/work/8d547b974a7be21f/ktor-client/ktor-client-core/common/src/io/ktor/client/HttpClient.kt:42)
            at io.ktor.client#HttpClient(/Users/administrator/Documents/agent/work/8d547b974a7be21f/ktor-client/ktor-client-core/posix/src/io/ktor/client/HttpClient.kt:20)
            at io.ktor.client#HttpClient$default(/Users/administrator/Documents/agent/work/8d547b974a7be21f/ktor-client/ktor-client-core/posix/src/io/ktor/client/HttpClient.kt:18)
    a
    e
    c
    • 4
    • 6
  • j

    James Black

    04/18/2022, 4:26 AM
    I am trying to get my android app to call my local server. When I do this it works fine:
    curl -X POST -d 'Hello' <http://0.0.0.0:8080/outfit_data>
    success%
    The error I get from android is:
    I/System.out: Failed to connect to /0.0.0.0:8080 calling <http://0.0.0.0:8080/outfit_data>
    This is my ktor 2.0.0 routing:
    post("/outfit_data") {
        val data = call.receive<String>()
        println(data)
        call.respondText("success", null, HttpStatusCode.OK)
    }
    And on the android side this is how I make the call, and baseUrl is set as this is the top-level gradle.properties file
    weather_client_host_name=<http://0.0.0.0:8080>
    try {
        <http://client.post|client.post>(
            "$baseUrl/outfit_data"
        ) {
            contentType(ContentType.Application.Json)
            setBody(data)
        }.also { response ->
            return response.status == HttpStatusCode.OK || response.status == HttpStatusCode.Created
        }
    } catch(e:Throwable) {
        println("${e.message} calling $baseUrl/outfit_data")
        return false
    }
    My code is in the androidApp, shared/androidMain and server subprojects. The http call for Android is in shared/src/androidMain/.../api/WeatherApi.kt I also put this in the android manifest in the shared/src/androidMain:
    <application
        android:usesCleartextTraffic="true">
    https://github.com/jblack975/MyOutfitPicker/tree/pass_anon_data_to_server
    a
    a
    c
    • 4
    • 5
  • s

    suresh

    04/18/2022, 10:55 PM
    Hi, planning to use Ktor 2.0 for a new API backend project and would like to use auto generated OpenAPI yaml and hosted UI. Since there is no official support in 2.0, wondering how you folks are achieving this? Would like to have something like in micronaut (compile time generated yaml from route data https://micronaut-projects.github.io/micronaut-openapi/latest/guide/index.html#openApiViews)
    l
    m
    • 3
    • 8
  • v

    Vivek Modi

    04/19/2022, 11:53 AM
    Hey guys, How can I remove
    Bearer
    keyword from
    authorization
    token in Ktor. I don't want to use these keyword in my api call. I think it call authorization header, but I am not sure. Thanks
    install(Auth) {
        bearer {
            loadTokens {
                BearerTokens("u_b6I4kItp", "xyz111")
            }
        }
    }
    c
    • 2
    • 4
  • v

    Vivek Modi

    04/19/2022, 3:08 PM
    Hey guys, I am reading the doc and I find
    HttpResponseValidator
    is used for api status, correct me If I am wrong. 1. I need to call api, if api returns 401 status, I need to call refershToken api. After getting new accessToken from refreshToken api, I need to send this to api call. 2. If refreshToken is giving 401 then I need to infrom my application to logout. How can I achieve through this Ktor?
    • 1
    • 2
  • a

    Alex

    04/20/2022, 11:36 AM
    Hi Guys, I am new to Ktor and a great fan of the Kotlin language and i have the following questions to better understand if using Ktor is the best option for me I have basic HTML and CSS knowlege, i hate using Javascript the language itself makes me want to faint. 1. I'm planning to build websites using Ktor can i use kotlin instead of Javascript to manage the logic of a website 2. The other thing is why Ktor, because i want to have a proper understanding in what way Ktor is better Thank you
    a
    d
    d
    • 4
    • 6
  • v

    Vivek Modi

    04/20/2022, 2:45 PM
    Hey guys, I used
    @Body
    in retrofit. what is alternative in ktor?
    m
    • 2
    • 8
  • m

    Mark Malik

    04/20/2022, 3:18 PM
    Hello guys, does one know how I would be able to access the ApplicationCall context from outside of te routing handler? Down the line I need to get access to the principal in a service that is being called by a endpoint, passing the principal from the handler is from a design perspective a bad idea in bigger apps. I can try to use the Kotlin Coroutines feature but I’m struggling to find any good examples.
    a
    p
    • 3
    • 7
  • l

    LastExceed

    04/21/2022, 11:39 AM
    how do i configure a timeout for a tcp socket?
    a
    • 2
    • 1
  • j

    Jason Han

    04/21/2022, 8:08 PM
    hi all, is it expected that ByteReadChannel removes newlines? If so, is there a way to preserve the newlines instead?
    e
    • 2
    • 15
  • r

    Renaud

    04/22/2022, 1:58 PM
    Trying to write tests on Ktor2 with kotlinx-serialization. I’m getting this error:
    No request transformation found
    . Does it sound familiar to someone? Looking a ktor source code, it comes from HttpRequest.kt
    body as? OutgoingContent ?: error("No request transformation found: $body")
    It seems related to the setBody function in my test
    @Test
        fun testPostRandom() = testApplication {
            val response = <http://client.post|client.post>("/random") {
                contentType(ContentType.Application.Json)
                setBody(PostRandomRequest(listOf("Jet", "Brains")))
    
            }
            assertEquals("Hello World!", response.bodyAsText())
            assertEquals(HttpStatusCode.Created, response.status)
        }
    a
    p
    • 3
    • 6
  • n

    Nikky

    04/23/2022, 12:29 AM
    how do i use JWT auth with
    optional=true
    ? in my code when the token verification fails it always responds with 401, even when set up like so
    authenticate("auth-jwt", optional = true) {
    any tricks that i can do to evad whats in
    JWTUtils.kt#verifyAndValidate at lines 96-99
    ? from how i read the documentation a failed auth should lead to a principal being null.. but in this case it never hits my code and always just jumps to the challenge... PS: diging into the code.. seems like
    AuthenticationFailedCause.InvalidCredentials
    is still responded with a 401 and token verification failure, eg. expired token or signing key differs or such.. will trigger that i'd prefer to treat it as if it was a
    AuthenticationFailedCause.NoCredentials
    for now i copied the
    JWTAuthenticationProvider
    and all the internal classes it uses.. just to change one line...
    a
    • 2
    • 2
  • r

    russhwolf

    04/23/2022, 3:36 AM
    The following test succeeded in ktor 2.0.0-beta-1
    @Test
        fun errorTest() = runTest {
            val engine = MockEngine {
                respondError(HttpStatusCode.NotFound)
            }
            val httpClient = HttpClient(engine) {
                install(ContentNegotiation) {
                    json()
                }
            }
            assertFailsWith<ClientRequestException> { httpClient.get("<https://example.com/>").body<Message>() }
        }
    
    @Serializable
    data class Message(val data: String)
    In 2.0.0 the test fails with
    Expected an exception of class io.ktor.client.plugins.ClientRequestException to be thrown, but was io.ktor.client.call.NoTransformationFoundException: No transformation found: class io.ktor.utils.io.ByteBufferChannel
    . It seems like the http client is attempting to deserialize the error response rather than throwing due to the unsuccessful status code. Was there a deliberate behavior change here or is this a bug?
    • 1
    • 1
  • b

    brabo-hi

    04/23/2022, 9:58 PM
    Hi, all it looks like with
    ktor-2.0
    handleResponseException has been deprecated in replacement of
    handleResponseExceptionWithRequest
    . However i am having exception when accessing
    request.call.response.status
    a
    • 2
    • 2
  • v

    Viktor Orlyk

    04/24/2022, 12:00 PM
    Hi, all. Maybe someone can help me understand what is the problem with my code for class serialization? Not to polute the channel posted question on stackoverflow. Thanks in advance! https://stackoverflow.com/questions/71988144/serializer-for-class-is-not-found-mark-the-class-as-serializable-or-prov
    c
    • 2
    • 5
  • h

    Hayden Meloche

    04/25/2022, 12:24 AM
    is there any documentation on how to build a Ktor plugin that supports multi-platform? right now my plugin relies on a few ktor
    *-jvm
    libraries and I believe I need to generate a file like this
    👀 1
    h
    • 2
    • 3
  • m

    Muhammad Talha

    04/25/2022, 7:46 AM
    Hi all! I’m new to Kotlin and Ktor. I just generated a Ktor project from https://start.ktor.io/. I added the routing, content negotiation, and kotlinx.serialization plugins. When I try to build my project I’m getting a
    Unresolved reference: ContentNegotiation
    error in
    com/talhaguy/plugins/Serialization.kt
    . Does any one know how I can get past this error? Thanks in advance! I have a feeling not everything I needed got generated. I was following the https://ktor.io/docs/creating-http-apis.html#source_code tutorial and the
    /src/main/resources/application.conf
    did not get generated either and I manually created it.
    s
    • 2
    • 2
  • l

    Louis

    04/25/2022, 11:20 AM
    Hello , I have audios to store in a Ktor app. I don't know what is the best way to do this. Is is better to store base64 in a database or store audios in a file system like AWS? What are the advantages to use AWS over a base 64 in a db?
    a
    • 2
    • 1
  • j

    Jari Ruokonen

    04/25/2022, 2:52 PM
    Hello everyone! I am developing a project that I inherited and it uses Ktor. After upgrading Ktor from 1.4.2 to 1.6.8, I ran into a weird issue with unit tests. Following is an example test, but they all fail the same with 404 error.
    @Test
        fun `400 Bad request on item sync when request body cannot be parsed`() {
            val invalidItem = "invalid body"
            withTestApplication({
                restService(connector, synchronizer, logger)
            }) {
                handleRequest(true) {
                    method = <http://HttpMethod.Post|HttpMethod.Post>
                    uri = "/synchronize/item"
                    setBody(invalidItem)
                }.apply {
                    assertEquals(HttpStatusCode.BadRequest, response.status())
                }
            }
        }
    This particular test fails with following status: expected: <400 Bad Request> but was: <404 Not Found> Expected : 400 Bad Request Actual : 404 Not Found If I place breakpoints to the tested restService code, they are never reached, like the 404 error hints. I also placed breakpoint to start() method of the RestService and it's being called at the start of the test as expected and I can step through it without errors. If I revert Ktor back to 1.4.2, all the tests run ok - so, what exactly could have changed from 1.4.2 to 1.6.8 that breaks these? The change log is quite lengthy, so I ask for an educated advise.
    a
    • 2
    • 6
  • m

    Martin Gaens

    04/25/2022, 3:16 PM
    How big of a security vulnerability is using Thymeleaf's
    th:utext
    ? I'm trying to render a page using Thymeleaf but there are certain parts of the website which are much easier rendered using
    kotlinx.html
    . I'd like to inject them using
    th:utext
    but this Stackoverflow answer and a comment underneath it says it's a security vulnerability.
    r
    • 2
    • 3
  • m

    MBegemot

    04/26/2022, 9:49 AM
    I have a server and a client, can I move to 2.0 first the client and then the server, or should I move both at the same time?
    j
    • 2
    • 1
  • r

    Rescribet

    04/26/2022, 10:33 AM
    After upgrading from beta1 to 2.0.0, IntelliJ is unable to find
    io.ktor.util.*
    , but I'm seeing this mysterious asterisk after the package in the gradle menu. Adding/removing a dependency (
    io.ktor:ktor-utils:2.0.0
    ) to
    commonMain
    and/or
    jvmMain
    doesn't fix the missing package (can't click through to
    io.ktor.util.Attributes
    from
    ApplicationCall
    )
    a
    • 2
    • 9
  • s

    Satyam Agarwal

    04/27/2022, 9:27 AM
    Hei. We are using CIO engine for our httpclient. And often we see this error right request has been made. We noticed that the request never reaches the server, and dies with the following error while sending. Do you know what is happening, and how we can find more about whats causing it ? Version we use for ktor CIO is 1.6.8
    java.io.EOFException: Invalid chunk: content block of size 8192 ended unexpectedly
    	at io.ktor.http.cio.ChunkedTransferEncodingKt.decodeChunked(ChunkedTransferEncoding.kt:92)
    	at io.ktor.http.cio.ChunkedTransferEncodingKt$decodeChunked$3.invokeSuspend(ChunkedTransferEncoding.kt)
    	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    	at kotlinx.coroutines.internal.DispatchedContinuation.resumeWith(DispatchedContinuation.kt:205)
    	at io.ktor.utils.io.ByteBufferChannel.resumeWriteOp(ByteBufferChannel.kt:2191)
    	at io.ktor.utils.io.ByteBufferChannel.bytesRead(ByteBufferChannel.kt:908)
    	at io.ktor.utils.io.ByteBufferChannel.readAsMuchAsPossible(ByteBufferChannel.kt:533)
    	at io.ktor.utils.io.ByteBufferChannel.readAsMuchAsPossible$default(ByteBufferChannel.kt:514)
    	at io.ktor.utils.io.ByteBufferChannel.readRemainingSuspend(ByteBufferChannel.kt:2154)
    	at io.ktor.utils.io.ByteBufferChannel.readRemaining$suspendImpl(ByteBufferChannel.kt:2128)
    	at io.ktor.utils.io.ByteBufferChannel.readRemaining(ByteBufferChannel.kt)
    	at io.ktor.utils.io.ByteReadChannelKt.readRemaining(ByteReadChannel.kt:212)
    	at io.ktor.util.ByteChannelsKt$split$1.invokeSuspend(ByteChannels.kt:25)
    	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
    	at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
    	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
    	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
    	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)
    a
    • 2
    • 5
Powered by Linen
Title
s

Satyam Agarwal

04/27/2022, 9:27 AM
Hei. We are using CIO engine for our httpclient. And often we see this error right request has been made. We noticed that the request never reaches the server, and dies with the following error while sending. Do you know what is happening, and how we can find more about whats causing it ? Version we use for ktor CIO is 1.6.8
java.io.EOFException: Invalid chunk: content block of size 8192 ended unexpectedly
	at io.ktor.http.cio.ChunkedTransferEncodingKt.decodeChunked(ChunkedTransferEncoding.kt:92)
	at io.ktor.http.cio.ChunkedTransferEncodingKt$decodeChunked$3.invokeSuspend(ChunkedTransferEncoding.kt)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.internal.DispatchedContinuation.resumeWith(DispatchedContinuation.kt:205)
	at io.ktor.utils.io.ByteBufferChannel.resumeWriteOp(ByteBufferChannel.kt:2191)
	at io.ktor.utils.io.ByteBufferChannel.bytesRead(ByteBufferChannel.kt:908)
	at io.ktor.utils.io.ByteBufferChannel.readAsMuchAsPossible(ByteBufferChannel.kt:533)
	at io.ktor.utils.io.ByteBufferChannel.readAsMuchAsPossible$default(ByteBufferChannel.kt:514)
	at io.ktor.utils.io.ByteBufferChannel.readRemainingSuspend(ByteBufferChannel.kt:2154)
	at io.ktor.utils.io.ByteBufferChannel.readRemaining$suspendImpl(ByteBufferChannel.kt:2128)
	at io.ktor.utils.io.ByteBufferChannel.readRemaining(ByteBufferChannel.kt)
	at io.ktor.utils.io.ByteReadChannelKt.readRemaining(ByteReadChannel.kt:212)
	at io.ktor.util.ByteChannelsKt$split$1.invokeSuspend(ByteChannels.kt:25)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
	at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)
cc: @Aleksei Tirman [JB]
a

Aleksei Tirman [JB]

04/27/2022, 4:59 PM
Seems like some problem occurs while parsing a response body. It’s really weird that a request never reaches a server.
s

Satyam Agarwal

04/27/2022, 5:06 PM
Is there something I can go on with to debug the issue ?
a

Aleksei Tirman [JB]

04/27/2022, 5:10 PM
You can use a protocol analyzer like WireShark to capture a request/response and then share it with us.
s

Satyam Agarwal

04/27/2022, 5:13 PM
hmm, this could be hard to do, as this happens only one api, and sporadically. All the other applications I have, use the same http client, engine, and configurations. They have never faced this problem. Neither have I been able to reproduce it. And the issue is in our production environment, where capturing request response in such a way is expensive when we don’t know when it will occur.
View count: 6