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§
Required Methods§
Sourcefn websocket(
&self,
url: impl IntoUrl,
) -> BlockingWebSocketRequestBuilder<'_, Self::AsyncService, Body>
fn websocket( &self, url: impl IntoUrl, ) -> BlockingWebSocketRequestBuilder<'_, Self::AsyncService, Body>
Create a WebSocket request builder for an HTTP/1.1 upgrade.
Sourcefn websocket_h2(
&self,
url: impl IntoUrl,
) -> BlockingWebSocketRequestBuilder<'_, Self::AsyncService, Body>
fn websocket_h2( &self, url: impl IntoUrl, ) -> BlockingWebSocketRequestBuilder<'_, Self::AsyncService, Body>
Create a WebSocket request builder for HTTP/2 Extended CONNECT.
Sourcefn websocket_with_request<RequestBody: Into<Body>>(
&self,
request: Request<RequestBody>,
) -> BlockingWebSocketRequestBuilder<'_, Self::AsyncService, Body>
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".