1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-24 15:19:26 -05:00

refactor: change cli/ to use hyper 1.1 (#21705)

This commit is contained in:
Bartek Iwańczuk 2023-12-26 14:32:21 +01:00 committed by GitHub
parent 753777b4af
commit 8fbac67395
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 69 additions and 82 deletions

37
Cargo.lock generated
View file

@ -958,16 +958,20 @@ dependencies = [
"env_logger",
"eszip",
"fancy-regex",
"fastwebsockets 0.5.0",
"fastwebsockets",
"flaky_test",
"flate2",
"fs3",
"fwdansi",
"glibc_version",
"glob",
"h2 0.4.0",
"hex",
"http 0.2.11",
"hyper 0.14.27",
"http 1.0.0",
"http-body-util",
"hyper 1.1.0",
"hyper-util",
"import_map",
"indexmap 2.1.0",
"jsonc-parser",
@ -1612,8 +1616,7 @@ dependencies = [
"deno_webstorage",
"dlopen2",
"encoding_rs",
"fastwebsockets 0.5.0",
"fastwebsockets 0.6.0",
"fastwebsockets",
"filetime",
"flate2",
"fs3",
@ -1770,14 +1773,10 @@ dependencies = [
"deno_core",
"deno_net",
"deno_tls",
"fastwebsockets 0.5.0",
"fastwebsockets 0.6.0",
"h2 0.3.22",
"fastwebsockets",
"h2 0.4.0",
"http 0.2.11",
"http 1.0.0",
"http-body-util",
"hyper 0.14.27",
"hyper 1.1.0",
"hyper-util",
"once_cell",
@ -2347,23 +2346,6 @@ version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5"
[[package]]
name = "fastwebsockets"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17c35f166afb94b7f8e9449d0ad866daca111ba4053f3b1960bb480ca4382c63"
dependencies = [
"base64 0.21.5",
"hyper 0.14.27",
"pin-project",
"rand",
"sha1",
"simdutf8",
"thiserror",
"tokio",
"utf-8",
]
[[package]]
name = "fastwebsockets"
version = "0.6.0"
@ -5988,8 +5970,7 @@ dependencies = [
"bytes",
"console_static_text",
"denokv_proto",
"fastwebsockets 0.5.0",
"fastwebsockets 0.6.0",
"fastwebsockets",
"flate2",
"futures",
"glob",

View file

@ -96,7 +96,6 @@ data-encoding = "2.3.3"
dlopen2 = "0.6.1"
encoding_rs = "=0.8.33"
ecb = "=0.1.2"
fastwebsockets = "=0.5.0"
filetime = "0.2.16"
flate2 = { version = "1.0.26", default-features = false }
fs3 = "0.5.0"

View file

@ -95,14 +95,12 @@ dprint-plugin-typescript = "=0.88.7"
encoding_rs.workspace = true
env_logger = "=0.10.0"
fancy-regex = "=0.10.0"
fastwebsockets.workspace = true
# If you disable the default __vendored_zlib_ng feature above, you _must_ be able to link against `-lz`.
flate2.workspace = true
fs3.workspace = true
glob = "0.3.1"
hex.workspace = true
http.workspace = true
hyper.workspace = true
import_map = { version = "=0.18.0", features = ["ext"] }
indexmap.workspace = true
jsonc-parser = { version = "=0.23.0", features = ["serde"] }
@ -152,7 +150,13 @@ nix.workspace = true
[dev-dependencies]
deno_bench_util.workspace = true
fastwebsockets_06 = { package = "fastwebsockets", version = "0.6", features = ["upgrade", "unstable-split"] }
flaky_test = "=0.1.0"
h2_04 = { package = "h2", version = "0.4" }
http-body-util = "0.1"
http_1 = { package = "http", version = "1.0" }
hyper-util.workspace = true
hyper1.workspace = true
once_cell.workspace = true
os_pipe.workspace = true
pretty_assertions.workspace = true

View file

@ -1,20 +1,20 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
use bytes::Bytes;
use deno_core::anyhow::anyhow;
use deno_core::error::AnyError;
use deno_core::serde_json;
use deno_core::serde_json::json;
use deno_core::url;
use deno_runtime::deno_fetch::reqwest;
use fastwebsockets::FragmentCollector;
use fastwebsockets::Frame;
use fastwebsockets::WebSocket;
use http::header::HOST;
use hyper::header::HeaderValue;
use hyper::upgrade::Upgraded;
use hyper::Body;
use hyper::Request;
use hyper::Response;
use fastwebsockets_06::FragmentCollector;
use fastwebsockets_06::Frame;
use fastwebsockets_06::WebSocket;
use hyper1::body::Incoming;
use hyper1::upgrade::Upgraded;
use hyper1::Request;
use hyper1::Response;
use hyper_util::rt::TokioIo;
use std::io::BufRead;
use std::time::Duration;
use test_util as util;
@ -25,9 +25,14 @@ use util::assert_starts_with;
use util::DenoChild;
use util::TestContextBuilder;
// TODO(bartlomieju): remove `http::header` once we update to `reqwest`
// to version that uses Hyper 1.0
use http::header::HeaderValue;
use http::header::HOST;
struct SpawnExecutor;
impl<Fut> hyper::rt::Executor<Fut> for SpawnExecutor
impl<Fut> hyper1::rt::Executor<Fut> for SpawnExecutor
where
Fut: std::future::Future + Send + 'static,
Fut::Output: Send + 'static,
@ -37,7 +42,9 @@ where
}
}
async fn connect_to_ws(uri: Url) -> (WebSocket<Upgraded>, Response<Body>) {
async fn connect_to_ws(
uri: Url,
) -> (WebSocket<TokioIo<Upgraded>>, Response<Incoming>) {
let domain = &uri.host().unwrap().to_string();
let port = &uri.port().unwrap_or(match uri.scheme() {
"wss" | "https" => 443,
@ -53,23 +60,23 @@ async fn connect_to_ws(uri: Url) -> (WebSocket<Upgraded>, Response<Body>) {
.method("GET")
.uri(uri.path())
.header("Host", host)
.header(hyper::header::UPGRADE, "websocket")
.header(hyper::header::CONNECTION, "Upgrade")
.header(hyper1::header::UPGRADE, "websocket")
.header(hyper1::header::CONNECTION, "Upgrade")
.header(
"Sec-WebSocket-Key",
fastwebsockets::handshake::generate_key(),
fastwebsockets_06::handshake::generate_key(),
)
.header("Sec-WebSocket-Version", "13")
.body(hyper::Body::empty())
.body(http_body_util::Empty::<Bytes>::new())
.unwrap();
fastwebsockets::handshake::client(&SpawnExecutor, req, stream)
fastwebsockets_06::handshake::client(&SpawnExecutor, req, stream)
.await
.unwrap()
}
struct InspectorTester {
socket: FragmentCollector<Upgraded>,
socket: FragmentCollector<TokioIo<Upgraded>>,
notification_filter: Box<dyn FnMut(&str) -> bool + 'static>,
child: DenoChild,
stderr_lines: Box<dyn Iterator<Item = String>>,

View file

@ -1,5 +1,6 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
use bytes::Bytes;
use deno_core::serde_json::json;
use deno_core::url;
use deno_runtime::deno_fetch::reqwest;
@ -4378,32 +4379,32 @@ async fn websocketstream_ping() {
let script = util::testdata_path().join("run/websocketstream_ping_test.ts");
let root_ca = util::testdata_path().join("tls/RootCA.pem");
let srv_fn = hyper::service::service_fn(|mut req| async move {
let srv_fn = hyper1::service::service_fn(|mut req| async move {
let (response, upgrade_fut) =
fastwebsockets::upgrade::upgrade(&mut req).unwrap();
fastwebsockets_06::upgrade::upgrade(&mut req).unwrap();
tokio::spawn(async move {
let mut ws = upgrade_fut.await.unwrap();
ws.write_frame(fastwebsockets::Frame::text(b"A"[..].into()))
ws.write_frame(fastwebsockets_06::Frame::text(b"A"[..].into()))
.await
.unwrap();
ws.write_frame(fastwebsockets::Frame::new(
ws.write_frame(fastwebsockets_06::Frame::new(
true,
fastwebsockets::OpCode::Ping,
fastwebsockets_06::OpCode::Ping,
None,
vec![].into(),
))
.await
.unwrap();
ws.write_frame(fastwebsockets::Frame::text(b"B"[..].into()))
ws.write_frame(fastwebsockets_06::Frame::text(b"B"[..].into()))
.await
.unwrap();
let message = ws.read_frame().await.unwrap();
assert_eq!(message.opcode, fastwebsockets::OpCode::Pong);
ws.write_frame(fastwebsockets::Frame::text(b"C"[..].into()))
assert_eq!(message.opcode, fastwebsockets_06::OpCode::Pong);
ws.write_frame(fastwebsockets_06::Frame::text(b"C"[..].into()))
.await
.unwrap();
ws.write_frame(fastwebsockets::Frame::close_raw(vec![].into()))
ws.write_frame(fastwebsockets_06::Frame::close_raw(vec![].into()))
.await
.unwrap();
});
@ -4425,8 +4426,9 @@ async fn websocketstream_ping() {
.unwrap();
tokio::spawn(async move {
let (stream, _) = server.accept().await.unwrap();
let conn_fut = hyper::server::conn::Http::new()
.serve_connection(stream, srv_fn)
let io = hyper_util::rt::TokioIo::new(stream);
let conn_fut = hyper1::server::conn::http1::Builder::new()
.serve_connection(io, srv_fn)
.with_upgrades();
if let Err(e) = conn_fut.await {
@ -4440,7 +4442,7 @@ async fn websocketstream_ping() {
struct SpawnExecutor;
impl<Fut> hyper::rt::Executor<Fut> for SpawnExecutor
impl<Fut> hyper1::rt::Executor<Fut> for SpawnExecutor
where
Fut: std::future::Future + Send + 'static,
Fut::Output: Send + 'static,
@ -4476,28 +4478,28 @@ async fn websocket_server_multi_field_connection_header() {
let stream = tokio::net::TcpStream::connect("localhost:4319")
.await
.unwrap();
let req = hyper::Request::builder()
.header(hyper::header::UPGRADE, "websocket")
.header(http::header::CONNECTION, "keep-alive, Upgrade")
let req = http_1::Request::builder()
.header(http_1::header::UPGRADE, "websocket")
.header(http_1::header::CONNECTION, "keep-alive, Upgrade")
.header(
"Sec-WebSocket-Key",
fastwebsockets::handshake::generate_key(),
fastwebsockets_06::handshake::generate_key(),
)
.header("Sec-WebSocket-Version", "13")
.uri("ws://localhost:4319")
.body(hyper::Body::empty())
.body(http_body_util::Empty::<Bytes>::new())
.unwrap();
let (mut socket, _) =
fastwebsockets::handshake::client(&SpawnExecutor, req, stream)
fastwebsockets_06::handshake::client(&SpawnExecutor, req, stream)
.await
.unwrap();
let message = socket.read_frame().await.unwrap();
assert_eq!(message.opcode, fastwebsockets::OpCode::Close);
assert_eq!(message.opcode, fastwebsockets_06::OpCode::Close);
assert!(message.payload.is_empty());
socket
.write_frame(fastwebsockets::Frame::close_raw(vec![].into()))
.write_frame(fastwebsockets_06::Frame::close_raw(vec![].into()))
.await
.unwrap();
assert!(child.wait().unwrap().success());
@ -4531,20 +4533,20 @@ async fn websocket_server_idletimeout() {
let stream = tokio::net::TcpStream::connect("localhost:4509")
.await
.unwrap();
let req = hyper::Request::builder()
.header(hyper::header::UPGRADE, "websocket")
.header(http::header::CONNECTION, "keep-alive, Upgrade")
let req = http_1::Request::builder()
.header(http_1::header::UPGRADE, "websocket")
.header(http_1::header::CONNECTION, "keep-alive, Upgrade")
.header(
"Sec-WebSocket-Key",
fastwebsockets::handshake::generate_key(),
fastwebsockets_06::handshake::generate_key(),
)
.header("Sec-WebSocket-Version", "13")
.uri("ws://localhost:4509")
.body(hyper::Body::empty())
.body(http_body_util::Empty::<Bytes>::new())
.unwrap();
let (_socket, _) =
fastwebsockets::handshake::client(&SpawnExecutor, req, stream)
fastwebsockets_06::handshake::client(&SpawnExecutor, req, stream)
.await
.unwrap();

View file

@ -8,6 +8,7 @@ use std::sync::Arc;
use base64::prelude::BASE64_STANDARD;
use base64::Engine;
use bytes::Bytes;
use deno_config::ConfigFile;
use deno_core::anyhow::bail;
use deno_core::anyhow::Context;
@ -20,7 +21,6 @@ use deno_runtime::colors;
use deno_runtime::deno_fetch::reqwest;
use http::header::AUTHORIZATION;
use http::header::CONTENT_ENCODING;
use hyper::body::Bytes;
use import_map::ImportMap;
use lsp_types::Url;
use serde::Serialize;

View file

@ -1,10 +1,10 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
use bytes::Bytes;
use deno_core::anyhow;
use deno_core::anyhow::Context;
use deno_core::error::AnyError;
use deno_core::url::Url;
use hyper::body::Bytes;
use std::io::Write;
use std::path::Path;
use tar::Header;

View file

@ -18,14 +18,10 @@ bytes.workspace = true
deno_core.workspace = true
deno_net.workspace = true
deno_tls.workspace = true
fastwebsockets = { workspace = true, features = ["upgrade", "unstable-split"] }
fastwebsockets_06 = { package = "fastwebsockets", version = "0.6", features = ["upgrade", "unstable-split"] }
h2.workspace = true
h2_04 = { package = "h2", version = "0.4" }
http.workspace = true
http-body-util = "0.1"
http_1 = { package = "http", version = "1.0" }
hyper = { workspace = true, features = ["backports"] }
hyper-util.workspace = true
hyper1.workspace = true
once_cell.workspace = true

View file

@ -93,7 +93,6 @@ deno_webgpu.workspace = true
deno_webidl.workspace = true
deno_websocket.workspace = true
deno_webstorage.workspace = true
fastwebsockets.workspace = true
console_static_text.workspace = true
dlopen2.workspace = true

View file

@ -20,7 +20,6 @@ base64.workspace = true
bytes.workspace = true
console_static_text.workspace = true
denokv_proto.workspace = true
fastwebsockets = { workspace = true, features = ["upgrade"] }
fastwebsockets_06 = { package = "fastwebsockets", version = "0.6", features = ["upgrade"] }
flate2 = { workspace = true, features = ["default"] }
futures.workspace = true