Amir Rudd
08/13/2021, 1:24 AM* What went wrong:
Execution failed for task ':presentation:minifyBrandProductionReleaseWithR8'.
> Could not resolve all files for configuration ':presentation:brandProductionReleaseRuntimeClasspath'.
> 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=brandProductionRelease, org.gradle.libraryelements=jar, org.gradle.status=release, org.gradle.usage=java-runtime, org.jetbrains.kotlin.platform.type=jvm}.
> Execution failed for AsmClassesTransform: /root/.gradle/caches/transforms-3/0442ceba8861991962529ab9a6c53c81/transformed/jetified-ktor-client-core-jvm-1.6.2.jar.
> Index -1 out of bounds for length 0
Muhammad Usman
08/13/2021, 4:21 AMh3{+"a < b"}
it display as it is rather then less then sign. how html entities can be displayed?Łukasz Bednarczyk
08/13/2021, 10:58 AMJonathan Hollingsworth
08/14/2021, 3:57 AMkotlin("plugin.serialization") version "1.5.20"
declared in my build.gradle.kts
file, and yet I cannot use the *import* kotlinx.serialization.Serializable
in my code. The "External Libraries" part of the project explorer does not show Gradle:io.ktor:ktor-serialization:1.6.1
like the example code in https://ktor.io/docs/creating-http-apis.html does when I run that.
I'm not sure what I need to do in order to get IntelliJ/Gradle to install the necessary dependencies so I can use them in the code?v79
08/14/2021, 9:35 AMauthenticate()
or do you just add authenticate()
to the routes which actually do the authentication? I'm terribly confused.Jgafner
08/14/2021, 10:48 AMappengine {
stage {
artifact = "build/libs/$project.name-$project.version-all.jar"
}
So missing some curly braces:
appengine {
stage {
artifact = "build/libs/${project.name}-${project.version}-all.jar"
}
Danish Ansari
08/14/2021, 2:47 PM0.0.0.0
to 0.0.0.0/project_name
but while running I'm getting java.nio.channels.UnresolvedAddressException
What's the correct way to change host URL?Jonathan Hollingsworth
08/15/2021, 3:05 AMjdiaz
08/15/2021, 3:38 PMStylianos Gakis
08/15/2021, 10:15 PMignoreUnknownKeys = true
.
And I am using the post("path") { myType: MyType -> //code }
syntax. I could potentially change this with
val login: Login = try {
call.receive()
} catch (e: SerializationException) {
return@post call.respondWith(Response.badRequest(InvalidInput))
}
Or even val login: Login = call.receiveOrNull() ?: return@post call.respondWith(Response.badRequest(InvalidInput))
But I don’t necessarily like this if there is an alternative.
How would I deal with this? Can I create an interceptor that catches all SerializationExceptions? Something else? Is my proposed solution the only way? I really do want to use the typed version of the post() method if possible.Slackbot
08/16/2021, 2:37 AMYuval Dryer
08/16/2021, 3:51 PMPiotr Krzemiński
08/16/2021, 7:22 PMio.ktor.features.CORS.respondCorsFailed(CORS.kt:604)
It points to line 604 where CORS.kt has only 537 lines... I know it seems to be not really related to ktor, but probably Kotlin in general, but has anyone faced something similar or understands why it happens? If not, I'm going to report it as a Kotlin bug.Angad
08/17/2021, 6:20 AMprivate fun handle(config: Config, scope: HttpClient) {
scope.receivePipeline.intercept(HttpReceivePipeline.Before) { response ->
if (context.response.status == HttpStatusCode.Unauthorized) {
val client = HttpClient(scope.engine)
var newResponse: HttpResponse = context.response
runCatching {
val accessToken = config.tokenRefreshService?.getAccessToken()
val requestBuilder = request {
url(context.request.url)
headers {
for (header in context.request.headers.names()) {
if (header != AUTH_TOKEN) {
append(header, context.request.headers[header] ?: "")
} else {
append(header, NetworkModule.authToken(accessToken ?: ""))
}
}
}
method = context.request.method
body = context.request.content
}
client.request(requestBuilder) as HttpResponse
}.onSuccess {
newResponse = it
}.onFailure {
newResponse = response
}
client.close()
if (newResponse == context.response) {
proceed()
} else {
proceedWith(newResponse)
}
}
}
}
Please can someone help with this? I was expecting that by updating the subject in proceedWith
it will work.Łukasz Bednarczyk
08/17/2021, 6:49 AMjmfayard
08/18/2021, 10:19 AMHarrison
08/19/2021, 8:15 AMŁukasz Bednarczyk
08/20/2021, 8:24 AMcodec
08/20/2021, 5:09 PMktor.locations
? why does get<Object> work, but not post<Object> not work?Łukasz Bednarczyk
08/20/2021, 7:13 PMthanh
08/20/2021, 7:59 PMJan
08/20/2021, 8:20 PMrouting {
static("/static") {
staticBasePackage = "/home/pi/Raspy/"
files("public")
}
}
2021-08-20 22:15:54.514 [eventLoopGroupProxy-4-2] TRACE ktor.application - Failed to decode request
java.lang.IllegalArgumentException: invalid version format: XV�PÒ�ÆICL;ÅËÊ)|$À+À/̨̩À,À0À
URL I try: https://localhost:26666/static/public/test.txtTheDukerChip
08/21/2021, 6:04 AMHarrison
08/21/2021, 2:10 PMv79
08/21/2021, 4:19 PM{"title":"AA","slug":"BB"}
and I've got an equally simple Serialiable data class TestForm(val title: String, val slug: String)
. Posting the JSON from my web page gets a 415 Unsupported Media Type error. What am I likely to have got wrong in setting up ContentNegotiation?Didier Villevalois
08/21/2021, 4:59 PMktor-io
help. I encounter some difficulties because ReadByteChannel
and ByteReadPacket
don't share a common super-interface for all the read***
operations. I have to read a possibly large amount X of bytes (up to 2^63-1) from a ReadByteChannel
. The precise number X of bytes is read first then I wish to delegate the read of the content of those X bytes to a sub-method which have to read (in this amount of bytes) an unknown number of packets of different sizes. My problem is that readPacket(size: Int)
takes an Int
and not a Long
(and also that may be crazy to load a possibly very large number of bytes in memory). Ideally, I would like to create as "sub-channel" with a limit (of X bytes). Any hint on how I should proceed ? (Please tell me if I am not clear enough.)Slackbot
08/21/2021, 5:19 PMJonathan Hollingsworth
08/22/2021, 10:36 PMget("/user/{login}") {
if (call.parameters["login"] == "admin") {
// ...
}
}
But from looking at the definition call
just seems an alias for context
- what is the reason for the convention that has us using call
over context
in this situation?
(Kotlin noob, so feel free just to point me at the docs and RTFM me)Łukasz Bednarczyk
08/23/2021, 12:22 PMResponse has already been sent
io.ktor.server.engine.BaseApplicationResponse$ResponseAlreadySentException: Response has already been sent
but only in tests and only in the situation when I call
every { something, something } throws AnyException
Did you have similar problem?Anton Afanasev
08/23/2021, 12:28 PMonUpload
API on KMM platform. Android works fine, but iOS produce an InvalidMutabilityException
.I am looking for any feedback from the community. I am using ktor = 1.6.0
suspend fun uploadFile(
url: String,
byteArray: ByteArray,
progressCallback: (Float) -> Unit
) {
client.put<Unit>(url) {
onUpload { bytesSendTotal: Long, contentLength: Long ->
progressCallback((bytesSendTotal / contentLength.toFloat()) * 100)
}
body = byteArray
}
}
I call it from another class that is responsible for managing states of the uploaded object.
Dispatcher:
private val uploadDispatcher = CoroutineScope(Dispatchers.Main + SupervisorJob())
Call to the function:
uploadDispatcher.launch { api.uploadFile(url, byteArray) { progress ->
data = data.copy(state = Uploading(progress))
.also(onUploadProgress)
}
}
where the onUploadProgress
is lambda:
private val onUploadProgress: (Data) -> Unit,
As mentioned above, while executing this code on iOS I am receiving an InvalidMutabilityException
Looking into Ktor, it looks like the
UploadProgressListenerAttributeKey
marked with @SharedImmutable
which makes it deeply frozen and freeze the objects it refers to.
Considering that when upload progress change I need to wrap and update state sof my internal objects - how should I do that using provided onUpload
API?Anton Afanasev
08/23/2021, 12:28 PMonUpload
API on KMM platform. Android works fine, but iOS produce an InvalidMutabilityException
.I am looking for any feedback from the community. I am using ktor = 1.6.0
suspend fun uploadFile(
url: String,
byteArray: ByteArray,
progressCallback: (Float) -> Unit
) {
client.put<Unit>(url) {
onUpload { bytesSendTotal: Long, contentLength: Long ->
progressCallback((bytesSendTotal / contentLength.toFloat()) * 100)
}
body = byteArray
}
}
I call it from another class that is responsible for managing states of the uploaded object.
Dispatcher:
private val uploadDispatcher = CoroutineScope(Dispatchers.Main + SupervisorJob())
Call to the function:
uploadDispatcher.launch { api.uploadFile(url, byteArray) { progress ->
data = data.copy(state = Uploading(progress))
.also(onUploadProgress)
}
}
where the onUploadProgress
is lambda:
private val onUploadProgress: (Data) -> Unit,
As mentioned above, while executing this code on iOS I am receiving an InvalidMutabilityException
Looking into Ktor, it looks like the
UploadProgressListenerAttributeKey
marked with @SharedImmutable
which makes it deeply frozen and freeze the objects it refers to.
Considering that when upload progress change I need to wrap and update state sof my internal objects - how should I do that using provided onUpload
API?Igor Maric
08/23/2021, 2:16 PMAleksei Tirman [JB]
08/23/2021, 2:36 PMdata = data.copy(state = Uploading(progress))
.also(onUploadProgress)
}
Anton Afanasev
08/23/2021, 2:42 PMdata
is actually a mutable map:
private val dataMap = mutableMapOf<String, Data>()
@Serializable
private class Data(
val state: Data.State = Data.State.Idle,
val id: String? = null,
val fileName: String,
var byteArray: ByteArray,
var job: Job? = null,
) {
@Serializable
sealed class State {
object Idle : State()
object Deleted : State()
object Detached : State()
object Presigning : State()
data class Uploading(val progress: Float) : State()
data class Uploaded(val downloadUrl: String) : State()
data class Sent(val downloadUrl: String) : State()
}
}
I am using Data
to report changes with this object. Potentially there are can be multiple data
objects handle in the same time.progress
is the outcome of progressCallback that is invoked every ktor.onUpdate() and simply convert the progress to percentage amountAleksei Tirman [JB]
08/23/2021, 2:51 PMInvalidMutabilityException
reproducible without using definitions for all those classes?Anton Afanasev
08/23/2021, 2:52 PMUploadProgressListenerAttributeKey
and DownloadProgressListenerAttributeKey
in io.ktor.client.features
They annotated with @SharedImmutable. Wondering if it is necessary, as apparently this is the reason why my own listener and data structure that handle onUpload/onDownload become frozen as well. And since I am trying to mutate them I got an In InvalidMutabilityException
.
Thank you in advanceAleksei Tirman [JB]
08/25/2021, 8:54 AMonDownload
lambda if those objects were defined outside of it. I've created an issue KTOR-3068 to address this problem. Unfortunately, I don't know how to work around this issue.russhwolf
08/25/2021, 12:26 PMflag
atomicAnton Afanasev
08/25/2021, 1:01 PMonDownload
and onUpload
listeners.russhwolf
08/27/2021, 1:29 PM