Skip to main content

H2AsyncConn

Struct H2AsyncConn 

Source
pub struct H2AsyncConn { /* private fields */ }
Expand description

Async HTTP/2 connection with multiplexed request support.

Wraps a sans-IO H2Connection and a ConnCtx, providing a pump loop that bridges bytes between the transport and the H2 state machine.

Implementations§

Source§

impl H2AsyncConn

Source

pub async fn connect(addr: SocketAddr, host: &str) -> Result<Self, HttpError>

Connect to an HTTP/2 server over TLS.

Performs TLS handshake, sends the H2 connection preface, and waits for the server SETTINGS exchange to complete.

Source

pub async fn connect_with_timeout( addr: SocketAddr, host: &str, timeout_ms: u64, ) -> Result<Self, HttpError>

Connect with a timeout (milliseconds).

Source

pub async fn from_conn(conn: ConnCtx) -> Result<Self, HttpError>

Wrap an already-connected ConnCtx (must be TLS for H2).

Sends the H2 preface and waits for SETTINGS exchange.

Source

pub fn close(&self)

Returns the underlying connection context.

Source

pub fn conn(&self) -> ConnCtx

Source

pub fn pending_count(&self) -> usize

Number of in-flight streams.

Source

pub async fn send_request( &mut self, method: &str, path: &str, host: &str, extra_headers: &[(&str, &str)], body: Option<&[u8]>, ) -> Result<Response, HttpError>

Send a request and wait for the complete response.

Source

pub fn fire_request( &mut self, method: &str, path: &str, host: &str, extra_headers: &[(&str, &str)], body: Option<&[u8]>, ) -> Result<u32, HttpError>

Fire an HTTP/2 request. Returns the stream ID immediately.

The request is queued for sending; call recv() or recv_stream() to pump the connection and collect responses.

Source

pub async fn recv(&mut self) -> Result<(u32, Response), HttpError>

Pump until any stream completes. Returns (stream_id, Response).

Source

pub async fn recv_stream( &mut self, stream_id: u32, ) -> Result<Response, HttpError>

Pump until a specific stream completes.

Source

pub async fn send_request_streaming( &mut self, method: &str, path: &str, host: &str, extra_headers: &[(&str, &str)], body: Option<&[u8]>, ) -> Result<H2StreamingResponse<'_>, HttpError>

Send a request and return a streaming response after headers arrive.

The caller must drain the body via H2StreamingResponse::next_chunk() before issuing further requests on this connection.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.