Skip to content

v0.5.1 -- WebSocket source + sink

Choose a tag to compare

@hamidr hamidr released this 11 Apr 09:22
· 93 commits to main since this release

New: WebSocket source + sink in pipe-http

Bidirectional WebSocket communication via pipe_http::ws.

use pipe_http::ws;

let (incoming, sender) = ws::connect("wss://example.com/ws");

// Send from any task
let s = sender.clone();
tokio::spawn(async move { s.send_text("hello").await });

// Process incoming as a pipe
incoming
    .and_then(|m| m.text())
    .for_each(|text| println!("{text}"))
    .await?;

Features

  • ws::connect(url) -- returns (Pipe<WsMessage>, WsSender) synchronously; connection established lazily on first pull
  • WsSender -- cloneable, channel-based write handle decoupled from pong responses
  • WsMessage -- Text, Binary, Close variants with Option-returning text() and bytes() accessors
  • Automatic ping/pong handling (transparent to user)
  • 16 MiB incoming message size limit
  • Sender detects closed connection (PipeError::Closed)
  • 8 integration tests against in-process axum WebSocket server

No auto-reconnection by design

WebSocket has no built-in resume protocol (unlike SSE's Last-Event-ID). For app-level reconnection, use pipe's retry() or handle_error_with().

Install

[dependencies]
pipe-http = { git = "https://github.com/hamidr/pipe" }

263 total workspace tests, zero warnings.