johnaqel
06/30/2021, 12:34 AMJúlio Santos
06/30/2021, 12:58 PMribesg
07/01/2021, 10:21 AMdivyanshunegi
07/02/2021, 5:14 AMsuspend fun GETRequest(
baseUrl:String,
path: String,
headers: List<Headers>? = null,
model: , MODEL_CLASS_NAME
json: Json = Json {
ignoreUnknownKeys = true
}
) : MODEL_CLASS {
val builder = HttpRequestBuilder()
builder.method = HttpMethod.Get
builder.url {
takeFrom(baseUrl)
encodedPath = encodedPath.let { startingPath ->
path(path)
return@let startingPath + encodedPath.substring(1)
}
}
with(builder.headers) {
if (!headers.isNullOrEmpty()) {
headers.forEach {
append(it.key, it.value)
}
}
}
try {
val serializer = model.serializer()
//not primitive type
val result: String = httpApiClient.request(builder)
return json.decodeFromString(serializer, result)
} catch (pipeline: ReceivePipelineException) {
throw pipeline.cause
}
}
I am trying to make a generic GETrequest function which can be used from Android and iOS in Ktor native with KMM, I am not sure how can we pass the MODEL_CLASS_NAME
, any idea ?Stylianos Gakis
07/02/2021, 2:40 PM@Location("/login")
data class PostLogin(val username: String, val password: String)
But I want the username
and the password
to be part of the body of the post request instead of the Params.
Is that something that is possible, or must I do call.receive
like I would when I wasn’t using the Locations plugin?Lucas Milotich
07/02/2021, 9:19 PMpublic fun CoroutineScope.cancel(message: String, cause: Throwable? = null): Unit = cancel(CancellationException(message, cause))
But it just cancel de coroutine and i don’t know what happens with the connection, buffers, etc.
Thanks!Helio
07/03/2021, 6:54 AMembeddedServer(Netty, 8080, module = Application::module).start()
with developmentMode = false
to be able to run my application locally. Is that expected?
I couldn’t find any information in the change logs.
val builder = ApplicationEngineEnvironmentBuilder()
builder.module(Application::module)
embeddedServer(Netty, builder.build {
developmentMode = false
connector {
port = 8080
}
}).start()
The reason I had to do it, was to avoid the a similar error reported here. https://youtrack.jetbrains.com/issue/KTOR-2306divyanshunegi
07/06/2021, 10:21 AMAPIClient.GETRequest<UserData, Error>("/kmm-test", { success ->
Log.i(TAG, "Success: ${it.toString()}")
}, { error ->
Log.e(TAG, "Error: ${it.cause}")
}, { genericError ->
Log.e(TAG, "Throwable: ${it.message}")
})
it looks something like this.
I am handeling the generic error with ktor client engine.
but the error from API is still a mystery to me, can someone guide me to a good direction ?Justin Moy
07/06/2021, 7:07 PMIllegalStateException
when trying to use our ktor client to call a ktor server for our integration tests, anyone able to take a look?
This is the error message when customPost()
is called:
Failed to parse request body: request body length should be specified, chunked transfer encoding should be used or keep-alive should be disabled (connection: close)
setup:
val httpClient = HttpClient(CIO) {
expectSuccess = false
}
suspend inline fun <reified TRequestData> customPost(
url: String,
requestCacheKey: String,
requestContent: TRequestData,
headers: Map<String, String>? = null,
contentType: ContentType = ContentType.Application.Json
) {
<http://httpClient.post|httpClient.post><HttpResponse>(url) {
var contentAstString = requestCacheManager.getOrCreateRawString(requestCacheKey) { requestContent } // returns a string
headers?.forEach { headerKey, value ->
header(headerKey, value)
}
body = TextContent(contentAstString, contentType)
}
}
divyanshunegi
07/07/2021, 5:05 PM401
in that case retry the call after making a new token.
scope.requestPipeline.intercept(HttpRequestPipeline.State) {
println("MyNewPlugin : works the scope ${context.method}")
context.header(HttpHeaders.UserAgent, feature.agent)
}
scope.responsePipeline.intercept(HttpRequestPipeline.State) {
println("MyNewPlugin : works the scope ${context.response.status}")
}
I wrote this in the install
function to test the Plugin for request and response pipeline but it crashes with this error
Caused by: io.ktor.util.pipeline.InvalidPhaseException: Phase Phase('State') was not registered for this pipeline
Brendan Weinstein
07/08/2021, 6:19 PMAleksandr Ivanov
07/09/2021, 12:50 PMrefreshToken
in BearerTokens
. I don’t found an usage inside library. In my case I’m storing and refreshing tokens on application side.MBegemot
07/09/2021, 4:38 PMjava.lang.Exception:
Exception -> java.lang.IllegalStateException Expected 8 bytes in the trailer. Actual: 7 $
at io.ktor.util.EncodersJvmKt$inflate$1.invokeSuspend(EncodersJvm.kt:128)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)
I'm finding this error at random times, it happens when building up the body parameters in a POST with json. Unfortunately it only happens time to time but of course is annoying , the request is cancelled before being send to the server. (Since version 1.5.4) .darkmoon_uk
07/10/2021, 7:44 AMDavid Dupraz
07/11/2021, 12:56 PMClient request(<http://localhost:2077/login>) invalid: 400 Bad Request. Text: "Wrong password"
printed by exception.message
, is there a way to print only "Wrong password" ?Gus
07/12/2021, 2:58 PMjava.nio.file.FileSystems
, which breaks on Android 5-8 but works in newer versions. This line in `ApplicationEngineEnvironmentReloading` is the culprit, but I don't think that class should be used in production, right? So how can I disable that behaviour, so that that class won't be loaded? I'm not running the server in development mode, so it shouldn't be trying to reload the server.Joost Klitsie
07/12/2021, 8:23 PMCLOVIS
07/13/2021, 10:26 AMSet-Cookie
header in the response.
However, call.respond
doesn't take a lambda to configure the request, unlike its client-side equivalent. I found call.respondText
, which has an override with a lambda with an OutgoingContent
receiver, which has a headers
attribute, however it seems to be immutable.
How can I add a specific header for a specific request? I don't want that header to be present in other requests.tylerwilson
07/13/2021, 7:53 PMGlobalScope.launch {
launch(ApplicationDispatcher) {
client.get {
}
}
}
but when testing with a macOS SwiftUI app, I get the following:
Error: There is no event loop. Use runBlocking { ... } to start one.
but runBlocking cannot be used in the common code. Any solutions to this? Is the above ‘canonical’ way to make Ktor client calls in common code?yogurtearl
07/14/2021, 3:49 AMmaskipli
07/14/2021, 11:57 AMfailed with exception: kotlinx.coroutines.JobCancellationException: Parent job is Completed; job=JobImpl{Completed}
Marcelus Trojahn
07/14/2021, 7:27 PMJoseph Magara
07/14/2021, 8:51 PMError: Could not find or load main class io.ktor.server.netty.EngineMain
Does anyone know how to fix it?andylamax
07/15/2021, 6:53 AMktor-client-curl
library on a linuxX64 target fails to located libcurl, cannot find -lcurl
I can add a def file but that would fail in my CI encironment.
I am confident that I have installed libcurl while I installed curl but I am open to know if that's not the case
So, how does one go about having a configuration that can run locally and on CI?Slavi
07/15/2021, 12:22 PMokaymak
07/15/2021, 2:38 PM.body()
after every request.
This doesn’t look like an improvement at all.enleur
07/17/2021, 3:31 PMval id = query["id"] ?: return@post call.respondBadRequest()
2. Using exceptions and StatusPage
val id = query["id"] ?: throw BadRequestException()
saket
07/18/2021, 4:30 AMByteReadChannel
looks correct?
private fun ByteReadChannel.source(): okio.Source {
val channel = this
return object : okio.Source {
override fun read(sink: okio.Buffer, byteCount: Long): Long {
if (byteCount == 0L) return 0L
return runBlocking {
if (!channel.isClosedForRead) {
val bytes = channel.toByteArray(byteCount.toInt())
sink.write(bytes)
bytes.size.toLong()
} else {
-1. // Source is exhausted.
}
}
}
override fun close() = Unit // Couldn't find any way to close ByteReadChannel.
override fun timeout() = Timeout.NONE
}
}
neworldlt
07/18/2021, 12:23 PMMarc Knaup
07/18/2021, 5:25 PMMarc Knaup
07/18/2021, 5:25 PMBig Chungus
07/18/2021, 5:43 PM<http://localhost>:<KTOR_PORT>/<path>
?Marc Knaup
07/18/2021, 5:44 PMBig Chungus
07/18/2021, 5:44 PMMarc Knaup
07/18/2021, 6:01 PMRobert Jaros
07/18/2021, 6:01 PMMarc Knaup
07/18/2021, 6:01 PMRobert Jaros
07/18/2021, 6:12 PMMarc Knaup
07/18/2021, 6:34 PMkenkyee
07/18/2021, 7:23 PMBig Chungus
07/18/2021, 7:24 PMMarc Knaup
07/18/2021, 7:25 PMRobert Jaros
07/18/2021, 7:37 PMmicronaut-ktor
module, which embeds Ktor inside Micronaut, reusing Micronaut's native http server.
https://github.com/micronaut-projects/micronaut-kotlin/tree/master/ktor/src/main/kotlin/io/micronaut/ktorMarc Knaup
07/18/2021, 8:45 PMkenkyee
07/18/2021, 9:33 PM