pub fn static_headers<I, N, V>(
headers: I,
slot: &CredentialSlot,
) -> Result<Headers>Expand description
The headers a provider sends with every request: User-Agent:
DEFAULT_USER_AGENT, then headers (a builder’s
header(name, value) settings, in order), each replacing the headers of
the same name before it, so header("user-agent", ..) replaces the
default. Set them on each request with
HttpRequest::with_headers.
These headers belong to one provider: a gateway’s routing header, a
tenant tag, a beta flag. Credentials do not: they are refused here, as
HttpRequest::apply_options refuses
them in a request’s options, so a key always goes through the builder’s
key setting or a per-request Credential, where it
is scoped and redacted.
use allama_http::{CredentialPlacement, CredentialSlot, DEFAULT_USER_AGENT, config};
let slot = CredentialSlot::new("acme", CredentialPlacement::Bearer);
let headers = config::static_headers([("x-route", "eu")], &slot)?;
assert_eq!(headers.get("user-agent"), Some(DEFAULT_USER_AGENT));
assert_eq!(headers.get("x-route"), Some("eu"));
let err = config::static_headers([("x-api-key", "sk-acme")], &slot).unwrap_err();
assert!(matches!(err, allama::Error::Configuration { .. }));
assert!(!err.to_string().contains("sk-acme"));§Errors
An authored allama::Error::Configuration naming the header, never
its value, when the name is not a valid header name, the value holds a
character a header cannot carry (anything but visible ASCII, spaces and
tabs), or the header carries a credential: it is on the exact credential
list (is_credential_header), or slot writes or replaces it.