Skip to main content

Config

Struct Config 

Source
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: Duration

Whole-request timeout: connect, send and body read.

§redirects: FollowRedirects

Whether to follow redirects, and how many hops to allow.

§insecure: bool

Skip 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.

§cookie_jar: bool

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

Source

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.

Source

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.

Source

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 Clone for Config

Source§

fn clone(&self) -> Config

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Config

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Config

Source§

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).

Source§

impl Eq for Config

Source§

impl PartialEq for Config

Source§

fn eq(&self, other: &Config) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Config

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more