Challenge 1: Read a Handshake — Possible Solution ==================================================================== GIVEN REQUEST (missing the Upgrade header): GET /chat HTTP/1.1 Host: example.com Connection: Upgrade Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ== Sec-WebSocket-Version: 13 WHAT THE SERVER SHOULD DO -------------------------- The server should NOT respond with "101 Switching Protocols" — it should treat this as an ordinary HTTP request and respond accordingly (most likely a 400 Bad Request, or simply route it to whatever normal HTTP handler exists for that path, since nothing in this request validly asks for a protocol upgrade). WHY THE CONNECTION FAILS TO ESTABLISH -------------------------------------- - The "Upgrade: websocket" header is the specific signal that tells the server "I want to switch this connection to the WebSocket protocol." Without it, the server has no reason to believe this is anything other than a normal HTTP request — "Connection: Upgrade" alone is meaningless without a matching "Upgrade:" header naming WHAT to upgrade to. - Both headers work together: "Connection: Upgrade" says "this request wants to change protocols," and "Upgrade: websocket" says "specifically, to WebSocket." A server correctly implementing the handshake checks for BOTH before it will respond with 101 Switching Protocols and compute a Sec-WebSocket-Accept value. - Even Sec-WebSocket-Key and Sec-WebSocket-Version being present and correct doesn't matter here — those headers are only meaningful in the context of an actual upgrade request. A well-implemented server checks for the Upgrade header first; if it's missing, it never even looks at the WebSocket-specific headers, since this clearly isn't intended to be a handshake at all. - The practical result: the client's JavaScript WebSocket object, having sent a request that the server responds to as ordinary HTTP (not with a 101 status), will fire its own error/close event — the connection never reaches the OPEN state, because the one required response (101 Switching Protocols) never happened.