From patchwork Mon May 9 04:02:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Russell Currey X-Patchwork-Id: 619716 X-Patchwork-Delegate: andrew.donnellan@au1.ibm.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3r37yd313wz9sdm for ; Mon, 9 May 2016 14:03:05 +1000 (AEST) Received: from ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3r37yd2KR1zDq68 for ; Mon, 9 May 2016 14:03:05 +1000 (AEST) X-Original-To: snowpatch@lists.ozlabs.org Delivered-To: snowpatch@lists.ozlabs.org Received: from russell.cc (russell.cc [IPv6:2404:9400:2:0:216:3eff:fee0:3370]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3r37yZ0DKBzDq5m for ; Mon, 9 May 2016 14:03:01 +1000 (AEST) Received: from snap.ozlabs.ibm.com (static-82-10.transact.net.au [122.99.82.10]) by russell.cc (OpenSMTPD) with ESMTPSA id 70b5324a TLS version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES128-SHA256 bits=128 verify=NO; Mon, 9 May 2016 04:02:57 +0000 (UTC) From: Russell Currey To: snowpatch@lists.ozlabs.org Date: Mon, 9 May 2016 14:02:51 +1000 Message-Id: <1462766571-7834-1-git-send-email-ruscur@russell.cc> X-Mailer: git-send-email 2.8.2 Subject: [snowpatch] [PATCH] HTTP proxy support X-BeenThere: snowpatch@lists.ozlabs.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: Continuous Integration for patch-based workflows List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Russell Currey MIME-Version: 1.0 Errors-To: snowpatch-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "snowpatch" 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 --- 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() {