diff --git a/crates/nu-command/src/network/http/client.rs b/crates/nu-command/src/network/http/client.rs index 6450a870fec6..1d0d455744e1 100644 --- a/crates/nu-command/src/network/http/client.rs +++ b/crates/nu-command/src/network/http/client.rs @@ -34,10 +34,17 @@ pub fn http_client(allow_insecure: bool) -> ureq::Agent { .build() .expect("Failed to build network tls"); - ureq::builder() + let mut agent_builder = ureq::builder() .user_agent("nushell") - .tls_connector(std::sync::Arc::new(tls)) - .build() + .tls_connector(std::sync::Arc::new(tls)); + + if let Some(http_proxy) = retrieve_http_proxy_from_env() { + if let Ok(proxy) = ureq::Proxy::new(http_proxy) { + agent_builder = agent_builder.proxy(proxy); + } + }; + + agent_builder.build() } pub fn http_parse_url( @@ -639,3 +646,11 @@ pub fn request_handle_response_headers( }, } } + +fn retrieve_http_proxy_from_env() -> Option { + std::env::vars() + .find(|(key, _)| key == "http_proxy") + .or(std::env::vars().find(|(key, _)| key == "HTTP_PROXY")) + .or(std::env::vars().find(|(key, _)| key == "ALL_PROXY")) + .map(|(_, value)| value) +}