Module negotiate

Module negotiate 

Source
Expand description

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

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 resp = svc.call(some_http_req).await?;

Functions§

builder
Start a builder to construct a Negotiate pool.