Struct poem::web::websocket::WebSocket [−][src]
pub struct WebSocket { /* fields omitted */ }
This is supported on crate feature
websocket
only.Expand description
Implementations
Set the known protocols.
If the protocol name specified by Sec-WebSocket-Protocol
header
to match any of them, the upgrade response will include
Sec-WebSocket-Protocol
header and return the protocol name.
use futures_util::{SinkExt, StreamExt};
use poem::{get, handler, web::websocket::WebSocket, IntoResponse, Route};
#[handler]
async fn index(ws: WebSocket) -> impl IntoResponse {
ws.protocols(vec!["graphql-rs", "graphql-transport-ws"])
.on_upgrade(|socket| async move {
// ...
})
}
let app = Route::new().at("/", get(index));
pub fn on_upgrade<F, Fut>(self, callback: F) -> impl IntoResponse where
F: FnOnce(WebSocketStream) -> Fut + Send + Sync + 'static,
Fut: Future + Send + 'static,
pub fn on_upgrade<F, Fut>(self, callback: F) -> impl IntoResponse where
F: FnOnce(WebSocketStream) -> Fut + Send + Sync + 'static,
Fut: Future + Send + 'static,
Finalize upgrading the connection and call the provided callback
with
the stream.
Note that the return value of this function must be returned from the handler.
Trait Implementations
fn from_request<'life0, 'async_trait>(
req: &'a Request,
_body: &'life0 mut RequestBody
) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>> where
'a: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait,
fn from_request<'life0, 'async_trait>(
req: &'a Request,
_body: &'life0 mut RequestBody
) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>> where
'a: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait,
Extract from request head and body.
Auto Trait Implementations
impl !RefUnwindSafe for WebSocket
impl !UnwindSafe for WebSocket
Blanket Implementations
Mutably borrows from an owned value. Read more
pub fn vzip(self) -> V
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more