Is there any clever way to set protocol (AKA `Sec-...
# kotlinx-rpc
n
Is there any clever way to set protocol (AKA
Sec-WebSocket-Protocol
) on krpc server side? The default option does not leave opportunity to do that: https://github.com/Kotlin/kotlinx-rpc/blob/main/krpc/krpc-ktor/krpc-ktor-server/src/commonMain/kotlin/kotlinx/rpc/krpc/ktor/server/KtorServerDsl.kt#L45
a
Not sure, what do you want to do?
n
Workaround browser limitations to authenticate an RPC connection, a preferred solution that involves smuggling the token via
Sec-WebSocket-Protocol
. The problem is, without subprotocol support, the browser will drop the WS connection if the backend does not respond with the expected subprotocol.
a
Does Ktor support these subprotocols? If yes, how would you write it?
n
I never tried that and I am not sure if it works as I expected, just looked at the code, there is a parameter of `protocol`: https://github.com/ktorio/ktor/blob/main/ktor-server/ktor-server-plugins/ktor-server-websockets/common/src/io/ktor/server/websocket/Routing.kt#L164
Currently, I can only write headers and read headers, but if I provide any content, the browser immediately cancels the connection, and I assume this is due to a protocol mismatch (I read about it somewhere). So my assumption is, the server responds with the exact protocol and the browsers match it.