Extract client creation to a single place

This commit is contained in:
Jake Howard
2021-04-06 21:04:37 +01:00
parent b268c3dd1c
commit 155109dea1
5 changed files with 33 additions and 23 deletions

View File

@@ -478,7 +478,6 @@ pub fn retry<F, T, E>(func: F, max_tries: u32) -> Result<T, E>
where
F: Fn() -> Result<T, E>,
{
use std::{thread::sleep, time::Duration};
let mut tries = 0;
loop {
@@ -497,12 +496,13 @@ where
}
}
use std::{thread::sleep, time::Duration};
pub fn retry_db<F, T, E>(func: F, max_tries: u32) -> Result<T, E>
where
F: Fn() -> Result<T, E>,
E: std::error::Error,
{
use std::{thread::sleep, time::Duration};
let mut tries = 0;
loop {
@@ -522,3 +522,18 @@ where
}
}
}
use reqwest::{blocking::{Client, ClientBuilder}, header};
pub fn get_reqwest_client() -> Client {
get_reqwest_client_builder().build().expect("Failed to build client")
}
pub fn get_reqwest_client_builder() -> ClientBuilder {
let mut headers = header::HeaderMap::new();
headers.insert(header::USER_AGENT, header::HeaderValue::from_static("Bitwarden_RS"));
Client::builder()
.default_headers(headers)
.timeout(Duration::from_secs(10))
}