pub struct Config {
pub headers: BTreeMap<String, String>,
pub timeout: Duration,
pub redirects: FollowRedirects,
pub insecure: bool,
pub proxy: Option<String>,
pub client_cert: Option<PathBuf>,
pub client_key: Option<PathBuf>,
pub cookie_jar: bool,
pub sources: Vec<PathBuf>,
}Expand description
Resolved, ready-to-use configuration: every field decided, no Options
left. Built by merging whichever config files exist over the hardcoded
defaults, so the rest of the crate never has to ask whether a file was
found.
Fields§
§headers: BTreeMap<String, String>Headers added to every request that does not set them itself.
timeout: DurationWhole-request timeout: connect, send and body read.
redirects: FollowRedirectsWhether to follow redirects, and how many hops to allow.
insecure: boolSkip TLS certificate verification. See ConfigFile::insecure.
proxy: Option<String>Route every request through this HTTP proxy, or None to follow the
standard proxy environment variables. See ConfigFile::proxy.
client_cert: Option<PathBuf>Client certificate file for mutual TLS, or None to present none. See
ConfigFile::client_cert. Always set together with client_key, or
not at all — build_client refuses a Config
where exactly one of the two is Some.
client_key: Option<PathBuf>Private key matching client_cert. See ConfigFile::client_cert.
Persist and resend cookies automatically for this run. See
ConfigFile::cookie_jar.
sources: Vec<PathBuf>The config files this was built from, in the order they were merged (global first). Empty when no config file was found anywhere.
Implementations§
Source§impl Config
impl Config
Sourcepub fn resolve() -> Result<Self, SendraError>
pub fn resolve() -> Result<Self, SendraError>
Resolve configuration for a run starting from the current directory.
The walk-up starts at the working directory rather than at the request
file’s directory, so which config applies depends on where you are, the
same way git status does. sendra run ../other/req.yaml uses this
project’s defaults, which is the reading that stays predictable when a
path is typed by hand.
Sourcepub fn resolve_from(
start_dir: &Path,
global_config: Option<&Path>,
) -> Result<Self, SendraError>
pub fn resolve_from( start_dir: &Path, global_config: Option<&Path>, ) -> Result<Self, SendraError>
The resolution itself, with both starting points passed in.
Config::resolve is this with the real working directory and the real
global path. Taking them as arguments keeps the merge logic testable
against temporary directories without setting process-global environment
variables or changing the working directory, neither of which tests
running in parallel threads can do safely.
global_config is the config file, not its directory, and neither
path needs to exist: a missing file is not an error, only an unreadable
or unparseable one is.
Sourcepub fn apply(&self, request: &Request) -> Request
pub fn apply(&self, request: &Request) -> Request
Apply this config to request, returning the request as it will be
sent.
Only the headers show up on a Request; the timeout is applied to the
client build_client makes for the run. A config header is
added only when the request does not already set one with that name,
compared case-insensitively, because HTTP header names are
case-insensitive: a config User-Agent and a request user-agent are
the same header, and adding both would give the request two entries
under a name it never repeated itself, rather than to the stated rule.
This is still a suppression, not a merge: Request.headers allowing a
name to repeat is about what the request is allowed to say, not an
invitation for a config default to duplicate something the request
already set. A repeated header only happens when the request file (or
a script) asks for it.
Trait Implementations§
Source§impl Default for Config
impl Default for Config
Source§fn default() -> Self
fn default() -> Self
What Sendra does with no config file anywhere: no extra headers,
DEFAULT_TIMEOUT, redirects followed up to
DEFAULT_MAX_REDIRECTS — reqwest’s own default — TLS verification
on, and no explicit proxy (so the standard proxy environment
variables apply, same as any other HTTP tool).
impl Eq for Config
impl StructuralPartialEq for Config
Auto Trait Implementations§
impl Freeze for Config
impl RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnsafeUnpin for Config
impl UnwindSafe for Config
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.