mirror of
https://git.asonix.dog/asonix/relay.git
synced 2024-12-21 02:36:30 +00:00
Keep client in thread-local storage
This commit is contained in:
parent
e005adfcf8
commit
74f35faa22
1 changed files with 18 additions and 8 deletions
|
@ -162,7 +162,14 @@ impl std::fmt::Debug for Requests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
thread_local! {
|
||||||
|
static CLIENT: std::cell::OnceCell<Client> = std::cell::OnceCell::new();
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn build_client(user_agent: &str, pool_size: usize) -> Client {
|
pub(crate) fn build_client(user_agent: &str, pool_size: usize) -> Client {
|
||||||
|
CLIENT.with(|client| {
|
||||||
|
client
|
||||||
|
.get_or_init(|| {
|
||||||
let connector = Connector::new().limit(pool_size);
|
let connector = Connector::new().limit(pool_size);
|
||||||
|
|
||||||
Client::builder()
|
Client::builder()
|
||||||
|
@ -171,6 +178,9 @@ pub(crate) fn build_client(user_agent: &str, pool_size: usize) -> Client {
|
||||||
.add_default_header(("User-Agent", user_agent.to_string()))
|
.add_default_header(("User-Agent", user_agent.to_string()))
|
||||||
.timeout(Duration::from_secs(15))
|
.timeout(Duration::from_secs(15))
|
||||||
.finish()
|
.finish()
|
||||||
|
})
|
||||||
|
.clone()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Requests {
|
impl Requests {
|
||||||
|
|
Loading…
Reference in a new issue