|
1 |
| -//! Module for handling WebSocket connection |
| 1 | +//! Handle WebSocket connection |
2 | 2 | //!
|
3 | 3 | //! This module provides utilities for setting up and handling WebSocket connections, including
|
4 | 4 | //! configuring WebSocket options, setting protocols, and upgrading connections.
|
|
8 | 8 | //! # Example
|
9 | 9 | //!
|
10 | 10 | //! ```rust
|
| 11 | +//! use std::convert::Infallible; |
| 12 | +//! |
11 | 13 | //! use futures_util::{SinkExt, StreamExt};
|
12 | 14 | //! use volo_http::{
|
13 | 15 | //! response::ServerResponse,
|
|
21 | 23 | //! async fn handle_socket(mut socket: WebSocket) {
|
22 | 24 | //! while let Some(Ok(msg)) = socket.next().await {
|
23 | 25 | //! match msg {
|
24 |
| -//! Message::Text(text) => { |
| 26 | +//! Message::Text(_) => { |
25 | 27 | //! socket.send(msg).await.unwrap();
|
26 | 28 | //! }
|
27 | 29 | //! _ => {}
|
|
33 | 35 | //! ws.on_upgrade(handle_socket)
|
34 | 36 | //! }
|
35 | 37 | //!
|
36 |
| -//! let app = Router::new().route("/ws", get(ws_handler)); |
| 38 | +//! let app: Router<ServerResponse, Infallible> = Router::new().route("/ws", get(ws_handler)); |
37 | 39 | //! ```
|
38 | 40 |
|
39 | 41 | use std::{borrow::Cow, fmt::Formatter, future::Future};
|
@@ -127,8 +129,8 @@ impl Config {
|
127 | 129 | }
|
128 | 130 |
|
129 | 131 | /// Set transport config
|
130 |
| - /// e.g. write buffer size |
131 | 132 | ///
|
| 133 | + /// e.g. write buffer size |
132 | 134 | ///
|
133 | 135 | /// ```rust
|
134 | 136 | /// use tokio_tungstenite::tungstenite::protocol::WebSocketConfig as WebSocketTransConfig;
|
@@ -213,16 +215,18 @@ impl Callback for DefaultCallback {
|
213 | 215 | ///
|
214 | 216 | /// **Constrains**:
|
215 | 217 | ///
|
216 |
| -/// The extractor only supports for the request that has the method [`GET`](http::Method::GET) |
| 218 | +/// The extractor only supports for the request that has the method [`GET`](http::method::GET) |
217 | 219 | /// and contains certain header values.
|
218 | 220 | ///
|
| 221 | +/// See more details in [`WebSocketUpgrade::from_context`] |
| 222 | +/// |
219 | 223 | /// # Usage
|
220 | 224 | ///
|
221 | 225 | /// ```rust
|
222 | 226 | /// use volo_http::{response::ServerResponse, server::utils::WebSocketUpgrade};
|
223 | 227 | ///
|
224 | 228 | /// fn ws_handler(ws: WebSocketUpgrade) -> ServerResponse {
|
225 |
| -/// ws.on_upgrade(|socket| unimplemented!()) |
| 229 | +/// ws.on_upgrade(|socket| async { unimplemented!() }) |
226 | 230 | /// }
|
227 | 231 | /// ```
|
228 | 232 | pub struct WebSocketUpgrade<F = DefaultOnFailedUpgrade> {
|
|
0 commit comments