mirror of
https://github.com/tokio-rs/axum.git
synced 2026-08-27 00:00:24 +02:00
Add support for websockets (#3)
Basically a copy/paste of whats in warp.
Example usage:
```rust
use tower_web::{prelude::*, ws::{ws, WebSocket}};
let app = route("/ws", ws(handle_socket));
async fn handle_socket(mut socket: WebSocket) {
while let Some(msg) = socket.recv().await {
let msg = msg.unwrap();
socket.send(msg).await.unwrap();
}
}
```
This commit is contained in:
@@ -147,6 +147,17 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> IntoResponse for (HeaderMap, T)
|
||||
where
|
||||
T: Into<Body>,
|
||||
{
|
||||
fn into_response(self) -> Response<Body> {
|
||||
let mut res = Response::new(self.1.into());
|
||||
*res.headers_mut() = self.0;
|
||||
res
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> IntoResponse for (StatusCode, HeaderMap, T)
|
||||
where
|
||||
T: Into<Body>,
|
||||
|
||||
Reference in New Issue
Block a user