pub struct WebSocketUpgrade { /* private fields */ }
This is supported on crate feature 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

Formats the value using the given formatter. Read more

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

Perform the extraction.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

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