Skip to main content

BlockingHttpClientWebSocketExt

Trait BlockingHttpClientWebSocketExt 

Source
pub trait BlockingHttpClientWebSocketExt<Body>: BlockingHttpClientWebSocketExtSealed<Body> {
    type AsyncService: Service<Request, Output = Response<Body>, Error: Into<BoxError>>;

    // Required methods
    fn websocket(
        &self,
        url: impl IntoUrl,
    ) -> BlockingWebSocketRequestBuilder<'_, Self::AsyncService, Body>;
    fn websocket_h2(
        &self,
        url: impl IntoUrl,
    ) -> BlockingWebSocketRequestBuilder<'_, Self::AsyncService, Body>;
    fn websocket_with_request<RequestBody: Into<Body>>(
        &self,
        request: Request<RequestBody>,
    ) -> BlockingWebSocketRequestBuilder<'_, Self::AsyncService, Body>;
}
Expand description

Extends a blocking HTTP client with WebSocket handshake builders.

The HTTP client remains reusable after the handshake. Each successful handshake returns one independent, connected BlockingClientWebSocket.

§Panics

Blocking handshakes and socket I/O must not run directly on an asynchronous executor thread.

use rama_core::{Service, error::BoxError};
use rama_http::{
    Body, Request, Response,
    service::client::blocking::Client,
};
use rama_ws::handshake::client::BlockingHttpClientWebSocketExt as _;

fn exchange<S>(client: &Client<S>) -> Result<(), BoxError>
where
    S: Service<Request, Output = Response<Body>, Error: Into<BoxError>>,
{
    let mut socket = client
        .websocket("wss://example.com/chat")
        .with_header("authorization", "Bearer secret")
        .try_handshake()?;

    socket.send_message("hello".into())?;
    let _reply = socket.recv_message()?;
    Ok(())
}

Required Associated Types§

Source

type AsyncService: Service<Request, Output = Response<Body>, Error: Into<BoxError>>

The asynchronous service wrapped by this blocking HTTP client.

Required Methods§

Source

fn websocket( &self, url: impl IntoUrl, ) -> BlockingWebSocketRequestBuilder<'_, Self::AsyncService, Body>

Create a WebSocket request builder for an HTTP/1.1 upgrade.

Source

fn websocket_h2( &self, url: impl IntoUrl, ) -> BlockingWebSocketRequestBuilder<'_, Self::AsyncService, Body>

Create a WebSocket request builder for HTTP/2 Extended CONNECT.

Source

fn websocket_with_request<RequestBody: Into<Body>>( &self, request: Request<RequestBody>, ) -> BlockingWebSocketRequestBuilder<'_, Self::AsyncService, Body>

Create a WebSocket request builder from an existing request.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<S, Body> BlockingHttpClientWebSocketExt<Body> for Client<S>
where S: Service<Request, Output = Response<Body>, Error: Into<BoxError>>, Body: Send + 'static,

Source§

type AsyncService = S

Source§

fn websocket( &self, url: impl IntoUrl, ) -> BlockingWebSocketRequestBuilder<'_, Self::AsyncService, Body>

Source§

fn websocket_h2( &self, url: impl IntoUrl, ) -> BlockingWebSocketRequestBuilder<'_, Self::AsyncService, Body>

Source§

fn websocket_with_request<RequestBody: Into<Body>>( &self, request: Request<RequestBody>, ) -> BlockingWebSocketRequestBuilder<'_, Self::AsyncService, Body>

Implementors§