Making Libcurl Work in WebAssembly
9 months ago
- #Networking
- #libcurl
- #WebAssembly
- Libcurl applications can work in WebAssembly by tunneling traffic over a websocket proxy.
- WebR ports R to WebAssembly, but networking is limited due to browser runtime constraints.
- Emscripten emulates TCP connections over WebSocket, requiring a WebSockify proxy server.
- Use `-sWEBSOCKET_URL=wss://` or runtime JS to enforce secure WebSocket connections.
- SOCKS5 proxy over WebSocket enables libcurl to connect to arbitrary HTTP services.
- A Docker container combines websockify and SOCKS5 for a production-ready proxy setup.
- CloudFlare can front the proxy for HTTPS and performance benefits.
- Setting `ALL_PROXY` in WebAssembly allows libcurl-based applications to work unchanged.
- Example: Downloading files in WebR via a SOCKS5 proxy over WebSocket demonstrates the approach.
- The solution is secure, leveraging encrypted HTTPS connections through the proxy.