diff mbox

[V2,2/2] HTTP proxy support

Message ID 20160525042143.25728-2-ruscur@russell.cc
State Accepted
Delegated to: Andrew Donnellan
Headers show

Commit Message

Russell Currey May 25, 2016, 4:21 a.m. UTC
With the new HTTP proxy support in hyper 0.9.2, we can finally include it
in snowpatch.

Enable snowpatch to use HTTP proxies through the http_proxy environment
variable, as seems to be standard.

Hyper does not yet support HTTPS proxies.  In addition, the Jenkins code
does not yet support using the main hyper Client, so the proxy will not
be used.

Signed-off-by: Russell Currey <ruscur@russell.cc>
---
 src/main.rs | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

Comments

Andrew Donnellan May 25, 2016, 6:03 a.m. UTC | #1
On 25/05/16 14:21, Russell Currey wrote:
> With the new HTTP proxy support in hyper 0.9.2, we can finally include it
> in snowpatch.
>
> Enable snowpatch to use HTTP proxies through the http_proxy environment
> variable, as seems to be standard.
>
> Hyper does not yet support HTTPS proxies.  In addition, the Jenkins code
> does not yet support using the main hyper Client, so the proxy will not
> be used.
>
> Signed-off-by: Russell Currey <ruscur@russell.cc>

Applied to master: 7e76a0c2126c2a8c577706bd35a5b143c69d419b

Thanks,
diff mbox

Patch

diff --git a/src/main.rs b/src/main.rs
index e9c2035..daf8923 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -25,6 +25,7 @@  extern crate git2;
 extern crate toml;
 extern crate tempdir;
 extern crate docopt;
+extern crate url;
 
 use git2::{Cred, BranchType, RemoteCallbacks, PushOptions};
 
@@ -32,12 +33,15 @@  use hyper::Client;
 
 use docopt::Docopt;
 
+use url::Url;
+
 use std::fs;
 use std::string::String;
 use std::sync::Arc;
 use std::thread;
 use std::time::Duration;
 use std::path::Path;
+use std::env;
 
 mod patchwork;
 use patchwork::{PatchworkServer, TestState, TestResult};
@@ -226,7 +230,21 @@  fn main() {
     let settings = settings::parse(args.arg_config_file);
 
     // The HTTP client we'll use to access the APIs
-    let client = Arc::new(Client::new());
+    // TODO: HTTPS support, not yet implemented in Hyper as of 0.9.6
+    let client = Arc::new(match env::var("http_proxy") {
+        Ok(proxy_url) => {
+            let proxy = Url::parse(&proxy_url).unwrap_or_else(|e| {
+                panic!("http_proxy is malformed: {:?}, error: {}", proxy_url, e);
+            });
+            assert!(proxy.has_host());
+            assert!(proxy.scheme() == "http");
+            // This should pass even if no trailing slash is in http_proxy
+            assert!(proxy.path() == "/");
+            Client::with_http_proxy(proxy.host_str().unwrap().to_string(),
+                proxy.port().unwrap_or(80))
+        },
+        _ => Client::new()
+    });
 
     let mut patchwork = PatchworkServer::new(&settings.patchwork.url, &client);
     if settings.patchwork.user.is_some() {