| Crates.io | axum-raw-websocket |
| lib.rs | axum-raw-websocket |
| version | 0.8.0 |
| created_at | 2025-10-17 09:14:37.334633+00 |
| updated_at | 2025-10-17 09:14:37.334633+00 |
| description | Handles WebSocket upgrades with raw socket access, based on Axum's WebSocket upgrade mechanism for Tungstenite. |
| homepage | https://github.com/tompro/axum-raw-websocket |
| repository | https://github.com/tompro/axum-raw-websocket |
| max_upload_size | |
| id | 1887402 |
| size | 37,815 |
A Rust library for handling WebSocket upgrades with raw socket access, based on Axum's WebSocket upgrade mechanism.
This websocket upgrade is based on the axum integrated one axum::extract::ws::WebSocketUpgrade. The main difference is that it will onvoke the on_upgrade callback with the raw socket which allow the socket to be used by other libraries than the default tokio-tungstenite.
RawSocketUpgrade struct for WebSocket upgrades.tokio-tungstenite.GET method) and HTTP/2+ (CONNECT method) WebSocket upgrades.OnFailedUpgrade trait.Add the following to your Cargo.toml:
[dependencies]
axum-raw-websocket = "*"
Here is an example of how to use RawSocketUpgrade:
use axum::{
routing::get,
Router,
};
use raw_socket_upgrade::RawSocketUpgrade;
async fn websocket_handler(upgrade: RawSocketUpgrade) -> axum::response::Response {
upgrade.on_upgrade(|socket| async move {
// Use the raw socket here
println!("WebSocket connection established!");
})
}
#[tokio::main]
async fn main() {
let app = Router::new().route("/ws", get(websocket_handler));
axum::Server::bind(&"0.0.0.0:3000".parse().unwrap())
.serve(app.into_make_service_with_connect_info::<SocketAddr>())
.await
.unwrap();
}
For detailed documentation, visit docs.rs.
This project is licensed under the MIT License. See the LICENSE file for details.