Name Description Size Coverage
cache.rs A cache of services The cache is a single list of cached services, bundled with a `MakeService`. Calling the cache returns either an existing service, or makes a new one. The returned `impl Service` can be used to send requests, and when dropped, it will try to be returned back to the cache. 15126 -
map.rs Map pool utilities The map isn't a typical `Service`, but rather stand-alone type that can map requests to a key and service factory. This is because the service is more of a router, and cannot determine which inner service to check for backpressure since it's not know until the request is made. The map implementation allows customization of extracting a key, and how to construct a MakeService for that key. # Example ```rust,ignore # async fn run() { # use hyper_util::client::pool; # let req = http::Request::new(()); # let some_http1_connector = || { # tower::service::service_fn(|_req| async { Ok::<_, &'static str>(()) }) # }; let mut map = pool::map::Map::builder() .keys(|uri| (uri.scheme().clone(), uri.authority().clone())) .values(|_uri| { some_http1_connector() }) .build(); let resp = map.service(req.uri()).call(req).await; # } ``` 5685 -
mod.rs Composable pool services This module contains various concepts of a connection pool separated into their own concerns. This allows for users to compose the layers, along with any other layers, when constructing custom connection pools. 323 -
negotiate.rs Negotiate a pool of services The negotiate pool allows for a service that can decide between two service types based on an intermediate return value. It differs from typical routing since it doesn't depend on the request, but the response. The original use case is support ALPN upgrades to HTTP/2, with a fallback to HTTP/1. # Example ```rust,ignore # async fn run() -> Result<(), Box<dyn std::error::Error>> { # struct Conn; # impl Conn { fn negotiated_protocol(&self) -> &[u8] { b"h2" } } # let some_tls_connector = tower::service::service_fn(|_| async move { # Ok::<_, std::convert::Infallible>(Conn) # }); # let http1_layer = tower::layer::layer_fn(|s| s); # let http2_layer = tower::layer::layer_fn(|s| s); let mut pool = hyper_util::client::pool::negotiate::builder() .connect(some_tls_connector) .inspect(|c| c.negotiated_protocol() == b"h2") .fallback(http1_layer) .upgrade(http2_layer) .build(); // connect let mut svc = pool.call(http::Uri::from_static("https://hyper.rs")).await?; svc.ready().await; // http1 or http2 is now set up # let some_http_req = http::Request::new(()); let resp = svc.call(some_http_req).await?; # Ok(()) # } ``` 19309 -
singleton.rs Singleton pools This ensures that only one active connection is made. The singleton pool wraps a `MakeService<T, Req>` so that it only produces a single `Service<Req>`. It bundles all concurrent calls to it, so that only one connection is made. All calls to the singleton will return a clone of the inner service once established. This fits the HTTP/2 case well. ## Example ```rust,ignore let mut pool = Singleton::new(some_make_svc); let svc1 = pool.call(some_dst).await?; let svc2 = pool.call(some_dst).await?; // svc1 == svc2 ``` 16059 -