feat: more client options
This commit is contained in:
parent
ce0d725c43
commit
2695c850bb
3 changed files with 11 additions and 0 deletions
|
@ -1,5 +1,7 @@
|
||||||
[client] # HTTP client configuration
|
[client] # HTTP client configuration
|
||||||
user_agent = "postwoman@sample/0.2.0"
|
user_agent = "postwoman@sample/0.2.0"
|
||||||
|
timeout = 60 # max time for each request to complete, in seconds
|
||||||
|
redirects = 5 # allow up to five redirects, defaults to none
|
||||||
|
|
||||||
[env] # these will be replaced in routes options. environment vars overrule these
|
[env] # these will be replaced in routes options. environment vars overrule these
|
||||||
PW_TOKEN = "set-me-as-and-environment-variable!"
|
PW_TOKEN = "set-me-as-and-environment-variable!"
|
||||||
|
|
|
@ -3,4 +3,10 @@
|
||||||
pub struct ClientConfig {
|
pub struct ClientConfig {
|
||||||
/// user agent for requests, defaults to 'postwoman/<version>'
|
/// user agent for requests, defaults to 'postwoman/<version>'
|
||||||
pub user_agent: Option<String>,
|
pub user_agent: Option<String>,
|
||||||
|
/// max total duration of each request, in seconds. defaults to 30
|
||||||
|
pub timeout: Option<u64>,
|
||||||
|
/// max number of redirects to allow, defaults to 0
|
||||||
|
pub redirects: Option<usize>,
|
||||||
|
/// accept invalid SSL certificates, defaults to false (be careful: this is dangerous!)
|
||||||
|
pub accept_invalid_certs: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,6 +106,9 @@ impl EndpointConfig {
|
||||||
|
|
||||||
let client = reqwest::Client::builder()
|
let client = reqwest::Client::builder()
|
||||||
.user_agent(opts.user_agent.as_deref().unwrap_or(APP_USER_AGENT))
|
.user_agent(opts.user_agent.as_deref().unwrap_or(APP_USER_AGENT))
|
||||||
|
.timeout(std::time::Duration::from_secs(opts.timeout.unwrap_or(30)))
|
||||||
|
.redirect(opts.redirects.map(reqwest::redirect::Policy::limited).unwrap_or(reqwest::redirect::Policy::none()))
|
||||||
|
.danger_accept_invalid_certs(opts.accept_invalid_certs.unwrap_or(false))
|
||||||
.build()?;
|
.build()?;
|
||||||
|
|
||||||
let res = client
|
let res = client
|
||||||
|
|
Loading…
Reference in a new issue