Hi team, are we able to change the header value at...
# ktor
i
Hi team, are we able to change the header value at runtime for WebSocket client? I tried this, but it didn't work well. Any thoughts?
Copy code
suspend fun create(
    path: String,
    isDebug: Boolean,
    session: suspend DefaultClientWebSocketSession.() -> Unit
) {
    ktorClient.config {
        defaultRequest {
            header("x-debug-request", isDebug)
        }
    }.wss(
        method = HttpMethod.Get,
        host = "...",
        path = path,
        block = session
    )
}
Updated: TIL; once the ws connection is established, we cannot change the request header. But is there any way to do so without closing and reopening the ws connection? Thanks!
c
There are no headers on Websocket connections after the connection is established. The flow for a WS connection is: • HTTP ‘upgrade’ request (this is an HTTP request, you can add headers here); • Websocket connection established; this is now whatever protocol you’ve chose to use on the WS connection (perhaps that supports the concept of “headers”?)
a
Can you explain why you need to change the header value at runtime?