From 29bd95b42cd2b3c364f0be1f3e07e4b654e0ccf3 Mon Sep 17 00:00:00 2001 From: David Wood Date: Wed, 14 Nov 2018 05:31:55 +0000 Subject: Disable Hyper's http protocol enforcement. (#129) There are some situations where the Docker daemon will expose a HTTP server and will expect connections through a TCP connection rather than via a unix socket. For example, this is the case with Docker for Windows when used through the Windows Subsystem for Linux. In these cases, `DOCKER_HOST` will be of the form `tcp://127.0.0.1:2375`. Docker will not work if `DOCKER_HOST` has the `http` protocol. This commit manually builds a `HttpConnector` from Hyper so that it does not fail if the protocol is not `http`. Therefore, the `DOCKER_HOST` that works with Docker will also work with shiplift. --- src/lib.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index fd45911..6823ea3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -729,6 +729,10 @@ impl Docker { Some("unix") => panic!("Unix socket support is disabled"), _ => { + let mut http = HttpConnector::new(1); + // Required to support DOCKER_HOST variables of the form `tcp://127.0.0.1:2375`. + http.enforce_http(false); + if let Ok(ref certs) = env::var("DOCKER_CERT_PATH") { // fixme: don't unwrap before you know what's in the box // https://github.com/hyperium/hyper/blob/master/src/net.rs#L427-L428 @@ -747,12 +751,10 @@ impl Docker { connector.set_ca_file(&Path::new(ca)).unwrap(); } - let http = HttpConnector::new(1); - let connector = HttpsConnector::with_connector(http, connector).unwrap(); - Docker { transport: Transport::EncryptedTcp { - client: Client::builder().build(connector), + client: Client::builder() + .build(HttpsConnector::with_connector(http, connector).unwrap()), runtime: RefCell::new(tokio::runtime::Runtime::new().unwrap()), host: tcp_host_str, }, @@ -760,7 +762,7 @@ impl Docker { } else { Docker { transport: Transport::Tcp { - client: Client::new(), + client: Client::builder().build(http), runtime: RefCell::new(tokio::runtime::Runtime::new().unwrap()), host: tcp_host_str, }, -- cgit v1.2.3