7 stable releases
Uses new Rust 2024
| new 2.3.1 | Feb 25, 2026 |
|---|---|
| 2.2.0 | Feb 21, 2026 |
| 1.4.0 | Feb 13, 2026 |
#156 in WebSocket
Used in 2 crates
335KB
5K
SLoC
hpx-yawc
A fast, secure WebSocket implementation with RFC 6455 compliance and permessage-deflate compression (RFC 7692). Autobahn compliant. Supports WASM targets.
This crate is part of the hpx project. It is a fork of yawc (Yet Another WebSocket Client).
Features
- Full RFC 6455 compliance — passes the Autobahn test suite
- Permessage-deflate compression (RFC 7692) with configurable window bits
- SIMD-accelerated frame masking (NEON on ARM, AVX2 on x86)
- Optional SIMD-accelerated UTF-8 validation
- WASM target support
- Axum WebSocket extractor integration
- Multiple TLS backends (ring, aws-lc-rs)
- Alternative async runtime support (smol)
Quick Start
Client
use futures::{SinkExt, StreamExt};
use hpx_yawc::{WebSocket, frame::OpCode};
async fn connect() -> hpx_yawc::Result<()> {
let mut ws = WebSocket::connect("wss://echo.websocket.org".parse()?).await?;
while let Some(frame) = ws.next().await {
match frame.opcode() {
OpCode::Text | OpCode::Binary => ws.send(frame).await?,
OpCode::Ping => {
// Pong is sent automatically, but ping is still returned
}
_ => {}
}
}
Ok(())
}
Server (with hyper)
use futures::StreamExt;
use http_body_util::Empty;
use hyper::{
Request, Response,
body::{Bytes, Incoming},
};
use hpx_yawc::WebSocket;
async fn upgrade(mut req: Request<Incoming>) -> hpx_yawc::Result<Response<Empty<Bytes>>> {
let (response, fut) = WebSocket::upgrade(&mut req)?;
tokio::spawn(async move {
if let Ok(mut ws) = fut.await {
while let Some(frame) = ws.next().await {
// Process frames
}
}
});
Ok(response)
}
Protocol Handling
hpx-yawc automatically handles WebSocket control frames:
- Ping frames: Automatically responded to with pongs, but still returned to your application
- Pong frames: Passed through without special handling
- Close frames: Automatically acknowledged, then returned before closing the connection
Feature Flags
| Feature | Default | Description |
|---|---|---|
rustls-ring |
Yes | TLS via rustls with ring crypto backend |
rustls-aws-lc-rs |
No | TLS via rustls with AWS LC crypto backend |
axum |
No | Axum WebSocket extractor integration |
simd |
No | SIMD-accelerated UTF-8 validation |
smol |
No | smol async runtime support |
zlib |
No | zlib compression backend (enables window bits configuration) |
Compression
Permessage-deflate compression is always available with the default flate2/miniz_oxide backend (a pure Rust implementation of deflate). The zlib feature enables the native zlib backend and advanced window bits configuration parameters.
Runtime Support
hpx-yawc is built on tokio's I/O traits but can work with other async runtimes through simple adapters. Enable the smol feature for built-in smol runtime support, or implement trait bridges between your runtime's I/O traits and tokio's AsyncRead/AsyncWrite.
License
Apache-2.0
Dependencies
~4–25MB
~325K SLoC