forked from extern/nushell
Add support for HTTP proxy in network commands (#10401)
Closes https://github.com/nushell/nushell/issues/8847 # Description If the `HTTP_PROXY` variable is found, use its value to setup ureq proxy. I haven't implemented `NO_PROXY` at the moment. # User-Facing Changes No breaking change for the user, the network commands simply use an environment variable. # Tests + Formatting The existing tests seem to run fine, although I can't think of a new test to add.
This commit is contained in:
parent
6c026242d4
commit
8f4ea69c22
@ -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<String> {
|
||||
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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user