pub struct Client<'scope> { /* private fields */ }Expand description
Durable remote-server interface. Clones share connection admission and
supervision. call submits pull bodies; open lends direct HTTP/1 directions.
Neither operation chooses a process-global scheduler.
'scope is the scheduler borrow, and it also bounds the request bodies and interim observers that calls queue for the driver. The client and its driver share that queue, so neither can outlive the scheduler. The type is invariant over 'scope: shortening it would let a call queue a body that borrows shorter-lived data for a driver that keeps running after the data is gone.
To keep a client for longer, give the scheduler a longer life. Create it at the application root and store the client in a struct generic over 'scope, or use a scheduler that lives for 'static, whose Client<'static> can be stored anywhere.
Implementations§
Source§impl<'scope> Client<'scope>
impl<'scope> Client<'scope>
Sourcepub async fn open(
&self,
method: Method,
path: impl Into<Path>,
cancellation: &Cancellation,
) -> Result<WritableRequest<'scope>, Error>
pub async fn open( &self, method: Method, path: impl Into<Path>, cancellation: &Cancellation, ) -> Result<WritableRequest<'scope>, Error>
Acquire a connection and send metadata for an imperative upload. Unknown length uses chunked HTTP/1.1 framing. Drive the client driver concurrently for establishment, TLS progress and cleanup. Established plaintext requests run entirely in the calling future.
Sourcepub async fn open_request(
&self,
metadata: RequestMetadata,
cancellation: &Cancellation,
) -> Result<WritableRequest<'scope>, Error>
pub async fn open_request( &self, metadata: RequestMetadata, cancellation: &Cancellation, ) -> Result<WritableRequest<'scope>, Error>
Open with explicit fields, authority and optional content length. Managed tunnels/upgrades and automatic request replay remain unsupported.
Sourcepub async fn open_request_with_interim<I: InterimHandler + 'scope>(
&self,
metadata: RequestMetadata,
interim: I,
cancellation: &Cancellation,
) -> Result<WritableRequest<'scope>, Error>
pub async fn open_request_with_interim<I: InterimHandler + 'scope>( &self, metadata: RequestMetadata, interim: I, cancellation: &Cancellation, ) -> Result<WritableRequest<'scope>, Error>
Observe informational responses while the pending response is polled. Opening and writing alone do not read input or wait for 100 Continue.
Source§impl<'scope> Client<'scope>
impl<'scope> Client<'scope>
Sourcepub fn new<S>(
scheduler: &'scope S,
endpoint: Endpoint,
options: Options,
) -> Result<(Self, Driver<'scope>), Error>where
S: SocketOpen + SocketConnect + SocketClose + SocketSetOption<TcpNoDelay> + SocketStreamReading + SocketStreamWriting + 'scope,
S::Socket: 'static,
pub fn new<S>(
scheduler: &'scope S,
endpoint: Endpoint,
options: Options,
) -> Result<(Self, Driver<'scope>), Error>where
S: SocketOpen + SocketConnect + SocketClose + SocketSetOption<TcpNoDelay> + SocketStreamReading + SocketStreamWriting + 'scope,
S::Socket: 'static,
Construct without dialing. Poll the returned driver concurrently with
calls. Bodies may borrow for the driver’s scope; spawning requires owned
Send + 'static captures, as with any scheduler task.
pub fn endpoint(&self) -> &Endpoint
pub fn pool_stats(&self) -> Stats
Sourcepub fn begin_close(&self)
pub fn begin_close(&self)
Reject new submissions, finish accepted calls, then retire connections. Cancel the driver’s lifetime signal to force active calls down.
Sourcepub async fn call<B>(
&self,
request: Request<B>,
cancellation: &Cancellation,
) -> Result<Response<ResponseBody>, Error>
pub async fn call<B>( &self, request: Request<B>, cancellation: &Cancellation, ) -> Result<Response<ResponseBody>, Error>
Return final response metadata promptly. The driver continues upload independently of response consumption. A reused idle connection is checked before any request bytes are sent, and one the server closed is replaced. No automatic retries occur.
Sourcepub async fn call_with_interim<B, I>(
&self,
request: Request<B>,
interim: I,
cancellation: &Cancellation,
) -> Result<Response<ResponseBody>, Error>
pub async fn call_with_interim<B, I>( &self, request: Request<B>, interim: I, cancellation: &Cancellation, ) -> Result<Response<ResponseBody>, Error>
Observe informational responses in order, without accumulating a log.