[snowpatch] [PATCH] HTTP proxy support
Andrew Donnellan
andrew.donnellan at au1.ibm.com
Mon May 16 10:52:36 AEST 2016
On 09/05/16 14:02, Russell Currey wrote:
> With the new HTTP proxy support in hyper 0.9.2, we can finally include it
> in snowpatch.
Excellent!
>
> Enable snowpatch to use HTTP proxies through the http_proxy environment
> variable, as seems to be standard.
What about https?
> + let client = Arc::new(match env::var("http_proxy") {
> + Ok(mut proxy) => {
> + if proxy.starts_with("http://") {
> + proxy.drain(..7);
> + }
> + let mut port = 80;
> + if let Some(colon) = proxy.rfind(":") {
> + port = proxy[colon + 1..].parse().unwrap_or_else(|e| {
> + panic!("http_proxy is malformed: {:?}, error: {}", proxy, e);
> + });
> + proxy.truncate(colon);
> + }
> + Client::with_http_proxy(proxy, port)
> + },
> + _ => Client::new()
> + });
Can we do the URL parsing with the url module instead to avoid doing
string awfulness?
Something along the lines of: (completely untested)
let client = Arc::new(match env::var("http_proxy") {
Ok(proxy_url) => {
let proxy = Url::parse(proxy_url).unwrap_or_else(|e| {
panic!("Malformed URL: {:?}, error: {}", proxy_url, e);
assert!(proxy.scheme() == "http");
assert!(proxy.path() == "");
Client::with_http_proxy(proxy.host_str(), if proxy.port() {
proxy.port() } else { 80 })
},
_ => Client::new()
});
--
Andrew Donnellan OzLabs, ADL Canberra
andrew.donnellan at au1.ibm.com IBM Australia Limited
More information about the snowpatch
mailing list