From 9fe26f8ca189ac81d9c20c454b9dbfa5e1011c3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Tue, 15 Dec 2020 21:45:29 +0100 Subject: [PATCH] refactor: remove dead code (#8781) --- Cargo.lock | 2 -- cli/Cargo.toml | 5 +--- cli/http_util.rs | 74 ---------------------------------------------- runtime/Cargo.toml | 3 ++ 4 files changed, 4 insertions(+), 80 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 58c278e56d..4f12da908a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -455,7 +455,6 @@ dependencies = [ "atty", "base64 0.12.3", "byteorder", - "bytes 0.5.6", "chrono", "clap", "crossbeam-channel 0.5.0", @@ -503,7 +502,6 @@ dependencies = [ "tokio-tungstenite", "uuid", "walkdir", - "warp", "winapi 0.3.9", "winres", ] diff --git a/cli/Cargo.toml b/cli/Cargo.toml index b6979c638d..b0dc9e5093 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -38,7 +38,6 @@ deno_runtime = { path = "../runtime", version = "0.3.0" } atty = "0.2.14" base64 = "0.12.3" -bytes = "0.5.6" byteorder = "1.3.4" clap = "2.33.3" crossbeam-channel = "0.5.0" @@ -72,11 +71,8 @@ tempfile = "3.1.0" termcolor = "1.1.0" tokio = { version = "0.2.22", features = ["full"] } tokio-rustls = "0.14.1" -# Keep in-sync with warp. -tokio-tungstenite = "0.11.0" uuid = { version = "0.8.1", features = ["v4"] } walkdir = "2.3.1" -warp = { version = "0.2.5", features = ["tls"] } [target.'cfg(windows)'.dependencies] winapi = { version = "0.3.9", features = ["knownfolders", "mswsock", "objbase", "shlobj", "tlhelp32", "winbase", "winerror", "winsock2"] } @@ -90,6 +86,7 @@ nix = "0.19.0" chrono = "0.4.15" os_pipe = "0.9.2" test_util = { path = "../test_util" } +tokio-tungstenite = "0.11.0" [target.'cfg(unix)'.dev-dependencies] exec = "0.3.1" # Used in test_raw_tty diff --git a/cli/http_util.rs b/cli/http_util.rs index 97e3453ec4..f6f8095a06 100644 --- a/cli/http_util.rs +++ b/cli/http_util.rs @@ -1,10 +1,8 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. use crate::version; -use bytes::Bytes; use deno_core::error::generic_error; use deno_core::error::AnyError; -use deno_core::futures; use deno_core::url::Url; use deno_runtime::deno_fetch::reqwest; use deno_runtime::deno_fetch::reqwest::header::HeaderMap; @@ -14,18 +12,10 @@ use deno_runtime::deno_fetch::reqwest::header::LOCATION; use deno_runtime::deno_fetch::reqwest::header::USER_AGENT; use deno_runtime::deno_fetch::reqwest::redirect::Policy; use deno_runtime::deno_fetch::reqwest::Client; -use deno_runtime::deno_fetch::reqwest::Response; use deno_runtime::deno_fetch::reqwest::StatusCode; -use std::cmp::min; use std::collections::HashMap; use std::fs::File; -use std::future::Future; -use std::io; use std::io::Read; -use std::pin::Pin; -use std::task::Context; -use std::task::Poll; -use tokio::io::AsyncRead; pub fn get_user_agent() -> String { format!("Deno/{}", version::deno()) @@ -166,70 +156,6 @@ pub async fn fetch_once( Ok(FetchOnceResult::Code(body, headers_)) } -/// Wraps reqwest `Response` so that it can be exposed as an `AsyncRead` and integrated -/// into resources more easily. -pub struct HttpBody { - response: Response, - chunk: Option, - pos: usize, -} - -impl AsyncRead for HttpBody { - fn poll_read( - self: Pin<&mut Self>, - cx: &mut Context, - buf: &mut [u8], - ) -> Poll> { - let mut inner = self.get_mut(); - if let Some(chunk) = inner.chunk.take() { - debug!( - "HttpBody Fake Read buf {} chunk {} pos {}", - buf.len(), - chunk.len(), - inner.pos - ); - let n = min(buf.len(), chunk.len() - inner.pos); - { - let rest = &chunk[inner.pos..]; - buf[..n].copy_from_slice(&rest[..n]); - } - inner.pos += n; - if inner.pos == chunk.len() { - inner.pos = 0; - } else { - inner.chunk = Some(chunk); - } - return Poll::Ready(Ok(n)); - } else { - assert_eq!(inner.pos, 0); - } - - let chunk_future = inner.response.chunk(); - futures::pin_mut!(chunk_future); - - let result = match futures::ready!(chunk_future.poll(cx)) { - Err(e) => Err(io::Error::new(io::ErrorKind::Other, e)), - Ok(Some(chunk)) => { - debug!( - "HttpBody Real Read buf {} chunk {} pos {}", - buf.len(), - chunk.len(), - inner.pos - ); - let n = min(buf.len(), chunk.len()); - buf[..n].copy_from_slice(&chunk[..n]); - if buf.len() < chunk.len() { - inner.pos = n; - inner.chunk = Some(chunk); - } - Ok(n) - } - Ok(None) => Ok(0), - }; - result.into() - } -} - #[cfg(test)] mod tests { use super::*; diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index d5a84a4b99..b7bfc494e9 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -58,6 +58,9 @@ tokio-rustls = "0.14.1" # Keep in-sync with warp. tokio-tungstenite = "0.11.0" uuid = { version = "0.8.1", features = ["v4"] } +# TODO(bartlomieju): remove dependency on warp, it's only used +# for a WebSocket server in inspector.rs +# Keep in-sync with tokio-tungestenite. warp = { version = "0.2.5", features = ["tls"] } webpki = "0.21.3" webpki-roots = "=0.19.0" # Pinned to v0.19.0 to match 'reqwest'.