Skip to content

Add support for proxying in `WebsocketClient`

Compare
Choose a tag to compare
@VaporBot VaporBot released this 11 Apr 14:34
· 13 commits to main since this release
2166cbe
This patch was authored by @rnro and released by @0xTim.

Added support for TLS and plain text proxying of Websocket traffic.

  • In the TLS case a CONNECT header is first sent establishing the proxied traffic.

  • In the plain text case the modified URI in the initial upgrade request header indicates to the proxy server that the traffic is to be proxied.

  • Use NIOWebSocketFrameAggregator to handle aggregating frame fragments. This brings with it more protections e.g. against memory exhaustion.

  • Accompanying config has been added to support this change.

This change also includes some performance gains by reducing the allocation and copies necessary to send ByteBuffer and ByteBufferView through WebSocket.send.

  • Sending ByteBuffer or ByteBufferView doesn’t require any allocation or copy of the data. Sending a String now correctly pre allocates the ByteBuffer if multibyte characters are present in the String.

  • Remove custom random websocket mask generation which would only generate bytes between UInt8.min..<UInt8.max, therefore excluding UInt8.max i.e. 255.