Expand description
Checking a provider builder’s configuration: base URLs, secrets, and
the headers a provider sends with every request, and how a URL shows in
Debug output.
Every bundled HTTP provider’s build() (and from_env()) runs these
checks, so a malformed value fails there, with an
authored allama::Error::Configuration
that names the setting or the environment variable, instead of failing
every request later as an invalid request. The messages never quote the
value: a base URL can carry a password, and a key is a secret. Provider
crates of your own use them the same way:
use allama_http::config;
// A key read from a Kubernetes secret file keeps its trailing newline.
assert_eq!(config::secret("ACME_API_KEY", "sk-acme\n")?, "sk-acme");
assert_eq!(
config::base_url("ACME_BASE_URL", " https://gw.example/v1/ ")?,
"https://gw.example/v1"
);
let err = config::base_url("ACME_BASE_URL", "localhost:8080/v1").unwrap_err();
assert!(matches!(err, allama::Error::Configuration { .. }));
assert!(err.to_string().contains("ACME_BASE_URL"));Plain http:// stays allowed: a local or LAN server (Ollama, vLLM) is a
common target. Only send keys over it to hosts you trust on that network.
Functions§
- base_
url - Check and normalize a base URL from a builder setting or environment
variable named
setting: surrounding whitespace and trailing slashes are removed, and the URL must be an absolutehttporhttpsURL with a host, no whitespace or control characters, and no query or fragment (requests append their path to it). - redact_
url urlasDebugoutput and error messages may show it: without a user name and password, query or fragment, which can carry credentials.- secret
- Check a secret (an API key or token) from a builder setting or
environment variable named
setting, and return it without surrounding whitespace: a key read from a file or a Kubernetes secret often ends in a newline, which no HTTP header can carry. - static_
headers - The headers a provider sends with every request:
User-Agent:DEFAULT_USER_AGENT, thenheaders(a builder’sheader(name, value)settings, in order), each replacing the headers of the same name before it, soheader("user-agent", ..)replaces the default. Set them on each request withHttpRequest::with_headers.