You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
i use kotiln ktor websocket call etcd api watch with auth token,but response error for "cancel_reason":"rpc error: code = InvalidArgument desc = etcdserver: user name is empty"; websocket proxy was loss header for token;
code:
@OptIn(ExperimentalEncodingApi::class)
suspend fun watchWebSocket(
keyStr: String,
onUpdate: (String) -> Unit
) {
println("etcd config watch")
val token = auth()
println("etcd config watch token: $token")
val watchKey = Base64.encode(keyStr.encodeToByteArray())
httpClient.ws(method = HttpMethod.Get, host = "localhost", port = 2379, path = "/v3/watch?token=$token",request = {
// 添加认证 header
header(HttpHeaders.Authorization, "Bearer $token")
header("Authorization", token)
}){
send(Frame.Text("""{
"create_request": {
"key": "$watchKey",
"start_revision": 0,
"progress_notify": true,
"filters": []
}
}
""".trimIndent()
))
// 接收事件
try {
for (frame in incoming) {
when (frame) {
is Frame.Text -> {
val text = frame.readText()
println("etcd config watch text: $text")
onUpdate(text)
}
is Frame.Close -> throw CancellationException("WebSocket closed")
else -> { /* ignore */ }
}
}
} catch (e: Exception) {
if (e is CancellationException) throw e
throw Exception("WebSocket error", e)
}
}
}
i use three way for take token;but all loss,help me ,thanks
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
i use kotiln ktor websocket call etcd api watch with auth token,but response error for "cancel_reason":"rpc error: code = InvalidArgument desc = etcdserver: user name is empty"; websocket proxy was loss header for token;
code:
i use three way for take token;but all loss,help me ,thanks
Beta Was this translation helpful? Give feedback.
All reactions