Use Duration for timeouts.
parent
953959f344
commit
be63232d4c
|
@ -9,8 +9,6 @@
|
||||||
* except according to those terms.
|
* except according to those terms.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use std::time::Duration;
|
|
||||||
|
|
||||||
use reqwest::header::CONTENT_TYPE;
|
use reqwest::header::CONTENT_TYPE;
|
||||||
|
|
||||||
use crate::{client::Client, core::session::URLPart};
|
use crate::{client::Client, core::session::URLPart};
|
||||||
|
@ -55,7 +53,7 @@ impl Client {
|
||||||
|
|
||||||
Client::handle_error(
|
Client::handle_error(
|
||||||
HttpClient::builder()
|
HttpClient::builder()
|
||||||
.timeout(Duration::from_millis(self.timeout()))
|
.timeout(self.timeout())
|
||||||
.danger_accept_invalid_certs(self.accept_invalid_certs)
|
.danger_accept_invalid_certs(self.accept_invalid_certs)
|
||||||
.redirect(self.redirect_policy())
|
.redirect(self.redirect_policy())
|
||||||
.default_headers(headers)
|
.default_headers(headers)
|
||||||
|
|
|
@ -9,8 +9,6 @@
|
||||||
* except according to those terms.
|
* except according to those terms.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use std::time::Duration;
|
|
||||||
|
|
||||||
use reqwest::header::CONTENT_TYPE;
|
use reqwest::header::CONTENT_TYPE;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
@ -64,7 +62,7 @@ impl Client {
|
||||||
serde_json::from_slice::<UploadResponse>(
|
serde_json::from_slice::<UploadResponse>(
|
||||||
&Client::handle_error(
|
&Client::handle_error(
|
||||||
HttpClient::builder()
|
HttpClient::builder()
|
||||||
.timeout(Duration::from_millis(self.timeout()))
|
.timeout(self.timeout())
|
||||||
.danger_accept_invalid_certs(self.accept_invalid_certs)
|
.danger_accept_invalid_certs(self.accept_invalid_certs)
|
||||||
.redirect(self.redirect_policy())
|
.redirect(self.redirect_policy())
|
||||||
.default_headers(self.headers().clone())
|
.default_headers(self.headers().clone())
|
||||||
|
|
|
@ -63,7 +63,7 @@ pub struct Client {
|
||||||
|
|
||||||
headers: header::HeaderMap,
|
headers: header::HeaderMap,
|
||||||
default_account_id: String,
|
default_account_id: String,
|
||||||
timeout: u64,
|
timeout: Duration,
|
||||||
pub(crate) accept_invalid_certs: bool,
|
pub(crate) accept_invalid_certs: bool,
|
||||||
|
|
||||||
#[cfg(feature = "websockets")]
|
#[cfg(feature = "websockets")]
|
||||||
|
@ -77,7 +77,7 @@ pub struct ClientBuilder {
|
||||||
trusted_hosts: AHashSet<String>,
|
trusted_hosts: AHashSet<String>,
|
||||||
forwarded_for: Option<String>,
|
forwarded_for: Option<String>,
|
||||||
accept_invalid_certs: bool,
|
accept_invalid_certs: bool,
|
||||||
timeout: u64,
|
timeout: Duration,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for ClientBuilder {
|
impl Default for ClientBuilder {
|
||||||
|
@ -91,7 +91,7 @@ impl ClientBuilder {
|
||||||
Self {
|
Self {
|
||||||
credentials: None,
|
credentials: None,
|
||||||
trusted_hosts: AHashSet::new(),
|
trusted_hosts: AHashSet::new(),
|
||||||
timeout: DEFAULT_TIMEOUT_MS,
|
timeout: Duration::from_millis(DEFAULT_TIMEOUT_MS),
|
||||||
forwarded_for: None,
|
forwarded_for: None,
|
||||||
accept_invalid_certs: false,
|
accept_invalid_certs: false,
|
||||||
}
|
}
|
||||||
|
@ -102,7 +102,7 @@ impl ClientBuilder {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn timeout(mut self, timeout: u64) -> Self {
|
pub fn timeout(mut self, timeout: Duration) -> Self {
|
||||||
self.timeout = timeout;
|
self.timeout = timeout;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -157,7 +157,7 @@ impl ClientBuilder {
|
||||||
let session: Session = serde_json::from_slice(
|
let session: Session = serde_json::from_slice(
|
||||||
&Client::handle_error(
|
&Client::handle_error(
|
||||||
HttpClient::builder()
|
HttpClient::builder()
|
||||||
.timeout(Duration::from_millis(self.timeout))
|
.timeout(self.timeout)
|
||||||
.danger_accept_invalid_certs(self.accept_invalid_certs)
|
.danger_accept_invalid_certs(self.accept_invalid_certs)
|
||||||
.redirect(redirect::Policy::custom(move |attempt| {
|
.redirect(redirect::Policy::custom(move |attempt| {
|
||||||
if attempt.previous().len() > 5 {
|
if attempt.previous().len() > 5 {
|
||||||
|
@ -223,7 +223,7 @@ impl Client {
|
||||||
ClientBuilder::new()
|
ClientBuilder::new()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_timeout(&mut self, timeout: u64) -> &mut Self {
|
pub fn set_timeout(&mut self, timeout: Duration) -> &mut Self {
|
||||||
self.timeout = timeout;
|
self.timeout = timeout;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -236,7 +236,7 @@ impl Client {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn timeout(&self) -> u64 {
|
pub fn timeout(&self) -> Duration {
|
||||||
self.timeout
|
self.timeout
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -283,7 +283,7 @@ impl Client {
|
||||||
HttpClient::builder()
|
HttpClient::builder()
|
||||||
.redirect(self.redirect_policy())
|
.redirect(self.redirect_policy())
|
||||||
.danger_accept_invalid_certs(self.accept_invalid_certs)
|
.danger_accept_invalid_certs(self.accept_invalid_certs)
|
||||||
.timeout(Duration::from_millis(self.timeout))
|
.timeout(self.timeout)
|
||||||
.default_headers(self.headers.clone())
|
.default_headers(self.headers.clone())
|
||||||
.build()?
|
.build()?
|
||||||
.post(&self.api_url)
|
.post(&self.api_url)
|
||||||
|
|
|
@ -9,8 +9,6 @@
|
||||||
* except according to those terms.
|
* except according to those terms.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use std::time::Duration;
|
|
||||||
|
|
||||||
use crate::{client::Client, core::session::URLPart, event_source::parser::EventParser, TypeState};
|
use crate::{client::Client, core::session::URLPart, event_source::parser::EventParser, TypeState};
|
||||||
use futures_util::{Stream, StreamExt};
|
use futures_util::{Stream, StreamExt};
|
||||||
use reqwest::header::{HeaderValue, ACCEPT, CONTENT_TYPE};
|
use reqwest::header::{HeaderValue, ACCEPT, CONTENT_TYPE};
|
||||||
|
@ -73,7 +71,7 @@ impl Client {
|
||||||
|
|
||||||
let mut stream = Client::handle_error(
|
let mut stream = Client::handle_error(
|
||||||
reqwest::Client::builder()
|
reqwest::Client::builder()
|
||||||
.connect_timeout(Duration::from_millis(self.timeout()))
|
.connect_timeout(self.timeout())
|
||||||
.danger_accept_invalid_certs(self.accept_invalid_certs)
|
.danger_accept_invalid_certs(self.accept_invalid_certs)
|
||||||
.redirect(self.redirect_policy())
|
.redirect(self.redirect_policy())
|
||||||
.default_headers(headers)
|
.default_headers(headers)
|
||||||
|
|
Loading…
Reference in New Issue