If someone would ask me if I'm familiar with websockets then I would answer yes. If there were to ask a follow up question on how it works then I'd be stumped. The only thing I realized that I know about websockets is that it is first initiated by an [[HTTP]] request and then the underlying [[TCP]] connection for that request is hijacked and kept open for communication.
I know there is the [[The Websocket Protocol]] but other than an initial handshake what does it do? And how does one proxy it, is it possible to just proxy the request as normal or do you need to hijack at each proxy and recreate the request to send further?
## Reading the websocket protocol
I'll start of by reading the protocol specification found at [The Websocket Protocol](https://datatracker.ietf.org/doc/html/rfc6455). I may choose to at many of the notes I take from that into [[The Websocket Protocol]] and keep the notes on how the protocol may affect my implementation.
After reading the specification it seems I only need to consider the initial handshake (and possibly correctly responding to the close handshake). In [[The Websocket Protocol#Completing the handshake|completing the handshake]] to complete the initial handshake the server needs to respond with:
```
HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: <some_key>
Sec-WebSocket-Protocol: <some_subprotocol_name>
```
I should need to attempt to interpret anything past the `Upgrade` and `Connection` headers. Since I'll be opening a [[Dedicated tunnel|dedicated tunnel]] for each websocket request, all I need to make sure is the the response is correctly routed back to the caller after I have hijacked the network connection.