[snowpatch] [PATCH] HTTP proxy support
Russell Currey
ruscur at russell.cc
Mon May 16 10:56:34 AEST 2016
On Mon, 2016-05-16 at 10:52 +1000, Andrew Donnellan wrote:
> 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?
I don't know. The ::with_http_proxy thing is all that's in hyper from what I
can tell, whether that'll actually happily use a https proxy I don't know. It
does make successful https connections through a http proxy from what I can
tell..I'll try to confirm.
>
> > + 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()
> });
This is a very good idea that I'm upset I didn't think of.
More information about the snowpatch
mailing list