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
sourceimpl WebSocketUpgrade
impl WebSocketUpgrade
sourcepub fn max_send_queue(self, max: usize) -> Self
pub fn max_send_queue(self, max: usize) -> Self
Set the size of the internal message send queue.
sourcepub fn max_message_size(self, max: usize) -> Self
pub fn max_message_size(self, max: usize) -> Self
Set the maximum message size (defaults to 64 megabytes)
sourcepub fn max_frame_size(self, max: usize) -> Self
pub fn max_frame_size(self, max: usize) -> Self
Set the maximum frame size (defaults to 16 megabytes)
sourcepub fn protocols<I>(self, protocols: I) -> Selfwhere
I: IntoIterator,
I::Item: Into<Cow<'static, str>>,
pub fn protocols<I>(self, protocols: I) -> Selfwhere
I: IntoIterator,
I::Item: Into<Cow<'static, str>>,
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, Response},
Router,
};
let app = Router::new().route("/ws", get(handler));
async fn handler(ws: WebSocketUpgrade) -> Response {
ws.protocols(["graphql-ws", "graphql-transport-ws"])
.on_upgrade(|socket| async {
// ...
})
}
sourcepub fn on_upgrade<F, Fut>(self, callback: F) -> Responsewhere
F: FnOnce(WebSocket) -> Fut + Send + 'static,
Fut: Future<Output = ()> + Send + 'static,
pub fn on_upgrade<F, Fut>(self, callback: F) -> Responsewhere
F: FnOnce(WebSocket) -> Fut + Send + 'static,
Fut: Future<Output = ()> + Send + 'static,
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
sourceimpl Debug for WebSocketUpgrade
impl Debug for WebSocketUpgrade
sourceimpl<S> FromRequestParts<S> for WebSocketUpgradewhere
S: Send + Sync,
impl<S> FromRequestParts<S> for WebSocketUpgradewhere
S: Send + Sync,
type Rejection = WebSocketUpgradeRejection
type Rejection = WebSocketUpgradeRejection
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
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
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<S, B, T> FromRequest<S, B, ViaParts> for Twhere
B: 'static + Send,
S: Send + Sync,
T: FromRequestParts<S>,
impl<S, B, T> FromRequest<S, B, ViaParts> for Twhere
B: 'static + Send,
S: Send + Sync,
T: FromRequestParts<S>,
type Rejection = <T as FromRequestParts<S>>::Rejection
type Rejection = <T as FromRequestParts<S>>::Rejection
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
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<V, T> VZip<V> for Twhere
V: MultiLane<T>,
impl<V, T> VZip<V> for Twhere
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more