mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-07 02:57:34 +00:00
Read HTTP proxy from env (#6765)
This PR will use http proxy from env for downloading files.
This commit is contained in:
parent
cbc2746d70
commit
5e81d780bd
2 changed files with 24 additions and 0 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
use crate::http_proxy_from_env;
|
||||||
pub use anyhow::{anyhow, Result};
|
pub use anyhow::{anyhow, Result};
|
||||||
use futures::future::BoxFuture;
|
use futures::future::BoxFuture;
|
||||||
use isahc::config::{Configurable, RedirectPolicy};
|
use isahc::config::{Configurable, RedirectPolicy};
|
||||||
|
@ -95,6 +96,7 @@ pub fn client() -> Arc<dyn HttpClient> {
|
||||||
isahc::HttpClient::builder()
|
isahc::HttpClient::builder()
|
||||||
.connect_timeout(Duration::from_secs(5))
|
.connect_timeout(Duration::from_secs(5))
|
||||||
.low_speed_timeout(100, Duration::from_secs(5))
|
.low_speed_timeout(100, Duration::from_secs(5))
|
||||||
|
.proxy(http_proxy_from_env())
|
||||||
.build()
|
.build()
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
)
|
)
|
||||||
|
|
|
@ -44,6 +44,28 @@ pub fn truncate(s: &str, max_chars: usize) -> &str {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn http_proxy_from_env() -> Option<isahc::http::Uri> {
|
||||||
|
macro_rules! try_env {
|
||||||
|
($($env:literal),+) => {
|
||||||
|
$(
|
||||||
|
if let Ok(env) = std::env::var($env) {
|
||||||
|
return env.parse::<isahc::http::Uri>().ok();
|
||||||
|
}
|
||||||
|
)+
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
try_env!(
|
||||||
|
"ALL_PROXY",
|
||||||
|
"all_proxy",
|
||||||
|
"HTTPS_PROXY",
|
||||||
|
"https_proxy",
|
||||||
|
"HTTP_PROXY",
|
||||||
|
"http_proxy"
|
||||||
|
);
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
/// Removes characters from the end of the string if its length is greater than `max_chars` and
|
/// Removes characters from the end of the string if its length is greater than `max_chars` and
|
||||||
/// appends "..." to the string. Returns string unchanged if its length is smaller than max_chars.
|
/// appends "..." to the string. Returns string unchanged if its length is smaller than max_chars.
|
||||||
pub fn truncate_and_trailoff(s: &str, max_chars: usize) -> String {
|
pub fn truncate_and_trailoff(s: &str, max_chars: usize) -> String {
|
||||||
|
|
Loading…
Reference in a new issue