Skip to main content

accept

Function accept 

Source
pub fn accept<B>(
    request: &mut Request<B>,
) -> Result<(Response<Empty<Bytes>>, impl Future<Output = Result<UpgradedIo, WebSocketError>>), WebSocketError>
Expand description

Accept a WebSocket upgrade, requiring the DEFAULT_SUBPROTOCOL (h2ts).

Echoes h2ts when the client offered it; a client that doesn’t offer h2ts is rejected with WebSocketError::UnsupportedSubprotocol (send rejection_response back as a 400). Use accept_with to select a different offered subprotocol, or accept_with_options with allow_implicit_codec to accept any codec.

On success, returns the 101 Switching Protocols response to send back immediately, plus a future that resolves to the upgraded connection as a byte stream (UpgradedIo). Drive the response through your framework; spawn the future and hand the stream to bridge or serve_h2. Control frames (ping/close) are handled downstream by wslay.

The outer HTTP/1 connection must be served with upgrades enabled (http1::Builder::serve_connection(..).with_upgrades()).