Skip to content

Commit

Permalink
Add support for HTTP proxy in network commands
Browse files Browse the repository at this point in the history
Closes #8847
  • Loading branch information
fnuttens committed Sep 17, 2023
1 parent bc7736b commit e5eb27f
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions crates/nu-command/src/network/http/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -639,3 +646,9 @@ pub fn request_handle_response_headers(
},
}
}

fn retrieve_http_proxy_from_env() -> Option<String> {
std::env::vars()
.find(|(key, _)| key == "HTTP_PROXY")
.map(|(_, value)| value)
}

0 comments on commit e5eb27f

Please sign in to comment.