Skip to main content

ConfigFile

Struct ConfigFile 

Source
pub struct ConfigFile {
    pub headers: BTreeMap<String, String>,
    pub timeout_seconds: Option<u64>,
    pub follow_redirects: Option<FollowRedirects>,
    pub insecure: Option<bool>,
    pub proxy: Option<String>,
    pub client_cert: Option<ClientCertFile>,
    pub cookie_jar: Option<bool>,
}
Expand description

One config file, exactly as it appears on disk.

Every field is optional, and stays optional after parsing, because that optionality is the merge information: None means “this file said nothing about it”, which is what lets a project file override one key without silently resetting the others. The all-decided resolved form is Config.

headers:                 # merged into every request; the request wins ties
  User-Agent: sendra
  Accept: application/json
timeout_seconds: 10      # whole-request timeout, connect through body read

Unknown keys are rejected, matching Request and Collection: a typo in a config key would otherwise be a setting that silently never applies, which is worse here than in a request file — there is no response in which to notice it.

Fields§

§headers: BTreeMap<String, String>

Headers merged into every request. A header set by the request itself wins.

§timeout_seconds: Option<u64>

Whole-request timeout in seconds.

Seconds as an integer, with the unit in the key name, rather than a duration string like "30s": there is then nothing to parse, no way to read the unit wrong, and no syntax to stay compatible with if a richer duration format is wanted later.

§follow_redirects: Option<FollowRedirects>

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

§insecure: Option<bool>

Skip TLS certificate verification for every request this run sends — the config-file form of --insecure.

A real security-relevant setting, not a convenience default: it exists for a self-signed or otherwise untrusted endpoint (an internal staging host, say) where there is no CA chain to verify against, and it disables the one thing standing between a request and a man-in-the-middle. See build_client for where it is applied, and the CLI’s --insecure doc comment for the warning printed whenever this resolves to true, from either source.

§proxy: Option<String>

Route every request through this HTTP proxy — the config-file form of --proxy.

proxy: http://proxy.example.com:8080
proxy: http://user:pass@proxy.example.com:8080   # credentials in the URL

A plain URL string rather than a structured {host, port, user, pass} object: reqwest, which actually builds the proxying connector, already reads user/pass credentials straight out of the URL’s userinfo, so a second, Sendra-specific way to spell the same thing would be a second thing to keep in sync with reqwest’s own parsing rather than a real capability. Not validated here — an unparsable URL surfaces as a SendraError::Client when build_client tries to build the client, the same place every other client-construction failure is reported.

Setting this — from either the config file or --proxy — takes over proxying for the run entirely: the standard HTTP_PROXY/ HTTPS_PROXY/NO_PROXY environment variables Sendra otherwise respects by default (matching curl, and every other common HTTP tool) are not consulted once an explicit proxy is configured. None — no proxy: key and no --proxy — is the plain “follow the environment, same as everyone else” default.

§client_cert: Option<ClientCertFile>

Present a client certificate for mutual TLS — the config-file form of --client-cert/--client-key.

client_cert:
  cert: ./client.pem
  key: ./client-key.pem

PEM only, not PKCS#12: Sendra’s reqwest is built against rustls-tls alone (no native-tls), and reqwest::Identity’s PKCS#12 and split-PEM constructors both require native-tls — pulling that in would mean shipping a second TLS backend just to accept one more input format. Identity::from_pem (the one constructor rustls-tls does expose) wants a single buffer containing both the certificate and its private key, so build_client reads both files and concatenates them in memory before handing that buffer to reqwest.

cert/key are resolved relative to this config file’s own directory, not the current working directory — the same rule body_file: uses for the request file that names it, and for the same reason: a project config checked into version control should mean the same file on every machine it runs on, not whichever directory the command happened to be typed from. See [resolve_client_cert_paths]. --client-cert/--client-key, by contrast, resolve relative to the working directory, matching how every other CLI-supplied path (--junit, say) is read.

Both halves are required together — a cert with no key, or a key with no cert, is refused as SendraError::ClientCertIncomplete when build_client tries to use it, the same place every other client-construction failure is reported. That check runs after CLI overrides are folded in, so a config cert: paired with a --client-key override (or vice versa) is a valid combination, not an error — only ending up with just one side, from any mix of sources, is refused.

§cookie_jar: Option<bool>

Persist cookies received via Set-Cookie and send them back automatically on later requests to the same host — the config-file form of --cookie-jar.

Opt-in, off by default, deliberately matching curl: curl does not carry cookies between requests unless you pass -c/-b yourself, and Sendra follows the same convention rather than defaulting to “on” because it would be convenient for the login-flow case this exists for. See build_client for where it is applied.

In-memory only, for the duration of one invocation — nothing is written to disk, and nothing survives between separate sendra run/ sendra test invocations, the same “no persistence across invocations” rule crate::capture already follows.

Implementations§

Source§

impl ConfigFile

Source

pub fn from_yaml_str(yaml: &str) -> Result<Self, SendraError>

Parse a config file from a YAML string.

Source

pub fn from_path(path: impl AsRef<Path>) -> Result<Self, SendraError>

Read and parse a config file from disk.

Trait Implementations§

Source§

impl Clone for ConfigFile

Source§

fn clone(&self) -> ConfigFile

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 ConfigFile

Source§

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

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

impl Default for ConfigFile

Source§

fn default() -> ConfigFile

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for ConfigFile

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for ConfigFile

Source§

impl PartialEq for ConfigFile

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl Serialize for ConfigFile

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for ConfigFile

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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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