diff --git a/postwoman.toml b/postwoman.toml index 7837f96..28dc601 100644 --- a/postwoman.toml +++ b/postwoman.toml @@ -1,5 +1,7 @@ [client] # HTTP client configuration 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 PW_TOKEN = "set-me-as-and-environment-variable!" diff --git a/src/model/client.rs b/src/model/client.rs index f6e8f0f..dfcf4ca 100644 --- a/src/model/client.rs +++ b/src/model/client.rs @@ -3,4 +3,10 @@ pub struct ClientConfig { /// user agent for requests, defaults to 'postwoman/' pub user_agent: Option, + /// max total duration of each request, in seconds. defaults to 30 + pub timeout: Option, + /// max number of redirects to allow, defaults to 0 + pub redirects: Option, + /// accept invalid SSL certificates, defaults to false (be careful: this is dangerous!) + pub accept_invalid_certs: Option, } diff --git a/src/model/endpoint.rs b/src/model/endpoint.rs index 50d3a4d..6cc3051 100644 --- a/src/model/endpoint.rs +++ b/src/model/endpoint.rs @@ -106,6 +106,9 @@ impl EndpointConfig { let client = reqwest::Client::builder() .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()?; let res = client