mirror of
https://github.com/denoland/deno.git
synced 2024-12-23 07:44:48 -05:00
parent
8a352f7260
commit
b310f32e39
1 changed files with 14 additions and 25 deletions
|
@ -29,31 +29,20 @@ use std::task::Poll;
|
||||||
use tokio::io::AsyncRead;
|
use tokio::io::AsyncRead;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
lazy_static! {
|
/// Create new instance of async reqwest::Client. This client supports
|
||||||
static ref HTTP_CLIENT: Client = {
|
|
||||||
let mut headers = HeaderMap::new();
|
|
||||||
headers.insert(
|
|
||||||
USER_AGENT,
|
|
||||||
format!("Deno/{}", version::DENO).parse().unwrap(),
|
|
||||||
);
|
|
||||||
// todo support brotli for fetch ops
|
|
||||||
headers.insert(
|
|
||||||
ACCEPT_ENCODING, HeaderValue::from_static("gzip")
|
|
||||||
);
|
|
||||||
Client::builder()
|
|
||||||
.redirect(Policy::none())
|
|
||||||
.default_headers(headers)
|
|
||||||
.use_rustls_tls()
|
|
||||||
.gzip(true)
|
|
||||||
.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() -> &'static Client {
|
pub fn get_client() -> Client {
|
||||||
&HTTP_CLIENT as &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()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct the next uri based on base uri and location header fragment
|
/// Construct the next uri based on base uri and location header fragment
|
||||||
|
@ -101,7 +90,7 @@ pub fn fetch_string_once(
|
||||||
cached_etag: Option<String>,
|
cached_etag: Option<String>,
|
||||||
) -> impl Future<Output = Result<FetchOnceResult, ErrBox>> {
|
) -> impl Future<Output = Result<FetchOnceResult, ErrBox>> {
|
||||||
let url = url.clone();
|
let url = url.clone();
|
||||||
let client: &Client = get_client();
|
let client = get_client();
|
||||||
|
|
||||||
let fut = async move {
|
let fut = async move {
|
||||||
let mut request = client
|
let mut request = client
|
||||||
|
|
Loading…
Reference in a new issue