mirror of
https://github.com/denoland/deno.git
synced 2025-07-26 22:53:59 +00:00
use shared HTTP client (#3563)
This commit moves HTTP client to lazy_static. Effectively HTTP client is shared by whole Deno process and will reuse connections.
This commit is contained in:
parent
46d76a7562
commit
011d485ce5
1 changed files with 19 additions and 13 deletions
|
@ -14,9 +14,8 @@ use reqwest::Client;
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
/// Create new instance of async reqwest::Client. This client supports
|
lazy_static! {
|
||||||
/// proxies and doesn't follow redirects.
|
static ref HTTP_CLIENT: Client = {
|
||||||
pub fn get_client() -> Client {
|
|
||||||
let mut headers = HeaderMap::new();
|
let mut headers = HeaderMap::new();
|
||||||
headers.insert(
|
headers.insert(
|
||||||
USER_AGENT,
|
USER_AGENT,
|
||||||
|
@ -28,6 +27,13 @@ pub fn get_client() -> Client {
|
||||||
.use_rustls_tls()
|
.use_rustls_tls()
|
||||||
.build()
|
.build()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get instance of async reqwest::Client. This client supports
|
||||||
|
/// proxies and doesn't follow redirects.
|
||||||
|
pub fn get_client() -> &'static Client {
|
||||||
|
&HTTP_CLIENT
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct the next uri based on base uri and location header fragment
|
/// Construct the next uri based on base uri and location header fragment
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue