pub struct WebSocketUpgrade { /* private fields */ }
ws
only.Expand description
Extractor for establishing WebSocket connections.
Note: This extractor requires the request method to be GET
so it should
always be used with get
. Requests with other methods will be
rejected.
See the module docs for an example.
Implementations
Set the size of the internal message send queue.
Set the maximum message size (defaults to 64 megabytes)
Set the maximum frame size (defaults to 16 megabytes)
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.
The protocols should be listed in decreasing order of preference: if the client offers multiple protocols that the server could support, the server will pick the first one in this list.
Examples
use axum::{
extract::ws::{WebSocketUpgrade, WebSocket},
routing::get,
response::IntoResponse,
Router,
};
let app = Router::new().route("/ws", get(handler));
async fn handler(ws: WebSocketUpgrade) -> impl IntoResponse {
ws.protocols(["graphql-ws", "graphql-transport-ws"])
.on_upgrade(|socket| async {
// ...
})
}
Finalize upgrading the connection and call the provided callback with the stream.
When using WebSocketUpgrade
, the response produced by this method
should be returned from the handler. See the module docs for an
example.
Trait Implementations
If the extractor fails it’ll use this “rejection” type. A rejection is a kind of error that can be converted into a response. Read more
fn from_request<'life0, 'async_trait>(
req: &'life0 mut RequestParts<B>
) -> Pin<Box<dyn Future<Output = Result<Self, Self::Rejection>> + Send + 'async_trait>> where
'life0: 'async_trait,
Self: 'async_trait,
fn from_request<'life0, 'async_trait>(
req: &'life0 mut RequestParts<B>
) -> Pin<Box<dyn Future<Output = Result<Self, Self::Rejection>> + Send + 'async_trait>> where
'life0: 'async_trait,
Self: 'async_trait,
Perform the extraction.
Auto Trait Implementations
impl !RefUnwindSafe for WebSocketUpgrade
impl Send for WebSocketUpgrade
impl Sync for WebSocketUpgrade
impl Unpin for WebSocketUpgrade
impl !UnwindSafe for WebSocketUpgrade
Blanket Implementations
Mutably borrows from an owned value. Read more
Create a new Policy
that returns Action::Follow
only if self
and other
return
Action::Follow
. 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