marioled
08/13/2020, 1:39 PMmanlan
08/14/2020, 5:26 AMasync
?
(When I am already in the context
of the IO Dispatcher)?codec
08/14/2020, 8:09 AMDefaultWebSocketSession
objects?
For example, in my Application.Kt
class, I have:
webSocket("/update") {
connections += this
try {
while (true) {
when (val frame = incoming.receive()) {
is Frame.Text -> {
val text = frame.readText()
// Send message to all the connections, except the messenger connection.
for (conn in connections) {
if (conn != this) {
conn.outgoing.send(Frame.Text(text))
}
}
}
}
}
} catch (e: ClosedReceiveChannelException) {
<http://log.info|log.info>("connection closed. ignore.")
}
finally {
connections -= this
}
}
}
So, what I’m trying to accomplish works there, in that class, but not elsewhere in other application classes. When I just have a list of connection objects, or DefaultWebSocketSession
objects?andylamax
08/15/2020, 4:46 PMktor-client
in multiplatform
?
I am aware of the formData{}
but I can't seem to find where I can append
a file
to the builder.Nikky
08/15/2020, 10:00 PMCestLaVie
08/15/2020, 11:11 PMwilliam
08/16/2020, 5:17 PMandylamax
08/16/2020, 10:23 PMinstall(CORS) {
method(HttpMethod.Options)
method(HttpMethod.Patch)
method(HttpMethod.Delete)
headersOf(HttpHeaders.AccessControlAllowOrigin, "*")
headersOf(
HttpHeaders.AccessControlAllowMethods to listOf(
HttpMethod.Get.value,
HttpMethod.Post.value,
HttpMethod.Put.value,
HttpMethod.Patch.value,
HttpMethod.Delete.value,
HttpMethod.Head.value,
HttpMethod.Options.value
),
HttpHeaders.AccessControlAllowHeaders to listOf(
HttpHeaders.Origin, HttpHeaders.ContentType, HttpHeaders.XAuthToken
)
)
anyHost()
}
Doens't help me when I am trying to fetch to my restful api with ktor
. How do I allow Cross Origin Resource Sharing?
I still get
Access to fetch at '<http://192.168.43.218:8080/v0.1.0/auth/users/exists>' from origin '<http://localhost:8088>' 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.
I have tested by disabling the web security. It works, but I don't wanna do that.
Can someone please tell me how?
Rest Api: ktor-server
Client: ktor-client-js
Browser: Chromium,Operaandylamax
08/17/2020, 12:11 AMphldavies
08/17/2020, 12:37 PMmatej
08/17/2020, 1:02 PMDavid Glasser
08/17/2020, 9:38 PMwithContext
block and the request succeeds but the withContext never hangs. like, i have:
<http://log.info|log.info>("going to execute request $callsite")
withContext(MyContextThingy()) {
<http://log.info|log.info>("in first context")
}
<http://log.info|log.info>("back from context")
val res: HttpResponse = withContext(MyContextThingy()) {
<http://log.info|log.info>("top of context")
val response: HttpResponse = httpClient.request {
url.takeFrom(this@DruidClient.url)
method = <http://HttpMethod.Post|HttpMethod.Post>
contentType(ContentType.Application.Json)
body = req
}
<http://log.info|log.info>("after request")
response
}
<http://log.info|log.info>("after WC")
res
and it gets in and out of the first withContext fine, and logs after request
, but never after WC
. anyone seen anything odd like this?andylamax
08/17/2020, 11:05 PMKtor
for 1.4.0
isn't release yet... E.T.A?hhariri
Jabez Magomere
08/18/2020, 8:07 PMJohn O'Reilly
08/18/2020, 8:57 PMnative-mt
kotlinx coroutines (and also updated to CIO
engine as it seems is now required to use this). Following is set of dependencies I'm using (also updated in following branch - https://github.com/joreilly/BikeShare/tree/1.4). (exception in thread....)
const val kotlin = "1.4.0"
const val kotlinxCoroutines = "1.3.9-native-mt"
const val ktor = "1.4.0"
const val kotlinxSerialization = "1.0.0-RC"
edenman
08/19/2020, 12:35 AMGunslingor
08/19/2020, 1:26 AMlink("/libs/package/css/somepackage.min.css","stylesheet")
which would be referencing stuff in the resources folder, how do you do something like:
link(npm("something))
I haven't really been able to figure out this node thing.Pere Casafont
08/19/2020, 10:50 AMEric Grimsborn
08/19/2020, 11:15 AMserver
authentication
oauth
routing
I am trying to implement an OAuth code flow. When the flow fails e.g. user does not have access to the app i get a callback with an error
query parameter. When this is the case I do not wish to apply auth. I have this routing:
route("/login-callback") {
param("error"){
handle(errorHandler)
}
authenticate("my-oauth") {
handle(successHandler)
}
}
when running without authentication block it will match the errorHandler but when adding the authentication around successHandler it will run it for errorHandler as well and since the request is not authed it will redirect causing another callback etc. until I get too many redirects error.
Is there a way to not run the auth when matching param("error")
above?jean
08/19/2020, 12:21 PMFailed to find HTTP client engine implementation in the classpath: consider adding client engine dependency. See <https://ktor.io/clients/http-client/engines.html>
I notice some changes in the doc, as far as I remember, that page had a comment regarding multiplatform saying devs could just omit to specify an engine when used in mpp context. I guess it’s not the case anymore? I plan to share an api client based on ktor client to android and ios, should I change to something like that :
class ApiClient(
private val engine: HttpClientEngine
) {
private val client = HttpClient(engine)
}
then android can instantiate this by passing CIO
and iOS passing Ios
wellingtoncosta
08/19/2020, 2:03 PMKotlinxSerializer
isn’t recognized.
commonMain {
implementation("io.ktor:ktor-client-core:1.4.0")
implementation("io.ktor:ktor-client-json:1.4.0")
implementation("io.ktor:ktor-client-logging:1.4.0")
implementation("io.ktor:ktor-client-serialization:1.4.0")
}
Kepha
08/20/2020, 7:50 AMJavier
08/21/2020, 12:00 PMclient.get<MyWrapper<SomeModel>>(...)
John O'Reilly
08/21/2020, 6:18 PM1.3.8-native-mt-1.4.0-rc
of kotlinx coroutines but that's not working for me here at least.pascal_le_merrer
08/22/2020, 7:54 AMzero_coding
08/22/2020, 9:54 AMmax.cruz
08/23/2020, 6:48 AMktor-client-core-native
is not available yet. Is there an alternative repository?Marcin Bak
08/24/2020, 12:29 AMjava.io.EOFException
at okio.RealBufferedSource.require(RealBufferedSource.kt:201)
at okio.RealBufferedSource.readByte(RealBufferedSource.kt:210)
at okhttp3.internal.ws.WebSocketReader.readHeader(WebSocketReader.kt:119)
at okhttp3.internal.ws.WebSocketReader.processNextFrame(WebSocketReader.kt:102)
at okhttp3.internal.ws.RealWebSocket.loopReader(RealWebSocket.kt:293)
at okhttp3.internal.ws.RealWebSocket$connect$1.onResponse(RealWebSocket.kt:195)
at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:504)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
my setup is simple
val commonMain by getting {
dependencies {
implementation(kotlin("stdlib-common"))
implementation(project(":backend-frontend-shared"))
implementation("io.ktor:ktor-client-core:$ktor_version")
implementation("io.ktor:ktor-client-websockets:$ktor_version")
implementation("io.ktor:ktor-client-serialization:$ktor_version")
implementation("io.ktor:ktor-client-logging:$ktor_version")
}
}
val androidMain by getting {
dependencies {
implementation(kotlin("stdlib"))
implementation("io.ktor:ktor-client-websockets-jvm:$ktor_version")
implementation("io.ktor:ktor-client-serialization-jvm:$ktor_version")
implementation("io.ktor:ktor-client-okhttp:$ktor_version")
implementation("io.ktor:ktor-client-logging-jvm:$ktor_version")
}
}
and I read from websocket like this:
HttpClient {
install(WebSockets)
}.ws(
method = HttpMethod.Get,
host = "192.168.0.38",
port = 8080,
path = CHAT_WS_PATH
) {
try {
val frame = incoming.receive()
} catch (e: Exception) {
//" Here's the crash
}
}
hikkidev
08/24/2020, 8:40 AMHttpCallValidator
in v1.4.0 ? DoubleReceiveException
val client = HttpClient(OkHttp) {
expectSuccess = false
install(HttpCallValidator) {
validateResponse { response -> throw RuntimeException("Response not valid") }
}
}
@Throws(RuntimeException::class)
suspend fun myBestRequest(): MyResponseObj = client.get {...}
Why can't I catch the error? In version 1.3.2 this worked.
try {
val response = myBestRequest()
Result.success(response)
} catch (cause: Throwable) {
Result.failure(cause)
}