bselfemim
07/29/2025, 12:45 PMAleksei Tirman [JB]
07/29/2025, 12:47 PMbselfemim
07/29/2025, 1:08 PMprivate class CustomConverter(): ContentConverter {
override suspend fun deserialize(charset: Charset, typeInfo: TypeInfo, content: ByteReadChannel): Any? {
return JSON.parse(content.readRemaining().readText(charset))
}
override suspend fun serialize(
contentType: ContentType,
charset: Charset,
typeInfo: TypeInfo,
value: Any?
): OutgoingContent? {
return value?.let { TextContent(JSON.stringify(value), contentType.withCharsetIfNeeded(charset)) }
}
}
... {
HttpClient(Js) {
install(ContentNegotiation) {
register(ContentType.Application.Json, CustomConverter())
}
install(Logging) {
level = LogLevel.ALL
}
}.use { httpClient ->
val response = httpClient.get {
url {
this.protocol = URLProtocol.HTTP
this.host = host
this.port = port
appendPathSegments(CHECKIN_URL)
}
}
if (response.status == HttpStatusCode.OK) {
val clientIdAndKey: ClientIdAndKey = response.body()
return ApiClient(clientIdAndKey)
} else {
return null
}
}
}
Aleksei Tirman [JB]
07/29/2025, 1:10 PMHttpResponse.bodyAsText()
. Can you print out the response headers?bselfemim
07/29/2025, 1:12 PMbodyAsText()
still just returns an empty String. The ContentType
header is applied correctly as application/json
and it will even log as much in the deserialize
function but content
is always just an empty SourceByteReadChannel
. Checking it's closed cause just returns null.Aleksei Tirman [JB]
07/29/2025, 1:13 PMbselfemim
07/29/2025, 1:23 PMClientIdAndKey
which is a custom data class with a String and ByteArray.bselfemim
07/29/2025, 1:24 PMAleksei Tirman [JB]
07/29/2025, 1:25 PMbselfemim
07/29/2025, 1:25 PMAleksei Tirman [JB]
07/30/2025, 8:22 AMfetch
from the same origin as the server or from a different one?bselfemim
07/30/2025, 12:20 PMAleksei Tirman [JB]
07/30/2025, 12:35 PMbselfemim
07/30/2025, 12:55 PMfetch
for context the KtorJS client request does still succeed, it just returns an empty response. Unless CORS configurations would somehow affect the response body?Aleksei Tirman [JB]
08/01/2025, 10:10 AMbselfemim
08/01/2025, 12:37 PMktor-samples/client-mpp
project to target my local dev server with the same endpoints I've been testing and can confirm that works when just running purely in kotlin-js by running the jsBrowserDevelopmentRun
gradle task, but if I try and package it as a JS library and import it into a JS/TS project that's when the requests start receiving empty response bodies. So I'm left wondering if the compilation to javascript is causing the client's response parsing functions to not properly suspend or something?bselfemim
08/01/2025, 12:38 PMjs(IR) {
browser()
binaries.library()
useEsModules()
generateTypeScriptDefinitions()
}