pub struct H2WsConnection { /* private fields */ }Expand description
An HTTP/2 connection that can open WebSocket streams via extended CONNECT.
Internally this wraps hyper’s HTTP/2 client connection and keeps the
SendRequest handle alive. The HTTP/2 connection driver is spawned on a
background task.
Implementations§
Source§impl H2WsConnection
impl H2WsConnection
Sourcepub async fn connect_tcp(addr: &str) -> Result<Self, H2WsError>
pub async fn connect_tcp(addr: &str) -> Result<Self, H2WsError>
Establish a new HTTP/2 client connection over plain TCP (h2c).
This helper is TCP-specific. If you need TLS, you can add a method like
connect_tls that wraps a TLS stream and passes it into Self::from_io.
Sourcepub async fn from_io<I>(io: I) -> Result<Self, H2WsError>
pub async fn from_io<I>(io: I) -> Result<Self, H2WsError>
Create an H2WsConnection from an arbitrary I/O stream.
The io type must implement AsyncRead + AsyncWrite + Unpin + Send + 'static.
This allows integrating with custom transports (TLS, Unix sockets, etc).
Sourcepub async fn connect_websocket(
&mut self,
path: &str,
host: &str,
subprotocol: Option<&str>,
) -> Result<H2WebSocketStream, H2WsError>
pub async fn connect_websocket( &mut self, path: &str, host: &str, subprotocol: Option<&str>, ) -> Result<H2WebSocketStream, H2WsError>
Open a WebSocket over this HTTP/2 connection using RFC 8441 extended CONNECT.
path: HTTP request path, e.g."/echo".host: value for theHostheader, e.g."localhost".subprotocol: optional WebSocket subprotocol, e.g."echo"or"graphql-ws".
This method:
- Sends a
CONNECTrequest with:protocol = "websocket". - Checks that the status code is 2xx.
- Calls
hyper::upgrade::onto obtain the upgraded I/O stream. - Wraps the upgraded stream in
tokio_tungstenite::WebSocketStream.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for H2WsConnection
impl !RefUnwindSafe for H2WsConnection
impl Send for H2WsConnection
impl Sync for H2WsConnection
impl Unpin for H2WsConnection
impl !UnwindSafe for H2WsConnection
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more