summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authormaowtm <micromaomao@gmail.com>2021-01-16 00:10:24 +0000
committerGitHub <noreply@github.com>2021-01-15 19:10:24 -0500
commit71a2d687187b7cc9f7954cbc041e3dd34349d0aa (patch)
tree403cb03291116f7586f4dbfc198eb5978e75425f /src
parentce4e36a20c81b96eedff47cd76b5bdeaa8c99b28 (diff)
Upgrade all dependencies (#246)
* Upgrade dependencies and add required features * Special case for parsing unix:// url in Docker::new hyper::Uri doesn't allow urls with empty authority, hence parsing unix:///var/run/docker.sock will fail. * Remove empty /lib.rs * Fix cargo fmt
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs34
-rw-r--r--src/transport.rs9
-rw-r--r--src/tty.rs5
3 files changed, 43 insertions, 5 deletions
diff --git a/src/lib.rs b/src/lib.rs
index f44919a..9a93c02 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -956,6 +956,10 @@ impl Docker {
pub fn new() -> Docker {
match env::var("DOCKER_HOST").ok() {
Some(host) => {
+ #[cfg(feature = "unix-socket")]
+ if let Some(path) = host.strip_prefix("unix://") {
+ return Docker::unix(path);
+ }
let host = host.parse().expect("invalid url");
Docker::host(host)
}
@@ -1210,3 +1214,33 @@ impl Default for Docker {
Self::new()
}
}
+
+#[cfg(test)]
+mod tests {
+ #[cfg(feature = "unix-socket")]
+ #[test]
+ fn unix_host_env() {
+ use super::Docker;
+ use std::env;
+ env::set_var("DOCKER_HOST", "unix:///docker.sock");
+ let d = Docker::new();
+ match d.transport {
+ crate::transport::Transport::Unix { path, .. } => {
+ assert_eq!(path, "/docker.sock");
+ }
+ _ => {
+ panic!("Expected transport to be unix.");
+ }
+ }
+ env::set_var("DOCKER_HOST", "http://localhost:8000");
+ let d = Docker::new();
+ match d.transport {
+ crate::transport::Transport::Tcp { host, .. } => {
+ assert_eq!(host, "http://localhost:8000");
+ }
+ _ => {
+ panic!("Expected transport to be http.");
+ }
+ }
+ }
+}
diff --git a/src/transport.rs b/src/transport.rs
index 3ad3b9e..b496e87 100644
--- a/src/transport.rs
+++ b/src/transport.rs
@@ -251,7 +251,7 @@ impl Transport {
let response = self.send_request(req).await?;
match response.status() {
- StatusCode::SWITCHING_PROTOCOLS => Ok(response.into_body().on_upgrade().await?),
+ StatusCode::SWITCHING_PROTOCOLS => Ok(hyper::upgrade::on(response).await?),
_ => Err(Error::ConnectionNotUpgraded),
}
}
@@ -294,7 +294,12 @@ where
cx: &mut Context<'_>,
buf: &mut [u8],
) -> Poll<io::Result<usize>> {
- self.project().tokio_multiplexer.poll_read(cx, buf)
+ let mut readbuf = tokio::io::ReadBuf::new(buf);
+ match self.project().tokio_multiplexer.poll_read(cx, &mut readbuf) {
+ Poll::Pending => Poll::Pending,
+ Poll::Ready(Ok(())) => Poll::Ready(Ok(readbuf.filled().len())),
+ Poll::Ready(Err(e)) => Poll::Ready(Err(e)),
+ }
}
}
diff --git a/src/tty.rs b/src/tty.rs
index a26846f..67c72bd 100644
--- a/src/tty.rs
+++ b/src/tty.rs
@@ -1,13 +1,12 @@
//! Types for working with docker TTY streams
use crate::{Error, Result};
-use bytes::{BigEndian, ByteOrder};
use futures_util::{
io::{AsyncRead, AsyncReadExt, AsyncWrite},
stream::{Stream, TryStreamExt},
};
use pin_project::pin_project;
-use std::io;
+use std::{convert::TryInto, io};
/// An enum representing a chunk of TTY text streamed from a Docker container.
///
@@ -63,7 +62,7 @@ where
}
let size_bytes = &header_bytes[4..];
- let data_length = BigEndian::read_u32(size_bytes);
+ let data_length = u32::from_be_bytes(size_bytes.try_into().unwrap());
let mut data = vec![0u8; data_length as usize];