Start a local TCP listener that bridges each connection to the WS tunnel. Returns the local address the proxy is listening on.
(ws_url: String)
| 184 | /// |
| 185 | /// Returns the local address the proxy is listening on. |
| 186 | async fn start_ws_proxy(ws_url: String) -> SocketAddr { |
| 187 | let listener = TcpListener::bind("127.0.0.1:0").await.unwrap(); |
| 188 | let local_addr = listener.local_addr().unwrap(); |
| 189 | |
| 190 | tokio::spawn(async move { |
| 191 | loop { |
| 192 | let Ok((tcp_stream, _)) = listener.accept().await else { |
| 193 | continue; |
| 194 | }; |
| 195 | let ws_url = ws_url.clone(); |
| 196 | tokio::spawn(async move { |
| 197 | let _ = proxy_connection(tcp_stream, &ws_url).await; |
| 198 | }); |
| 199 | } |
| 200 | }); |
| 201 | |
| 202 | local_addr |
| 203 | } |
| 204 | |
| 205 | /// Bridge a single local TCP connection through a WebSocket to the tunnel. |
| 206 | async fn proxy_connection( |
no test coverage detected