Trait BlockingHttpClientWebSocketExt
pub trait BlockingHttpClientWebSocketExt<Body>: BlockingHttpClientWebSocketExtSealed<Body> {
type AsyncService: Service<Request, Output = Response<Body>>
where <Self::AsyncService as Service<Request>>::Error: Into<Box<dyn Error + Send + Sync>>;
// Required methods
fn websocket(
&self,
url: impl IntoUrl,
) -> WebSocketRequestBuilder<WithService<'_, Self::AsyncService, Body, Blocking<Self::AsyncService>>>;
fn websocket_h2(
&self,
url: impl IntoUrl,
) -> WebSocketRequestBuilder<WithService<'_, Self::AsyncService, Body, Blocking<Self::AsyncService>>>;
fn websocket_with_request<RequestBody>(
&self,
request: Request<RequestBody>,
) -> WebSocketRequestBuilder<WithService<'_, Self::AsyncService, Body, Blocking<Self::AsyncService>>>
where RequestBody: Into<Body>;
}Available on crate features
http and std and ws only.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§
fn websocket(
&self,
url: impl IntoUrl,
) -> WebSocketRequestBuilder<WithService<'_, Self::AsyncService, Body, Blocking<Self::AsyncService>>>
fn websocket( &self, url: impl IntoUrl, ) -> WebSocketRequestBuilder<WithService<'_, Self::AsyncService, Body, Blocking<Self::AsyncService>>>
Create a WebSocket request builder for an HTTP/1.1 upgrade.
fn websocket_h2(
&self,
url: impl IntoUrl,
) -> WebSocketRequestBuilder<WithService<'_, Self::AsyncService, Body, Blocking<Self::AsyncService>>>
fn websocket_h2( &self, url: impl IntoUrl, ) -> WebSocketRequestBuilder<WithService<'_, Self::AsyncService, Body, Blocking<Self::AsyncService>>>
Create a WebSocket request builder for HTTP/2 Extended CONNECT.
fn websocket_with_request<RequestBody>(
&self,
request: Request<RequestBody>,
) -> WebSocketRequestBuilder<WithService<'_, Self::AsyncService, Body, Blocking<Self::AsyncService>>>
fn websocket_with_request<RequestBody>( &self, request: Request<RequestBody>, ) -> WebSocketRequestBuilder<WithService<'_, Self::AsyncService, Body, Blocking<Self::AsyncService>>>
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".