Andrey Tabakov
09/20/2022, 6:49 AMcpe
09/20/2022, 10:13 AMrouting {
get("/test") {
call.respondText("test called")
}
authenticate("auth-jwt") {
route("/featureA") {
get("/") {
val principalSubject = call.principal<JWTPrincipal>()?.subject
featureAService.handleGet(call, principalSubject)
}
post("/") {
val principalSubject = call.principal<JWTPrincipal>()?.subject
featureAService.handlePost(call, principalSubject)
}
put("/") {
val principalSubject = call.principal<JWTPrincipal>()?.subject
featureAService.handlePut(call, principalSubject)
}
}
route("/featureB") {
get("/") {
val principalSubject = call.principal<JWTPrincipal>()?.subject
featureBService.handleGet(call, principalSubject)
}
}
}
}
In this case I’d like to provide the principalSubject to each method (in reality there are a few more context parameters that are shared across those methods like parameters etc.). I don’t want to start each method with retrieving unsers and other context parameters and I also don’t want to repeat those lines in the routing
section. Is there any way to reduce the amount of code here by having some preprocessor (could then use context-receivers
)?Milton Johansson
09/20/2022, 10:54 AMayodele
09/20/2022, 7:18 PMval dnb = "<https://www.dnb.com/apps/dnb/servlets/CompanySearchServlet>"
val res = client.get(dnb) {
url {
parameters.append("pageNumber", "1")
parameters.append("pageSize", "5")
parameters.append("searchTerm", "NQB8 Limited")
parameters.append(
"token",
"eyJwNCI6IklvTEh3WVN6SkZTaDJLUG0zYU41c1NacnZLUFBNUE1MTlBSTE1RIiwicDIiOjksInAzIjozOCwicDEiOjE2NjM2MzI0NjgyMzd9"
)
}
}
println(res)
It works on postman, but it kinda freezes on Ktor with no response.Luiz Aguiar
09/20/2022, 8:20 PMIoannis Mavroukakis
09/21/2022, 2:11 PMHttpClient
re-use. What is the accepted wisdom here? Create a new one as needed, or never close()
the existing one? What do people do? Thanks!Dariusz Kuc
09/22/2022, 12:47 AMContent-Length
header (default in v1.6) vs Transfer-Encoding: chunked
(default in v2.0)?Johnny
09/22/2022, 9:09 AMHttpCacheEntry
is internal? This makes it impossible to extend the HttpCacheStorage
to be able to implement a custom caching solution, in which the entries could be persisted in a database (Android/iOS)Keith Miller
09/22/2022, 3:42 PMKristian Nedrevold
09/23/2022, 5:57 PMsuspend fun Application.runJobs(jobService: JobService) {
withContext(this.coroutineContext) {
launch {
while (true) {
delay(1000)
println("hello")
}
}
}
}
benkuly
09/24/2022, 1:00 PMczuckie
09/24/2022, 4:56 PMmarzelwidmer
09/25/2022, 8:45 AMjeggy
09/25/2022, 4:15 PMhhariri
Slackbot
09/26/2022, 2:48 PMGiuliopime
09/26/2022, 10:17 PM/**
* Represents a single list, which can contain categories to organize list items in it
*/
@Serializable
data class ListDto(
@Contextual @SerialName("_id") val id: String = ObjectId().toHexString(),
val user_id: String,
var name: String,
val categories: MutableList<CategoryDto>,
// TODO: types do be defined
var icon: String,
var color: String
)
I want the user to create a new List from the frontend so I will need to receive the list data in my ktor put route
route("/lists") {
get {
// Returns all lists
}
put {
// Need to receive the list data here but obviously it doesn't have an id yet
}
The issue is that when the user wants to create a list it will not send the list id too, 'cause that will be generated on the server after receiving the list properties like name, categories, etc...
Isn't there a way to reuse the ListDto data class but fill the id variable dynamically?Mihai Voicescu
09/27/2022, 8:02 AMCaused by: kotlinx.coroutines.channels.ClosedReceiveChannelException: Channel was closed
at kotlinx.coroutines.channels.Closed.getReceiveException(AbstractChannel.kt:1108)
at kotlinx.coroutines.channels.AbstractChannel$ReceiveElement.resumeReceiveClosed(AbstractChannel.kt:913)
at kotlinx.coroutines.channels.AbstractSendChannel.helpClose(AbstractChannel.kt:342)
at kotlinx.coroutines.channels.AbstractSendChannel.close(AbstractChannel.kt:271)
at kotlinx.coroutines.channels.SendChannel$DefaultImpls.close$default(Channel.kt:93)
at io.ktor.websocket.DefaultWebSocketSessionImpl$runIncomingProcessor$1.invokeSuspend(DefaultWebSocketSession.kt:204)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTaskKt.resume(DispatchedTask.kt:234)
at kotlinx.coroutines.DispatchedTaskKt.resumeUnconfined(DispatchedTask.kt:190)
at kotlinx.coroutines.DispatchedTaskKt.dispatch(DispatchedTask.kt:161)
at kotlinx.coroutines.CancellableContinuationImpl.dispatchResume(CancellableContinuationImpl.kt:397)
at kotlinx.coroutines.CancellableContinuationImpl.completeResume(CancellableContinuationImpl.kt:513)
at kotlinx.coroutines.channels.AbstractChannel$ReceiveHasNext.completeResumeReceive(AbstractChannel.kt:947)
at kotlinx.coroutines.channels.AbstractSendChannel.offerInternal(AbstractChannel.kt:56)
at kotlinx.coroutines.channels.AbstractSendChannel.send(AbstractChannel.kt:134)
at io.ktor.websocket.RawWebSocketJvm$1.invokeSuspend(RawWebSocketJvm.kt:68)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:42)
at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
Andrey Tabakov
09/28/2022, 11:01 AMNiko
09/29/2022, 5:18 PMkotlinx.html
DSL exceptions are swallowed and the result of a request is just *0.0.0.0* didn't send any data. ERR_EMPTY_RESPONSE
I found this issue for Ktor 1.x: https://youtrack.jetbrains.com/issue/KTOR-756 with status of being fixed in 1.5.4.
However, I'm now using Ktor JVM 2.1.1 and kotlinx-html-jvm:0.8.0
, and all exceptions inside the DSL get swallowed and the log just shows
2022-09-29 20:12:45.948 [eventLoopGroupProxy-4-3] INFO
Application - 200 OK: GET - /<path>
Debugging the exceptions, raised exception get to the catch
block in T.visitTag
in commonMain/visit.kt
in kotlinx-html-jvm
PHondogo
09/29/2022, 8:48 PMMeherdatta Chepuri
09/29/2022, 9:20 PMYuutokata
09/30/2022, 6:44 PMYuutokata
09/30/2022, 6:44 PMYuutokata
09/30/2022, 6:45 PMCLOVIS
10/02/2022, 1:20 PMtestApplication
? Or a proper way to debug the request response?Rodrigo Silva
10/02/2022, 6:34 PMdata class SomeClass (
name: String,
age: int,
document: ByteArray (is it correct?)
)
fun Route.test() {
route("/test") {
post("/doc") {
val receive = call.receive<SomeClass>()
...
João Gabriel Zó
10/03/2022, 2:44 PMjamireh
10/03/2022, 6:09 PMsendPipeline
after State
as well as intercepting HttpSend
. Both had issues that didn't meet my expectations. What I expect to happen is:
1. Developer triggers my companion plugin through a debug tool of their choice so the next API call will return an HTTP 401
2. Developer triggers another API call and within one execution context:
a. My companion plugin is triggered, rewriting the response to HTTP 401
b. The provided Auth plugin is triggered, with the refresh token logic being invoked & in Bearer token providers, the access_token
& refresh_token
are rotated
c. The provided Auth plugin retries the original API with the new access_token
and returns the responseSlackbot
10/04/2022, 1:48 AM