Handle some basic options in WebClient::default

This commit is contained in:
2022-06-02 08:15:40 +00:00
committed by GitHub
parent b9704e16ca
commit 36658a3753
3 changed files with 11 additions and 8 deletions

View File

@@ -99,7 +99,7 @@ impl Downloader<File> {
None => { None }
};
Ok(DownloaderResult::Ok(Self {
client: Arc::new(WebClient::new()),
client: Arc::new(WebClient::default()),
pd: Arc::new(pd_file),
url: Arc::new(url.into_url()?),
headers: Arc::new(h),

View File

@@ -30,7 +30,7 @@ pub struct PixivWebClient {
impl PixivWebClient {
pub fn new() -> Self {
Self {
client: WebClient::new(),
client: WebClient::default(),
inited: Arc::new(AtomicBool::new(false)),
data: RwLock::new(None),
params: RwLock::new(None),
@@ -88,12 +88,6 @@ impl PixivWebClient {
self.client.set_header("Accept-Language", "ja");
self.params.get_mut().replace(json::object! { "lang": "ja" });
}
self.client.set_verbose(helper.verbose());
let retry = helper.retry();
if retry.is_some() {
self.client.set_retry(retry.unwrap());
}
self.client.get_retry_interval_as_mut().replace(helper.retry_interval());
self.inited.store(true, Ordering::Relaxed);
true
}

View File

@@ -103,6 +103,8 @@ pub struct WebClient {
impl WebClient {
/// Create a new instance of client
///
/// This function will not handle any basic options, please use [Self::default()] instead.
pub fn new() -> Self {
Self {
client: Client::new(),
@@ -620,6 +622,13 @@ impl WebClient {
impl Default for WebClient {
fn default() -> Self {
let c = Self::new();
let opt = get_helper();
c.set_verbose(opt.verbose());
match opt.retry() {
Some(retry) => { c.set_retry(retry) }
None => {}
}
c.get_retry_interval_as_mut().replace(opt.retry_interval());
c
}
}