mirror of
https://github.com/denoland/deno.git
synced 2025-01-11 08:33:43 -05:00
refactor: remove dead code (#8781)
This commit is contained in:
parent
892d6cc997
commit
9fe26f8ca1
4 changed files with 4 additions and 80 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -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",
|
||||
]
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<Bytes>,
|
||||
pos: usize,
|
||||
}
|
||||
|
||||
impl AsyncRead for HttpBody {
|
||||
fn poll_read(
|
||||
self: Pin<&mut Self>,
|
||||
cx: &mut Context,
|
||||
buf: &mut [u8],
|
||||
) -> Poll<Result<usize, io::Error>> {
|
||||
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::*;
|
||||
|
|
|
@ -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'.
|
||||
|
|
Loading…
Reference in a new issue