pub trait HeaderProvider: Send + Sync {
// Required method
fn headers<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<HeaderMap, Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
}Expand description
Builds the headers for a dial, asked on every dial rather than once. A client reconnects on its own for as long as it runs, which is longer than a credential that expires lives, and a reconnect carrying the token the first dial used would be turned down for good.
What it returns is laid over the headers already set on the builder, so an Origin or a
token given with ClientBuilder::header survives. An error turns down that dial, and
the client tries again on its backoff.
Any Fn() -> Future<Output = Result<HeaderMap, Error>> is a provider, so the quick form
is a closure:
use actioncable::{Client, Error};
use http::{HeaderMap, HeaderValue};
let client = Client::builder("wss://example.com/cable")
.header_provider(|| async {
let mut headers = HeaderMap::new();
headers.insert("Authorization", HeaderValue::from_static("Bearer token"));
Ok(headers)
})
.build()?;A credentials type that already knows how to refresh itself implements the trait directly.
Required Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl<T: HeaderProvider + ?Sized> HeaderProvider for Arc<T>
A shared provider answers like the one it shares, so an application can keep one — and
the credentials behind it — and hand it to every client it builds.
impl<T: HeaderProvider + ?Sized> HeaderProvider for Arc<T>
A shared provider answers like the one it shares, so an application can keep one — and the credentials behind it — and hand it to every client it builds.