From 69bb85ce0d40bf2d0e76d07ae4aaff72c974dc5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Tue, 26 Dec 2023 14:32:21 +0100 Subject: [PATCH] refactor: change cli/ to use hyper 1.1 (#21705) --- Cargo.lock | 37 ++++------------ Cargo.toml | 1 - cli/Cargo.toml | 8 +++- cli/tests/integration/inspector_tests.rs | 41 ++++++++++-------- cli/tests/integration/run_tests.rs | 54 ++++++++++++------------ cli/tools/registry/mod.rs | 2 +- cli/tools/registry/tar.rs | 2 +- ext/websocket/Cargo.toml | 4 -- runtime/Cargo.toml | 1 - test_util/Cargo.toml | 1 - 10 files changed, 69 insertions(+), 82 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 01668b1a34..2a7d188de3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", diff --git a/Cargo.toml b/Cargo.toml index 37569f876e..ae1b0ad008 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 413da7db8f..77aded6da2 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -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 diff --git a/cli/tests/integration/inspector_tests.rs b/cli/tests/integration/inspector_tests.rs index 95310667be..c06cb6a0d1 100644 --- a/cli/tests/integration/inspector_tests.rs +++ b/cli/tests/integration/inspector_tests.rs @@ -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 hyper::rt::Executor for SpawnExecutor +impl hyper1::rt::Executor 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, Response) { +async fn connect_to_ws( + uri: Url, +) -> (WebSocket>, Response) { 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, Response) { .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::::new()) .unwrap(); - fastwebsockets::handshake::client(&SpawnExecutor, req, stream) + fastwebsockets_06::handshake::client(&SpawnExecutor, req, stream) .await .unwrap() } struct InspectorTester { - socket: FragmentCollector, + socket: FragmentCollector>, notification_filter: Box bool + 'static>, child: DenoChild, stderr_lines: Box>, diff --git a/cli/tests/integration/run_tests.rs b/cli/tests/integration/run_tests.rs index 6bba87ae3b..db18d18122 100644 --- a/cli/tests/integration/run_tests.rs +++ b/cli/tests/integration/run_tests.rs @@ -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 hyper::rt::Executor for SpawnExecutor +impl hyper1::rt::Executor 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::::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::::new()) .unwrap(); let (_socket, _) = - fastwebsockets::handshake::client(&SpawnExecutor, req, stream) + fastwebsockets_06::handshake::client(&SpawnExecutor, req, stream) .await .unwrap(); diff --git a/cli/tools/registry/mod.rs b/cli/tools/registry/mod.rs index 06d5a00910..42623039df 100644 --- a/cli/tools/registry/mod.rs +++ b/cli/tools/registry/mod.rs @@ -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; diff --git a/cli/tools/registry/tar.rs b/cli/tools/registry/tar.rs index 7d03e10a6d..14d0f4e4b3 100644 --- a/cli/tools/registry/tar.rs +++ b/cli/tools/registry/tar.rs @@ -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; diff --git a/ext/websocket/Cargo.toml b/ext/websocket/Cargo.toml index 2a0a20114d..5aa668bfea 100644 --- a/ext/websocket/Cargo.toml +++ b/ext/websocket/Cargo.toml @@ -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 diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index e7704dc9e6..d428fa2fbe 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -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 diff --git a/test_util/Cargo.toml b/test_util/Cargo.toml index 73e00ec727..527742816f 100644 --- a/test_util/Cargo.toml +++ b/test_util/Cargo.toml @@ -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