Aaron Rice
03/14/2022, 9:33 PMContentNegotiation
. In my dependencies
, I have:
implementation("io.ktor:ktor-server-content-negotiation:$ktor_version")
implementation("io.ktor:ktor-serialization-kotlinx-json:$ktor_version")
where ktor_version=2.0.0-beta-1
. Is there something else I'm missing?Karen Frangulyan
03/15/2022, 11:25 AMWWW-Authenticate
header set, as a result the refreshToken
is not being triggered. I tried to solve this by intercepting the responses and adding that header manually on mobile client, however, token refresh is still not triggered and I don't see that header in http response logs, even though the interceptor code is being executed. Below is the simplified version of my client setup:
install(Logging)
install("Fix Unauthorized headers") {
receivePipeline.intercept(HttpReceivePipeline.Before) { response ->
println("----------- INTERCEPTING!") // this is printed
proceedWith(UnauthorizedResponseWrapper(response))
}
}
install(Auth) {
bearer {
loadTokens {
println("---------- LOADING TOKENS!") // this is printed
...
}
refreshTokens {
println("---------- REFRESHING TOKENS!") // this is NOT printed
...
}
}
}
and the UnauthorizedResponseWrapper
is pretty simple - just adds the header if needed:
private class UnauthorizedResponseWrapper(response: HttpResponse): HttpResponse() {
override val call: HttpClientCall = response.call
override val content: ByteReadChannel = response.content
override val coroutineContext: CoroutineContext = response.coroutineContext
override val headers: Headers = buildHeaders {
appendAll(response.headers)
if (response.status == HttpStatusCode.Unauthorized && !response.headers.contains(HttpHeaders.WWWAuthenticate)) {
println("--------- APPENDING WWWAuth header!") // this is printed!
append(HttpHeaders.WWWAuthenticate, AuthScheme.Bearer)
}
}
override val requestTime: GMTDate = response.requestTime
override val responseTime: GMTDate = response.responseTime
override val status: HttpStatusCode = response.status
override val version: HttpProtocolVersion = response.version
}
As I said - I'm completely new to ktor, am I missing something here or maybe the header should be different to pass through Auth checks?Rustam Siniukov
03/16/2022, 2:55 PMPHondogo
03/17/2022, 8:16 PMConstantin Cezar Begu
03/20/2022, 5:25 AMsimon.vergauwen
03/21/2022, 3:13 PMCoroutineScope
is a SupervisorJob
.
And a async
without an await
is now crashing the server due to a child CoroutineScope
of the Application SupervisorJob
🤔 Adding await
in notFine
also doesn't change the behavior.
It's hard to find more documentation around this, I looked around the codebase but had a hard time locating where execute
is being called. Probably somewhere in the integration code with Netty, or other runtimes.Alexander Weickmann
03/22/2022, 8:35 AMrudolf.hladik
03/22/2022, 2:19 PMimplementation("ch.qos.logback:logback-classic:$logback_version")
from Ktor 2.0 embededServer ? it uses reflection and thats bad for GraalVM native-image
Andrew Reed
03/22/2022, 4:45 PMLucas León
03/22/2022, 4:56 PMMark Schisler
03/22/2022, 5:45 PM<domain-config>
network config on Android? The work around appears to be to drop down to fully enabling all clear text comms (which seems wild). To fix this bug, all that appears to be missing is an update to this function call to add in the hostname of the request. Is there a time table for release? This issue has existed since 1.5 and still isn’t fixed in the mainline branch. See the attached JIRA issue.
https://github.com/ktorio/ktor/blob/1d56e5505135022f72ff666e08f5d83a03413b04/ktor-[…]r-network-tls/jvm/src/io/ktor/network/tls/TLSClientHandshake.kt
https://youtrack.jetbrains.com/issue/KTOR-2243jmfayard
03/23/2022, 11:38 AMByteZ
03/23/2022, 3:31 PMktor-client-core
and ktor-client-cio
to my pom.xml dependencies but can't access any classes even though I can see them under external libraries. I already tried invalidating my intellij caches and deleting both dependencies from my local repo. Is there something I missed or is this an intellij bug?Vivek Modi
03/23/2022, 5:41 PMOKHTTP
client with some`interceptors` and authenticator
and iOS application using alamofire
with interceptors
.Both projects are huge in size. Now I want to use KMM for new api client. So How can I use these 2 http client through Ktor. I don't want to write from scratch in KMM module. Any suggestion?Joey
03/25/2022, 2:12 PMdodalovic
03/25/2022, 2:31 PMdodalovic
03/25/2022, 2:36 PMGraalVM 22.0.0.2 Java 11 CE
John O'Reilly
03/25/2022, 2:39 PMd.medina
03/25/2022, 3:31 PMJoey
03/25/2022, 3:34 PMTobias Gronbach
03/26/2022, 10:13 AMGrouvie
03/27/2022, 1:46 PMNathan Kleinschmidt
03/27/2022, 3:05 PMimplementation(files(./dependency))
. My question is which path exactly do I need to reference?S.
03/27/2022, 4:14 PMtestApplication {
client.config {
install(HttpCookies)
install(ContentNegotiation) {
json()
}
}
routing {
get("/login-test") {
call.sessions.set(UserSession(id = 4))
}
}
client.get("/login-test")
val response = client.get("v1/words")
response.status shouldBe HttpStatusCode.OK
}
phldavies
03/28/2022, 10:36 AMtestApplication
block, I’m trying to test some lifecycle hooks for a custom plugin. Is there a nice way to ensure the application environment is started than making a client call? I currently have something like this:
private suspend fun ApplicationTestBuilder.ensureStarted() = client.get("/") { expectSuccess = false }
class MyTest : FunSpec({
test("plugin works correctly") {
testApplication {
install(MyCustomPlugin) { ... }
ensureStarted()
// test the plugin
}
}
})
dodalovic
03/28/2022, 12:08 PMrouting {
authenticate("auth-jwt") {
route("*") {
call.response.cookies.append(...)
}
}
addRoutes()
}
is the way to go?André Martins
03/28/2022, 5:02 PMHttpResponseValidator
feature in ktor client how can I access original request information in handleResponseException
is it possible in anyway?natario1
03/28/2022, 11:04 PMcontentType(ContentType.Image.JPEG)
setBody(byteArray)
But in 2.0, I get a 500 error. Has anything changed with respect to this?James Black
03/29/2022, 2:56 AMval response: HttpResponse = <http://client.post|client.post>(
"<https://example.com/login>"
) {
contentType(ContentType.Application.Json)
LoginModel(username, password).also { body = it }
}
l get this error on the body part: This API is internal in Ktor and should not be used. It could be removed or changed without notice.
I attached a screenshot just to make certain it is clear. Basically, how can I set the body? I also tried
body = LoginModel(...) but same error, same result.
If I add the annotation to allow an internal API it works on Android but fails to compile on iOS. I am using Kotlin Multiplatform, with Kotlin 1.6.10 and kotlinxSerialization = "1.3.2"
This is how I initialized the httpclient.
fun createHttpClient() = HttpClient {
install(ContentNegotiation) {
json(Json { isLenient = true; ignoreUnknownKeys = true; useAlternativeNames = false; prettyPrint = true }
)
}
install(Logging) {
logger = Logger.DEFAULT
level = <http://LogLevel.INFO|LogLevel.INFO>
}
}
Nikky
03/29/2022, 2:44 PMreceivePipeline.intercept(ApplicationCallPipeline.Features) {
val headers = call.requestheaders
//TODO: add header
}
but how would i copy the request or be able to get a mutable version of the headers ?Nikky
03/29/2022, 2:44 PMreceivePipeline.intercept(ApplicationCallPipeline.Features) {
val headers = call.requestheaders
//TODO: add header
}
but how would i copy the request or be able to get a mutable version of the headers ?Satyam Agarwal
03/29/2022, 2:55 PMNikky
03/29/2022, 2:57 PM