MBegemot
08/28/2022, 11:00 AMddimitrov
08/28/2022, 11:26 AMlaunch
-ed coroutines on the IO dispatcher, using blocking receive()
and send()
with timeout, one draining an outbound channel, the other directly updating a map with statistics (guarded by synchronized
section).
Is this the idiomatic way? Am I supposed to use one of the Flow
implementations? Can I somehow plug my I/O into Ktor's selector?S.
08/28/2022, 4:48 PMmaxmello
08/29/2022, 7:36 AMtestApplication
functionality where the application initialization is not called. Please look at my issue https://youtrack.jetbrains.com/issue/KTOR-4819/testApplication-application-initialization-block-not-calledram prasad
08/29/2022, 10:03 AMeirikb
08/29/2022, 1:20 PMval ktorVersion = "2.0.3"
implementation("io.ktor:ktor-client:$ktorVersion")
implementation("io.ktor:ktor-client-core:$ktorVersion")
implementation("io.ktor:ktor-client-apache:$ktorVersion")
implementation("io.ktor:ktor-client-json:$ktorVersion")
implementation("io.ktor:ktor-client-jackson:$ktorVersion")
implementation("io.ktor:ktor-client-logging-jvm:$ktorVersion")
implementation("io.ktor:ktor-client-auth:$ktorVersion")
implementation("io.ktor:ktor-client-websockets:$ktorVersion")
implementation("io.ktor:ktor-client-okhttp:$ktorVersion")
implementation("io.ktor:ktor-client-content-negotiation:$ktorVersion")
implementation("io.ktor:ktor-serialization-jackson:$ktorVersion")
In another lib, LibB we include this lib.
implementation("ourgroup:ourapp:version")
When compiling LibB we get this error:
Cannot access class 'io.ktor.client.statement.HttpResponse'. Check your module classpath for missing or conflicting dependenciesWe don't reference anything from ktor directly in LibB
João Gabriel Zó
08/29/2022, 4:21 PM@JsonNames
but I don’t wanna do it for each one of the fieldsJakub Gwóźdź
08/30/2022, 10:31 AMpost("/fileimport") {
val multipartData = call.receiveMultipart()
val parts = multipartData.readAllParts()
.filterIsInstance<PartData.FileItem>()
.mapIndexed { index, item ->
UploadedContent(
name = item.name ?: "unnamed$index",
filename = item.originalFileName ?: "unnamed$index",
contentType = item.contentType,
bytes = item.provider.invoke().readBytes()
)
}
doSomething(parts)
call.respond("OK")
}
so the questions is - do I need to somehow close resources created by call.receiveMultipart()
or item.provider.invoke().readBytes()
?Hamza GATTAL
08/31/2022, 7:06 AMMarc Plano-Lesay
08/31/2022, 9:08 AMonCallRespond
/ transformBody
, the data
argument I get is Any
. When printing its type when a static HTML file is served, I get a io.ktor.server.http.content.PreCompressedResponse
(I don't have compression configured on this server). Is there a way to get the actual body?Marc Plano-Lesay
08/31/2022, 11:28 AMrouting {
static("/") {
staticRootFolder = dataDir
files(".")
default("index.html")
}
}
Ktor serves the top-level index.html
, but when requesting a subdirectory, Ktor returns a 404 (but requesting explicitly index.html
in this subdirectory works fine). I also tried default(File(dataDir, "index.html"))
, assuming it would at least serve the top-level index.html
, which isn't the case.
Is there any way to serve those index files in subdirectories?包子such fun
08/31/2022, 12:10 PMddimitrov
08/31/2022, 2:22 PMFrantišek Jeřábek
08/31/2022, 5:44 PMUncaught Kotlin exception: kotlin.native.IncorrectDereferenceException: Trying to access top level value not marked as @ThreadLocal or @SharedImmutable from non-main thread
The code looks like this
import io.ktor.client.*
import io.ktor.client.engine.cio.*
fun main() {
val client = HttpClient(CIO)
}
This is just a simple new instance. I think it should work but it does not 😐. Just in case it is important i am on linuxX64
with dependencies
implementation("io.ktor:ktor-client-core:2.1.0")
implementation("io.ktor:ktor-client-cio:2.1.0")
Trevor Stone
09/01/2022, 3:37 AMclose
on the websocket would cancel the coroutine scope and clean up children jobs. This doesn't seem to be the case, which I can work around, but I was wondering if this is the behavior for a specific reason?Jakub Gwóźdź
09/01/2022, 8:33 AMeirikb
09/01/2022, 12:34 PMTransfer-Encoding: chunked
. Are there any ways to prevent this? The server we communicate with doesn't support itNeil
09/01/2022, 6:49 PMMarc Plano-Lesay
09/02/2022, 9:53 AMinstall(CORS) {
anyHost()
}
A GET
request works just fine, but a POST
doesn't. Trying to be a bit more explicit with this:
install(CORS) {
anyHost()
allowHeader(HttpHeaders.ContentType)
allowMethod(HttpMethod.Get)
allowMethod(<http://HttpMethod.Post|HttpMethod.Post>)
}
results in the GET
not working either now. What's the minimum to get both GET
and POST
working from any host?João Gabriel Zó
09/02/2022, 1:55 PMjava.lang.IllegalStateException: No request transformation found:
when running Integration Tests for my endpoint.
If I just run the application it works fine, no exceptions or whatsoever.
Any ideas?Andrey Tabakov
09/02/2022, 5:38 PMLars Erik Rojeras
09/03/2022, 7:38 AM2022-09-02 14:38:46.137 [eventLoopGroupProxy-4-1] ERROR Application - Unhandled: GET - /tak/6/producers
kotlinx.serialization.SerializationException: Serializer for class 'FreeMarkerContent' is not found.
Mark the class as @Serializable or provide the serializer explicitly.
How can I solve that so that my server both can support Freemarker pages and JSON responses?Slackbot
09/03/2022, 5:39 PMSlackbot
09/03/2022, 5:39 PMSlackbot
09/03/2022, 5:39 PMJackson Cleary
09/04/2022, 2:59 AMsuspend fun getUpcomingLaunches(): List<Launch> =
client.get {
url {
protocol = URLProtocol.HTTPS
host = "<http://api.spacexdata.com/v4|api.spacexdata.com/v4>"
encodedPath = "launches/upcoming"
}
}.body()
This works fine on Android, however on iOS it is failing with 404 not found. From the logs it looks like the correct url is being built (https://api.spacexdata.com/v4/launches/upcoming) although obviously it is not calling that url exactly. However, f I change the code though to
suspend fun getUpcomingLaunches(): List<Launch> =
client.get("<https://api.spacexdata.com/v4/launches/upcoming>").body()
it works as expected.
I’m guessing it is a bug in Darwin engine, but just wanted to check I’m not doing something stupid or if it’s a known issue. TIA!mbonnin
09/04/2022, 10:13 PMIvan Đorđević
09/05/2022, 12:25 PMAugust Lilleaas
09/05/2022, 8:32 PMrespondHtml(status) { with(template) { apply() } }
is used as just doing template.apply()
triggers the built in scope function apply
. What is it about the use of with
that makes Kotlin invoke the apply
method on HTML<T>
rather than the scope function? Is it something about member functions taking presedence in the parser/compiler when it’s called without an explicit receiver, or something like that? If I try and change it to with(resp.body) { this.apply() }
, i.e. explicitly using this
inside with
, it tries to call the scope function again.martmists
09/06/2022, 8:54 AMmartmists
09/06/2022, 8:54 AMAugust Lilleaas
09/06/2022, 9:13 AMstatic
route, and include the file in your HTML served from KtorAleksei Tirman [JB]
09/06/2022, 9:29 AMmartmists
09/06/2022, 9:57 AMAugust Lilleaas
09/06/2022, 9:57 AMmartmists
09/06/2022, 9:58 AMAugust Lilleaas
09/06/2022, 9:58 AMstatic
route to make the file available to be loaded from a <script> tagmartmists
09/06/2022, 10:00 AMAugust Lilleaas
09/06/2022, 10:00 AMmartmists
09/06/2022, 10:05 AMI suppose singlePageApplication also sets up a catch-all route that is served for all URLs etc, so maybe it’s a good idea to use it. And then also add a static route to serve the jsHmm, that's not really desired, as different pages have different permissions and contents, so I'll just look into the vue stuff instead, though it seems to only generate a single file from what I can tell rather than one for each vue file.
August Lilleaas
09/06/2022, 10:10 AMAleksei Tirman [JB]
09/06/2022, 10:35 AMAugust Lilleaas
09/06/2022, 11:06 AMmartmists
09/06/2022, 8:36 PMso it’s not really a single page app, then?The main problem is that all our backend devs want to work with kotlin/ktor and implement the frontend with pebble templates, but the frontend devs want to work with vue. I assumed a single-page-application was just a vue rendered page, is it not? I also haven't seen of a way to pass data to the vue templates for rendering, so that's something to look into as well.
napperley
09/06/2022, 11:31 PMmartmists
09/07/2022, 12:02 AMAugust Lilleaas
09/07/2022, 6:57 AMmartmists
09/14/2022, 2:51 PMnapperley
09/15/2022, 1:26 AMmartmists
09/15/2022, 11:59 AMnapperley
09/15/2022, 11:52 PMAugust Lilleaas
09/16/2022, 7:25 AM