diff --git a/vlib/x/websocket/handshake.v b/vlib/x/websocket/handshake.v index 6fbe1373d1..55468829ee 100644 --- a/vlib/x/websocket/handshake.v +++ b/vlib/x/websocket/handshake.v @@ -22,7 +22,12 @@ fn (mut ws Client) handshake() ? { sb.write_string('\r\nUpgrade: websocket\r\nConnection: Upgrade\r\n') sb.write_string('Sec-WebSocket-Key: ') sb.write_string(seckey) - sb.write_string('\r\nSec-WebSocket-Version: 13\r\n\r\n') + sb.write_string('\r\nSec-WebSocket-Version: 13') + for key in ws.header.keys() { + val := ws.header.values_str(key).join(',') + sb.write_string('\r\n$key:$val') + } + sb.write_string('\r\n\r\n') handshake := sb.str() defer { unsafe { handshake.free() } diff --git a/vlib/x/websocket/websocket_client.v b/vlib/x/websocket/websocket_client.v index b468fcc8d9..d0212cd53e 100644 --- a/vlib/x/websocket/websocket_client.v +++ b/vlib/x/websocket/websocket_client.v @@ -4,6 +4,7 @@ module websocket import net +import net.http import x.openssl import net.urllib import time @@ -30,6 +31,7 @@ pub: uri Uri // uri of current connection id string // unique id of client pub mut: + header http.Header // headers that will be passed when connecting conn &net.TcpConn // underlying TCP socket connection nonce_size int = 16 // size of nounce used for masking panic_on_callback bool // set to true of callbacks can panic @@ -85,6 +87,7 @@ pub fn new_client(address string) ?&Client { uri: uri state: .closed id: rand.uuid_v4() + header: http.new_header() } } @@ -486,5 +489,6 @@ pub fn (c &Client) free() { c.error_callbacks.free() c.open_callbacks.free() c.close_callbacks.free() + c.header.free() } }