Files
session-rs/Cargo.toml
T
selimaj-devandclaude d11d4ea08b Make the protocol transport-agnostic and use tokio-tungstenite
Replace the hand-rolled WebSocket implementation with a transport
boundary (Frame over any Sink/Stream) plus adapters for tokio-tungstenite
(server/client features) and axum (axum feature). The JSON wire format
is unchanged, so existing peers keep working.

Fixes:
- unbounded frame lengths were allocated up front; the server now
  enforces message/frame size limits (1 MiB default)
- responses arriving before `request` subscribed were lost
- an accept() error ended `session_loop`
- requests sent right after connecting could arrive before handlers
  were registered; the receiver now starts after `on_conn` returns
- panics in the receive loop skipped `on_close` and leaked sessions;
  `on_close` now runs exactly once and handler panics fail only their
  request
- unknown methods and invalid data got no reply; they now get an
  error response
- slow handlers blocked pongs and responses

Adds `on_notification`, `request_timeout`, `closed`, `is_closed`, `id`,
`ServerConfig`, `from_transport`, `from_tungstenite` and `from_axum`,
integration tests, and an axum example. Bumps to 0.2.0 since
`Session::connect` now takes a URL and the `ws` module is removed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-09-25 05:35:57 +02:00

39 lines
1.5 KiB
TOML

[package]
name = "session-rs"
version = "0.2.0"
edition = "2024"
description = "A lightweight async request/response and notification protocol over WebSockets"
license = "Apache-2.0"
repository = "https://git.selimaj.dev/selimaj-dev/session-rs"
[features]
default = ["server", "client"]
# `SessionServer`: a standalone tokio-tungstenite WebSocket server.
server = ["dep:tokio-tungstenite", "tokio/net"]
# `Session::connect`: a tokio-tungstenite WebSocket client (ws:// only without a TLS feature).
client = ["dep:tokio-tungstenite", "tokio-tungstenite/connect"]
# `wss://` support for the client.
rustls = ["client", "tokio-tungstenite/rustls-tls-webpki-roots"]
native-tls = ["client", "tokio-tungstenite/native-tls"]
# `Session::from_axum`: run a session on an axum WebSocket upgrade.
axum = ["dep:axum"]
[dependencies]
futures-util = { version = "0.3.34", default-features = false, features = ["sink", "std"] }
serde = { version = "1.0.228", features = ["derive"] }
serde_json = "1.0.149"
tokio = { version = "1.49.0", features = ["macros", "rt", "sync", "time"] }
tokio-tungstenite = { version = "0.30.0", default-features = false, features = ["handshake"], optional = true }
axum = { version = "0.8.9", default-features = false, features = ["ws"], optional = true }
[dev-dependencies]
tokio = { version = "1.49.0", features = ["macros", "rt-multi-thread", "net", "time", "io-util"] }
axum = { version = "0.8.9", features = ["ws"] }
[[example]]
name = "axum"
required-features = ["axum"]
[package.metadata.docs.rs]
all-features = true