Dragos Rachieru
01/07/2021, 11:36 AMigor.wojda
01/07/2021, 12:47 PMdevelopment = true
in the application.conf
file and I can see stack-traces in the console. Now I wonder is there any way to print into console all requests and responses (including returned data like JSON and http codes) ?Arkangel
01/07/2021, 3:17 PMMrPowerGamerBR
01/09/2021, 10:32 PM/test/{param}
works, stuff like that, here: https://web.archive.org/web/20200611221212/https://ktor.io/servers/features/routing.html)
2. The AutoHeadResponse docs requires a dependecy that doesn't exist, but AutoHeadResponse is automatically included in Ktor!
I would've reported this in the correct location, but I can't find the repository that has Ktor's docs! (Only the API stuff seems to be in a repository, not the docs themselves)
Thank you 🙂igor.wojda
01/11/2021, 10:23 AMDariusz Kuc
01/12/2021, 8:35 PMIfvwm
01/14/2021, 5:52 AMval client = HttpClient(CIO) {
followRedirects = false
}
val _result = client.get<HttpResponse>(addr)
val readInputStream = client.get<InputStream>(_result.headers["LOCATION"]?:"")
// val count = client.get<HttpResponse>(_result.headers["LOCATION"]?:"")
the comment line would take 20 secondsIfvwm
01/14/2021, 6:07 AMhttpClient.put<ByteArray>(realUrl){
body = "aha".toByteArray()
}
this code can upload data to a link, now I need to get upload progress, how to use a outputStream to instead of this way to upload data?
val _outputStream = httpClient.put<HttpResponse>(realUrl)
val outputStream = _outputStream.receive<OutputStream>()
outputStream.write("abc".toByteArray())
outputStream.flush()
outputStream.close()
this won't work, error message o.ktor.client.call.NoTransformationFoundException: No transformation found: class io.ktor.utils.io.ByteBufferChannel (Kotlin reflection is not available) -> class java.io.OutputStream (Kotlin reflection is not available)Alexandre Brown
01/15/2021, 5:28 AMIfvwm
01/15/2021, 9:10 AMval outputStream = httpClient.put<ByteWriteChannel>(realUrl).toOutputStream()
outputStream.write("abc".toByteArray())
outputStream.flush()
outputStream.close()
why this won't put data to that link? but with httpurlconnection is okmalinskiy
01/15/2021, 10:42 AMoverride suspend fun <T> openConnection(socketAddress: InetSocketAddress, block: suspend (Socket) -> T): T {
val socketJob = Job()
var selectorManager: SelectorManager? = null
var socket: Socket? = null
try {
selectorManager = ActorSelectorManager(socketJob + coroutineContext)
socket = aSocket(selectorManager)
.tcp()
.connect(socketAddress) {
socketTimeout = 10_000
}
return block(socket)
} finally {
withContext(NonCancellable) {
selectorManager?.close()
socket?.close()
socketJob?.complete()
}
}
}
The channels opened in block() are closed in all cases.
What I’m observing (attached the screenshots) is that shutdownOutput() is sent, so the client socket gets into the FIN_WAIT_1, but there is no way for me AFAIK to wait for the whole 4-way TCP close to properly finish, so I end up with server socket that is still open and doesn’t know the client is dead. Sometimes the server sockets ends up in the CLOSE_WAIT as well.
I’ve checked the timeout tests in https://github.com/ktorio/ktor/blob/master/ktor-client/ktor-client-java/jvm/test/io/ktor/client/engine/java/RequestTests.kt#L52 and if you place a breakpoint after runBlocking
, I’m seeing the same socket behaviour.
Is it something that I’m missing or there is a problem in ktor? 🙂 thanksHelio
01/15/2021, 11:06 PMcrummy
01/16/2021, 9:40 PMDamien
01/17/2021, 8:07 PMsealed class A ()
data class B(val name) : A()
data class C(val name): A()
My endpoint returns a List<A> and according to https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/polymorphism.md#sealed-classes I would expect the following format:
[
{
"type": "com.A",
"name": "name"
}
]
And I am getting this format when Log the response object. Unfortunately, I got another response format when calling the endpoint:
[
[
"com.A",
{
"name": "name"
}
]
]
Any ideas why this different format appears when responding with call.respond(object)?spierce7
01/18/2021, 9:32 PMJose A.
01/19/2021, 10:12 AMCaused by: kotlinx.serialization.SerializationException: Class 'ArrayList' is not registered for polymorphic serialization in the scope of 'Collection'.
Partial stacktrace:
kotlinx.serialization.SerializationException: Class 'ArrayList' is not registered for polymorphic serialization in the scope of 'Collection'.
Mark the base class as 'sealed' or register the serializer explicitly.
at kotlinx.serialization.internal.AbstractPolymorphicSerializerKt.throwSubtypeNotRegistered(AbstractPolymorphicSerializer.kt:103)
at kotlinx.serialization.internal.AbstractPolymorphicSerializerKt.throwSubtypeNotRegistered(AbstractPolymorphicSerializer.kt:113)
at kotlinx.serialization.PolymorphicSerializerKt.findPolymorphicSerializer(PolymorphicSerializer.kt:96)
at kotlinx.serialization.internal.AbstractPolymorphicSerializer.serialize(AbstractPolymorphicSerializer.kt:32)
at kotlinx.serialization.json.internal.StreamingJsonEncoder.encodeSerializableValue(StreamingJsonEncoder.kt:223)
at kotlinx.serialization.json.Json.encodeToString(Json.kt:73)
at io.ktor.serialization.SerializationConverter.convertForSend(SerializationConverter.kt:118)
at io.ktor.features.ContentNegotiation$Feature$install$2.invokeSuspend(ContentNegotiation.kt:146)
at io.ktor.features.ContentNegotiation$Feature$install$2.invoke(ContentNegotiation.kt)
andylamax
01/19/2021, 11:07 AMinstall(CORS) {
method(HttpMethod.Options)
method(HttpMethod.Patch)
method(HttpMethod.Delete)
header(HttpHeaders.XForwardedProto)
anyHost()
header(AccessControlAllowOrigin)
header(AccessControlAllowMethods)
header(AccessControlAllowCredentials)
header(AccessControlAllowHeaders)
header(AccessControlRequestMethod)
header(AccessControlRequestHeaders)
header(AccessControlExposeHeaders)
header(AccessControlMaxAge)
allowCredentials = true
maxAgeInSeconds = 1000
allowNonSimpleContentTypes = true
}
But I still get this, when I run on the browser. What am I doing wrong? All I need is this request to work
Access to fetch at '<http://192.168.43.218:9010/v1/authorization/user-roles/all>' from origin '<http://localhost:8080>' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
Currently on: ktor 1.4.3
Kotlin: 1.4.21tylerwilson
01/19/2021, 4:07 PMspierce7
01/19/2021, 10:32 PMthan_
01/20/2021, 11:26 AMcall.respond
is called? Lets say I want to log something on calls with specific status codes.Júlio Santos
01/20/2021, 12:25 PMServer-Sent Events
with Ktor
, does anyone have an example? Because I didn't find anything enlightening.
I can send the event, but I can't consume it.Kuba Petržílka
01/20/2021, 2:50 PMspand
01/22/2021, 11:23 AMSebastian Kaspari
01/22/2021, 6:39 PMHttpClientEngine
, is there any way I can run the ktor test suite on them? Those tests do not happen to get published to maven, or? There’s ktor-client-tests*
but it doesn’t contain the actual test cases, right?Sam
01/22/2021, 10:08 PMrsktash
01/23/2021, 8:33 AMPoohrang
01/23/2021, 5:12 PMJoost Klitsie
01/24/2021, 9:43 AMSatyam Agarwal
01/24/2021, 7:30 PMECDHE-RSA-AES256-GCM-SHA384
as cipher suite. But I get http handshake failure, if I use Apache as engine it works. I thought this was fixed here : https://github.com/ktorio/ktor/issues/439
Can someone help me please ?spierce7
01/25/2021, 3:21 AMspierce7
01/25/2021, 3:21 AMsuspend fun downloadVideo(
httpClient: HttpClient,
url: String,
to: File,
): Flow<Float> = flow {
emit(0f)
val response = httpClient.get<HttpStatement>(url).execute()
val fileWriter = to.outputStream()
val bytes = response.receive<ByteReadChannel>()
try {
val byteBufferSize = 1024 * 100
val byteBuffer = ByteArray(byteBufferSize)
val contentLength = response.contentLength()
var totalRead = 0
do {
val currentRead = bytes.readAvailable(byteBuffer, 0, byteBufferSize)
if (currentRead > 0) {
totalRead += currentRead
if (contentLength != null) {
val progressPercent = totalRead / contentLength.toFloat()
val floorProgressPercent = (progressPercent * 100).toInt() / 100f
emit(floorProgressPercent)
}
fileWriter.write(byteBuffer, 0, currentRead)
}
} while (currentRead >= 0)
} finally {
fileWriter.flush()
fileWriter.close()
}
emit(100f)
}.flowOn(<http://Dispatchers.IO|Dispatchers.IO>)
cy
01/25/2021, 8:01 AMspierce7
01/25/2021, 3:14 PM