[snowpatch] [PATCH] HTTP proxy support
Russell Currey
ruscur at russell.cc
Mon May 9 14:02:51 AEST 2016
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.
Signed-off-by: Russell Currey <ruscur at russell.cc>
---
Cargo.toml | 2 +-
src/main.rs | 18 +++++++++++++++++-
2 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/Cargo.toml b/Cargo.toml
index 614abbb..2055e8a 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -26,7 +26,7 @@ license = "GPL-2.0+"
name = "snowpatch"
[dependencies]
-hyper = "0.9"
+hyper = ">0.9.2" # 0.9.2 or later required for proxy support
git2 = "0.3"
rustc-serialize = "0.3"
url = "0.5"
diff --git a/src/main.rs b/src/main.rs
index e9c2035..25899a4 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -38,6 +38,7 @@ 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 +227,22 @@ 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());
+ 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()
+ });
let mut patchwork = PatchworkServer::new(&settings.patchwork.url, &client);
if settings.patchwork.user.is_some() {
--
2.8.2
More information about the snowpatch
mailing list