Hi, I’ve noticed that Ktor WebSocket client sets a...
# ktor
n
Hi, I’ve noticed that Ktor WebSocket client sets a
SecWebSocketExtensions
header (i.e
Sec-WebSocket-Extensions
) when using
io.ktor:ktor-client-okhttp:2.1.2
(even though I didn’t specify any extension in the configuration (see configuration below) this Header should be optional according to the spec. this is causing an issue for my client since the value set is
permessage-deflate
which causes the server to compress the frames. Is there a configuration to disable this behaviour or is it a bug (I’ve noticed a user reported similar issue with CIO) Note: you can easily reproduce it using the official
:tutorial-websockets-client
(just switch the client to OkHttp instead of CIO) My client conf:
Copy code
client.webSocket(       method = HttpMethod.Get,
                        host = address,
                        port = port,
                        path = path,
                        request = {
                            header(HttpHeaders.SecWebSocketProtocol, supportedProtocols)
                        }
                    )
WireShark Request and Response
Copy code
Transmission Control Protocol, Src Port: 53272, Dst Port: 9090, Seq: 1, Ack: 1, Len: 1385
Hypertext Transfer Protocol
     [truncated]GET /api/****
    Sec-WebSocket-Protocol: ***\r\n
    Accept-Charset: UTF-8\r\n
    Accept: */*\r\n
    User-Agent: Ktor client\r\n
    Upgrade: websocket\r\n
    Connection: Upgrade\r\n
    Sec-WebSocket-Key: ***\r\n
    Sec-WebSocket-Version: 13\r\n
    Sec-WebSocket-Extensions: permessage-deflate\r\n.  <------------------------ This header is set by Ktor automatically 
    Host: localhost:9090\r\n
    Accept-Encoding: gzip\r\n

Transmission Control Protocol, Src Port: 9090, Dst Port: 53272, Seq: 1, Ack: 1386, Len: 487
Hypertext Transfer Protocol
    HTTP/1.1 101 Switching Protocols\r\n
    Cache-Control: no-cache, no-store, must-revalidate\r\n
    Connection: Upgrade\r\n
    Sec-Websocket-Accept: ***\r\n
    Sec-Websocket-Extensions: permessage-deflate; client_no_context_takeover; server_no_context_takeover\r\n
    Sec-Websocket-Protocol: ***\r\n
    Strict-Transport-Security: max-age=31536000; includeSubdomains;\r\n
    Upgrade: websocket\r\n
    Vary: Origin\r\n
    X-Appservices-Request-Id: 64f2ad66ff71568d3176fce6\r\n
Using
a
Unfortunately, it's not possible to remove the default WebSockets extensions. Can you file an issue?
n
Sure, here’s the issue https://youtrack.jetbrains.com/issue/KTOR-6266/Remove-the-default-WebSocket-extension-header-Sec-WebSocket-Extensions-when-using-OkHttp-engine 👍 Also is it possible to access the response header from the handshake? I’m sending a
Sec-WebSocket-Protocol
header with supported clients protocol and I need obviously to read back the
Sec-WebSocket-Protocol
sent back from the server to know which protocol it selected.
👍 1