pub struct Connection<Io> { /* private fields */ }h2 only.Expand description
An HTTP/2 server connection.
Io must be a raw transport: the preface is read byte-exact, so
any buffering layer between the socket and this type breaks the
initial read.
Implementations§
Source§impl<Io> Connection<Io>
impl<Io> Connection<Io>
Sourcepub fn new(io: Io, preface_timeout: Option<Duration>) -> Connection<Io>
pub fn new(io: Io, preface_timeout: Option<Duration>) -> Connection<Io>
Creates a connection over io.
Sourcepub fn with_shutdown(self, token: CancellationToken) -> Self
pub fn with_shutdown(self, token: CancellationToken) -> Self
Arms a CancellationToken that triggers a graceful shutdown
when cancelled: the connection sends GOAWAY, stops opening new
streams, drains in-flight responses, then closes (RFC 9113
Section 6.8).
Sourcepub async fn drive(self) -> Result<()>
pub async fn drive(self) -> Result<()>
Drives a connection that never serves requests: the preface handshake, SETTINGS/PING maintenance and error handling, but no request dispatch (any request stream is refused).
Equivalent to Connection::handle with a handler that never
completes; kept for tests and for callers that only want the
connection-level behavior.
Sourcepub async fn handle<F, Fut, ResB, ResBE, ResE>(
self,
request_fn: Arc<F>,
options: ConnectionOptions,
) -> Result<()>
pub async fn handle<F, Fut, ResB, ResBE, ResE>( self, request_fn: Arc<F>, options: ConnectionOptions, ) -> Result<()>
Serves requests to completion: peer EOF, GOAWAY received, preface timeout, or an unrecoverable protocol error.
Each decoded request starts a stream task running request_fn
(a clone-free sequential borrow: the loop owns the closure for
the connection’s lifetime). Responses are framed onto the wire
by this task as the stream tasks emit them.