Satyam Agarwal
11/13/2022, 1:10 PMon(CallSetup)
) I have three different plugins registered. What is the execution strategy ?Antonio Acuña Prieto
11/15/2022, 8:27 PMStylianos Gakis
11/15/2022, 10:10 PMLuiz Aguiar
11/16/2022, 10:55 PMinstall
statement?
@Test
fun testOptimizeRouter() = testApplication {
val client = createClient {
install(ContentNegotiation) {
json()
}
}
// omitted
}
Ktor 2.1.3
Kotlin 1.7.21
IDEA CE 2022.3 Beta (EAP)Bruno Ranschaert
11/18/2022, 12:14 PMscope.requestPipeline.intercept(HttpRequestPipeline.State) {
// inject auth header here - works fine
val clientCall = proceedWith(subject)
// Remove session cookie here - don't know how to do this
}
Piotr Krzemiński
11/18/2022, 12:47 PMbuild/distributions
, and another module with a working ktor server. What’s the idiomatic way to declare a dependency on the web UI project form the ktor project, copy over the bundle to the ktor module and serve it from ktor? My ultimate goal is being able to create a Docker image with the server hosting the web UI, so I presume the bundle should land somewhere in JVM resources
IsaacMart
11/21/2022, 8:57 AMFunkyMuse
11/21/2022, 10:23 PMRichard Schielek
11/22/2022, 1:06 PMval response = request.response()
val channel = response.toSendChannel(vertx)
response.headers().set("Transfer-Encoding", "chunked")
for (i in 1..10) {
delay(200)
channel.send(Buffer.buffer("""{"id": $i}"""))
channel.send(Buffer.buffer("\n"))
}
response.end().await()
Alberto Quario
11/22/2022, 2:29 PMshould("respond OK") {
testApplication {
application {
mockService("11111111111")
configureServing()
configureRouting()
}
client.get("/v1/foo/XXX00000000123").apply {
assertEquals(HttpStatusCode.OK, status)
}
}
}
should("respond to Unauthorized") {
testApplication {
application {
mockService("12345678")
configureServing()
configureRouting()
}
client.get("/v1/foo/XXX00000000123").apply {
assertEquals(HttpStatusCode.Unauthorized, status)
}
}
}
and the mockService mock a static builder using mockk
private fun mockService(id: String?) {
mockkObject(ReferenceClientBuilder)
val fakeService = mockk<ReferenceClient>()
coEvery { fakeService.customerId(any()) } returns id
...
coEvery { ReferenceClientBuilder.getClient(any()) } returns fakeService
}
Up to ktor 2.1.2 everything was ok, but now with 2.1.3 the second test fails cause the static mockk is just set on the first test and not updated on following ones.
Any hints? Thanks!dodalovic
11/23/2022, 8:54 PMhttpClient.get("/whatever") {
attributes.put("operation", "whatever")
}
and then in my validator:
val client = HttpClient(CIO) {
install(ContentNegotiation) { json() }
HttpResponseValidator {
validateResponse { response ->
if response.request.attributes["operation"] == "whatever"
//whatever
}
}
}
is this possible at allMarkRS
11/24/2022, 11:00 AMhhariri
James Chen
11/25/2022, 6:39 PMexternalServices
. This is the mock I have right now in my `testApplication`:
externalServices {
hosts("<ws://test.com>") {
install(io.ktor.server.websocket.WebSockets) {}
routing {
webSocket("/") {
this.send("hello")
}
}
}
}
My test will hang when it tries to connect to <ws://test.com>
and eventually return a io.ktor.client.network.sockets.ConnectTimeoutException: Connect timeout has expired [url=<ws://test.com>, connect_timeout=unknown ms]
error. Can externalServices
mock out ws servers? If not, are there any suggestions on how to mock a ws server for testing? Thank you!dino9
11/25/2022, 7:21 PM{
"base": "xyz",
"rates": {
"AED": 3.67295,
"AFN": 87.499995
}
}
@Serializable
class Obj(val base: String, val rates : Map<String?,Double>?)
I use kotlin serialization but observed following error
io.ktor.client.call.NoTransformationFoundException: No transformation found: class io.ktor.utils.io.ByteBufferChannel (Kotlin reflection is not available) -> class dev.packge (Kotlin reflection is not available)
James Chen
11/26/2022, 6:18 AMHttpClient
from an ApplicationTestBuilder()
in a test, or create an HttpClient
mockk, and inject that into my code path that uses a normal HttpClient
(e.g. HttpClient(CIO)
) during a testApplication
run. Odd side effects include authentication principals becoming null, and testcontainers not being recognized. For context I'm trying to do this to mock out some behaviors for testing. Does anyone know why this is?dave08
11/27/2022, 12:51 PMJsonContentNegotiationTest
for it, it fails testBadlyFormattedJson, that it expects a BAD REQUEST... what am I doing wrong? (code in the thread)Richard Schielek
11/27/2022, 5:29 PMfun Application.configureRouting() {
routing {
get("/") {
error("Something went wrong")
}
}
}
But when using this in a test, the test application will not return a 500 but throw the exception instead
class ApplicationTest {
@Test
fun testRoot() = testApplication {
application {
configureRouting()
}
val response = client.get("/") // java.lang.IllegalStateException: Something went wrong
assertEquals(HttpStatusCode.InternalServerError, response.status)
}
}
How do I test this behavior when I rely on the default implementation of ktor?FunkyMuse
11/27/2022, 11:21 PMdave08
11/28/2022, 2:09 PM'fun <P : Pipeline<*, ApplicationCall>, B : Any, F : Any> install(plugin: Plugin<Application, AuthenticationConfig, Authentication>, configure: AuthenticationConfig.() -> Unit = ...): Unit' can't be called in this context by implicit receiver. Use the explicit one if necessary
?dave08
11/28/2022, 2:11 PMthis@testApplication.install(...)
🙈...dave08
11/28/2022, 2:20 PMThe test application has already been built. Make sure you configure the application before accessing the client for the first time.
🤕... I wish Ktor would just let me create my own testApplication
without trying to magically find an existing one...spierce7
11/28/2022, 3:42 PMTrey
11/28/2022, 7:54 PMChris Ryder
11/29/2022, 5:27 PMColin L
11/30/2022, 4:52 AMJoão Gabriel Zó
11/30/2022, 12:16 PMCorrect the classpath of your application so that it contains compatible versions of the classes io.ktor.client.utils.CoroutineDispatcherUtilsKt and kotlinx.coroutines.CoroutineDispatcher
which versions would be compatible in this case?Alex Styl
12/01/2022, 7:12 AM// 1
call.receiveMultipart().forEachPart { part ->
// 2
when (part) {
is PartData.FileItem -> {
val input = part.provider()
// Read from input by chunks
}
else -> {}
}
}
I would like to listen to the progress between (1) and (2). Right now (1) is called, then the file is fully uploaded to the server, and then (2) is called.Cherrio LLC
12/03/2022, 12:16 PMSendCountException
. Code in 🧵zt
12/06/2022, 1:52 AM