WebSocket-to-HTTP reverse proxy

Overview

websocket-bridge

This is a simple reverse proxy server which accepts WebSocket connections and forwards any incoming frames to backend HTTP server(s) as POST requests. Those POST requests will include a header with a "callback" URL which may be used to send frames back to the client (again via POST requests). The "callback" URL may also be shared with other clients and servers, allowing them to send frames directly to the original client for as long as the WebSocket exists.

[client] <---WebSocket--> [websocket-bridge] <---HTTP POST requests---> [backend HTTP server]

Building and Running

Prerequisites

You can build and run in one step using cargo. The --base-url argument should match the publicly-visible hostname for your server, and will be used to construct "callback" URLs. The --cert and --key arguments are optional if you'd like to use TLS.

The --allowlist option(s) (which may be specified multiple times) control which backend HTTP servers may be proxied to. Note that the --allowlist option takes a regular expression, so be sure to escape any dots in the name (e.g. foo.example.com -> foo\.example\.com). Also, you may need to use double slashes (e.g. foo\\.example\\.com) or single quotes (e.g. 'foo\.example\.com') if your shell interprets slashes itself. If you don't specify an allow list, the server will reject all incoming traffic.

cargo run -- \
    --address 0.0.0.0:9443 \
    --base-url https://$YOUR_WEBSOCKET_BRIDGE_SERVER:9443 \
    --cert $PATH_TO_YOUR_WEBSOCKET_BRIDGE_TLS_CERT \
    --key $PATH_TO_YOUR_WEBSOCKET_BRIDGE_TLS_CERT \
    --allowlist 'https://$YOUR_BACKEND_SERVER_WITH_DOTS_ESCAPED/.*'

Then, assuming your backend server is up and accepting POST requests for /frame and /disconnect, you can start sending frames using e.g.

websocat wss://$YOUR_WEBSOCKET_BRIDGE_SERVER:9443/connect?f=https://$YOUR_BACKEND_SERVER/frame&d=https://$YOUR_BACKEND_SERVER/disconnect

Any frames you send will be posted to https://$YOUR_BACKEND_SERVER/frame, and websocket-bridge will send a final POST to https://$YOUR_BACKEND_SERVER/disconnect when the WebSocket connection is closed. In both cases, the POST requests will contain a x-ws-proxy-send header that specifies the "callback" URL -- e.g. https://$YOUR_WEBSOCKET_BRIDGE_SERVER:9443/[some random UUID], where [some random UUID] is a UUID which uniquely identifies the connection.

You might also like...
The ever fast websocket tunnel built on top of lightws

Kaminari The ever fast websocket tunnel built on top of lightws. Intro Client side receives tcp then sends [tcp/ws/tls/wss]. Server side receives [tcp

Lightweight websocket implement for stream transmission.

Lightws Lightweight websocket implement for stream transmission. Features Avoid heap allocation. Avoid buffering frame payload. Use vectored-io if ava

websocket client

#websocket client async fn test_websocket()-anyhow::Result() { wasm_logger::init(wasm_logger::Config::default()); let (tx, rx) = futures_c

A webserver and websocket pair to stop your viewers from spamming !np and
A webserver and websocket pair to stop your viewers from spamming !np and "what's the song?" all the time.

spotify-np 🦀 spotify-np is a Rust-based local webserver inspired by l3lackShark's gosumemory application, but the catch is that it's for Spotify! 🎶

A secure, real-time, low-latency binary WebSocket RPC subprotocol.

HardLight A secure, real-time, low-latency binary WebSocket RPC subprotocol. HardLight has two data models: RPC: a client connects to a server, and ca

A TCP proxy using HTTP - Reach SSH behind a Nginx reverse proxy

📡 TCP over HTTP 🥦 The Questions 🪃 What does it do? You can proxy TCP traffic over HTTP. A basic setup would be: [Your TCP target] --TCP-- [Exit No

Sōzu HTTP reverse proxy, configurable at runtime, fast and safe, built in Rust. It is awesome! Ping us on gitter to know more

Sōzu · Sōzu is a lightweight, fast, always-up reverse proxy server. Why use Sōzu? Hot configurable: Sozu can receive configuration changes at runtime

Reverse proxy for HTTP microservices and STDIO. Openfass watchdog which can run webassembly with wasmer-gpu written in rust.

The of-watchdog implements an HTTP server listening on port 8080, and acts as a reverse proxy for running functions and microservices. It can be used independently, or as the entrypoint for a container with OpenFaaS.

An experimental HTTP server in Rust that supports HTTP/1.1, HTTP/2, and HTTP/3 over QUIC.

🚀 H123 An experimental HTTP server in Rust that supports HTTP/1.1, HTTP/2, and HTTP/3 over QUIC. Warning This is an experimental project and not inte

Lightweight proxy that allows redirect HTTP(S) traffic through a proxy.

Proxyswarm Proxyswarm is a lightweight proxy that allows redirect HTTP(S) traffic through a proxy. WARNING: This app isn't recomended for download lar

A MITM Proxy Written in Rust 🦀! Toolkit for HTTP/1, HTTP/2, and WebSockets with SSL/TLS Capabilities. Learning Project.
A MITM Proxy Written in Rust 🦀! Toolkit for HTTP/1, HTTP/2, and WebSockets with SSL/TLS Capabilities. Learning Project.

Man In The Middle Proxy Description Rust-based Man in the Middle proxy, an early-stage project aimed at providing visibility into network traffic. Cur

A high performence Socks5 proxy server with bind/reverse support implementation by Rust.

rsocx A high performence Socks5 proxy server with bind/reverse support implementation by Rust Features Async-std No unsafe code Single executable Linu

A firewall reverse proxy for preventing Log4J (Log4Shell aka CVE-2021-44228) attacks.
A firewall reverse proxy for preventing Log4J (Log4Shell aka CVE-2021-44228) attacks.

log4jail 🛡️ A fast firewall reverse proxy with TLS (HTTPS) and swarm support for preventing Log4J (Log4Shell aka CVE-2021-44228) attacks. 📖 Table of

A fast and stable reverse proxy for NAT traversal, written in Rust
A fast and stable reverse proxy for NAT traversal, written in Rust

rathole A fast and stable reverse proxy for NAT traversal, written in Rust rathole, like frp, can help to expose the service on the device behind the

A lightweight Rust reverse proxy.

Brachyura A reverse proxy, which I am primarily using as a Rust / Hyper learning project. I utilize Nginx as part of my home lab providing reverse pro

A minimal ngrok liked reverse proxy implemented in Rust.

rok A minimal ngrok implementation in Rust, for educational purpose. This work is largely based on rathole, especially the very first commit. Other ho

A multi-connection TCP reverse proxy server and client.

tprox A multi-connection TCP reverse proxy. The tprox server is able to proxy multiple incoming connections to the tprox client over a single TCP conn

Hopper - Fast, configurable, lightweight Reverse Proxy for Minecraft

Hopper Hopper is a lightweight reverse proxy for minecraft. It allows you to connect multiple servers under the same IP and port, with additional func

A more modern http framework benchmarker supporting HTTP/1 and HTTP/2 benchmarks.

rewrk A more modern http framework benchmark utility.

Comments
  • Support persistent sessions over multiple connections

    Support persistent sessions over multiple connections

    Currently, websocket-bridge only keeps a session alive for as long as the websocket for that session is connected. However, that websocket could be disconnected at any time for various reasons, such as client a client network change, a proxy- or firewall-imposed timeout, etc.

    We should add support for persisting sessions for a period of time after the websocket closes, giving the client time to try reconnecting, at which point the session would be associated with the new websocket. This would probably involve sending a secret to the client when it first connects, which the client could provide on reconnect to prove that it owns the session.

    In order to make this completely seamless and avoid any message loss, both the client and the server may need to buffer unacknowledged messages, send acknowledgements for all received messages, and resend messages on reconnect. We could even persist the server-side session state in a database of some kind to handle server failover, although at that point we might as well use an existing distributed event store such as Kafka.

    opened by dicej 0
Owner
Fermyon
Pioneering the next wave of cloud computing.
Fermyon
A WebSocket (RFC6455) library written in Rust

Rust-WebSocket Note: Maintainership of this project is slugglish. You may want to use tungstenite or tokio-tungstenite instead. Rust-WebSocket is a We

Rust Websockets 1.3k Jan 6, 2023
Lightweight stream-based WebSocket implementation for Rust.

Tungstenite Lightweight stream-based WebSocket implementation for Rust. use std::net::TcpListener; use std::thread::spawn; use tungstenite::server::ac

Snapview GmbH 1.3k Jan 2, 2023
Websocket generic library for Bitwyre WS-API

Websocket Core (Rust) Websocket generic server library for: Periodic message broadcast Eventual (Pubsub) message broadcast Async request reply Authors

Bitwyre 13 Oct 28, 2022
Jamsocket is a lightweight framework for building WebSocket-based application backends.

Jamsocket is a lightweight framework for building services that are accessed through WebSocket connections.

null 94 Dec 30, 2022
A CLI development tool for WebSocket APIs

A CLI development tool for WebSocket APIs

Espen Henriksen 622 Dec 26, 2022
Spawn process IO to websocket with full PTY support.

Cliws Spawn process IO to websocket with full PTY support. Features Any process IO through Websocket Full pty support: VIM, SSH, readline, Ctrl+X Auto

B23r0 91 Jan 5, 2023
A lightweight framework for building WebSocket-based application backends.

Jamsocket Jamsocket is a lightweight framework for building services that are accessed through WebSocket connections. Services can either be native Ru

drifting in space 94 Dec 30, 2022
A WebSocket (RFC6455) library written in Rust

Rust-WebSocket Rust-WebSocket is a WebSocket (RFC6455) library written in Rust. Rust-WebSocket provides a framework for dealing with WebSocket connect

Jason N 19 Aug 22, 2022
An aria2 websocket jsonrpc in Rust.

aria2-ws An aria2 websocket jsonrpc in Rust. Built with tokio. Docs.rs aria2 RPC docs Features Almost all methods and structed responses Auto reconnec

null 8 Sep 7, 2022
A simple toy websocket client to connect to Bitstamp.net and print the live order book written in Rust.

A simple toy websocket client to connect to Bitstamp.net and print the live order book written in Rust.

Nate Houk 1 Feb 14, 2022