pub async fn proxy_upgrade(
host: String,
port: u16,
path: String,
tls: bool,
verify: bool,
tls_identity: Option<Arc<UpstreamTls>>,
fwd_headers: &HashMap<String, Vec<String>>,
client_on_upgrade: OnUpgrade,
client_is_h2: bool,
) -> Result<Response<Full<Bytes>>, WsError>Expand description
Opens the (always HTTP/1.1) upstream WebSocket handshake to host:port at
path, and — on a successful upstream 101 — returns the client-facing
response and spawns a task that relays bytes between the client and upstream
once the client connection upgrades.
client_is_h2 selects the client-facing semantics:
false(HTTP/1.1 client): forward the client’sSec-WebSocket-*headers to the upstream and return a101 Switching Protocolsechoing the upstream’sSec-WebSocket-Accept.true(HTTP/2 RFC 8441 client): the client sent noSec-WebSocket-Key, so synthesize one (andVersion: 13) for the upstream handshake, and return a200 OK(extended CONNECT success) with noSec-WebSocket-*headers.
fwd_headers are the client request’s headers (name → values); only the
WebSocket-relevant ones are forwarded. client_on_upgrade is the client’s
[OnUpgrade] captured by the listener before the request was consumed; it
resolves only after the returned response is written back to the client.
tls_identity, when set, is the per-upstream client certificate (and
private CA) to present during the wss handshake; None falls back to
the shared verified/insecure connector selected by verify.