0

I am trying to open a WebSocket (WSS) connection using the Ktor Client (v2.3.0), somewhat like this:

suspend fun main() {
    val client = HttpClient() {
        install(ContentNegotiation) {
            json()
        }
        install(WebSockets) {
            pingInterval = 300_000
        }
        defaultRequest {
            url(window.location.origin)
        }
    }

    client.wss(
        request = {
            url.takeFrom("wss://localhost:8000/ws/test")
            header("Authorization", "Bearer THISTOKENISINVALID00")
        },
        block = {
            close(CloseReason(CloseReason.Codes.NORMAL, ""))
        }
    )
}

However, when I observe the network in my browser, the Authorization header is missing on the corresponding request. (As such, it gets denied by my backend.)

How can I include the header properly?

Jolly
  • 199
  • 6

1 Answers1

0

Apparently this is not achievable in JavaScript, because you cannot add custom headers to websocket requests. See this SO answer.

Jolly
  • 199
  • 6