1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 23:34:47 -05: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:
Bartek Iwańczuk 2019-12-30 15:58:25 +01:00 committed by GitHub
parent 46d76a7562
commit 011d485ce5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -14,20 +14,26 @@ 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! {
static ref HTTP_CLIENT: Client = {
let mut headers = HeaderMap::new();
headers.insert(
USER_AGENT,
format!("Deno/{}", version::DENO).parse().unwrap(),
);
Client::builder()
.redirect(Policy::none())
.default_headers(headers)
.use_rustls_tls()
.build()
.unwrap()
};
}
/// Get instance of async reqwest::Client. This client supports
/// proxies and doesn't follow redirects. /// proxies and doesn't follow redirects.
pub fn get_client() -> Client { pub fn get_client() -> &'static Client {
let mut headers = HeaderMap::new(); &HTTP_CLIENT
headers.insert(
USER_AGENT,
format!("Deno/{}", version::DENO).parse().unwrap(),
);
Client::builder()
.redirect(Policy::none())
.default_headers(headers)
.use_rustls_tls()
.build()
.unwrap()
} }
/// Construct the next uri based on base uri and location header fragment /// Construct the next uri based on base uri and location header fragment