websocketshttp/httpsprotocols

WebSocket Handshake — A Small Discovery

· updated Feb 19, 2026

So, I was today year old when I found out that WebSocket connections at first are just simple HTTPS requests.

The browser sends something like this:

GET /chat HTTP/1.1
Host: example.com
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: random_base64
Sec-WebSocket-Version: 13

The client asks the server to switch protocols, like: “Hey, if you support WebSockets, do that.”

Then the server sends something like:

HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: hashed_key