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
impl H2AsyncConn
Sourcepub fn set_max_decompressed_size(&mut self, n: usize)
pub fn set_max_decompressed_size(&mut self, n: usize)
Override the cap on a decompressed response body. Default 64 MiB — defends against decompression bombs.
Sourcepub fn set_max_header_section(&mut self, n: usize)
pub fn set_max_header_section(&mut self, n: usize)
Override the cap on the total response header bytes (sum of name + value lengths) collected per stream. Default 64 KiB.
Sourcepub fn set_max_body_size(&mut self, n: usize)
pub fn set_max_body_size(&mut self, n: usize)
Override the cap on a single stream’s accumulated response body. Default 16 MiB.
Sourcepub fn peer_will_close(&self) -> bool
pub fn peer_will_close(&self) -> bool
Whether the peer has signalled it will not accept further requests
(GOAWAY received). When true, callers should reconnect rather
than reuse this connection.
Source§impl H2AsyncConn
impl H2AsyncConn
Sourcepub async fn connect(addr: SocketAddr, host: &str) -> Result<Self, HttpError>
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.
Sourcepub async fn connect_with_timeout(
addr: SocketAddr,
host: &str,
timeout_ms: u64,
) -> Result<Self, HttpError>
pub async fn connect_with_timeout( addr: SocketAddr, host: &str, timeout_ms: u64, ) -> Result<Self, HttpError>
Connect with a timeout (milliseconds).
Sourcepub async fn from_conn(conn: ConnCtx) -> Result<Self, HttpError>
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.
pub fn conn(&self) -> ConnCtx
Sourcepub fn pending_count(&self) -> usize
pub fn pending_count(&self) -> usize
Number of in-flight streams.
Sourcepub async fn send_request(
&mut self,
method: &str,
path: &str,
host: &str,
extra_headers: &[(&str, &str)],
body: Option<&[u8]>,
) -> Result<Response, HttpError>
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.
Sourcepub fn fire_request(
&mut self,
method: &str,
path: &str,
host: &str,
extra_headers: &[(&str, &str)],
body: Option<&[u8]>,
) -> Result<u32, HttpError>
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.
Sourcepub async fn recv(&mut self) -> Result<(u32, Response), HttpError>
pub async fn recv(&mut self) -> Result<(u32, Response), HttpError>
Pump until any stream completes. Returns (stream_id, Response),
or surfaces a per-stream HttpError for that stream.
Sourcepub async fn recv_stream(
&mut self,
stream_id: u32,
) -> Result<Response, HttpError>
pub async fn recv_stream( &mut self, stream_id: u32, ) -> Result<Response, HttpError>
Pump until a specific stream completes.
Sourcepub async fn send_request_streaming(
&mut self,
method: &str,
path: &str,
host: &str,
extra_headers: &[(&str, &str)],
body: Option<&[u8]>,
) -> Result<H2StreamingResponse<'_>, HttpError>
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.