refactor: simplify hyper, http, h2 deps (#21715)

Main change is that:
- "hyper" has been renamed to "hyper_v014" to signal that it's legacy
- "hyper1" has been renamed to "hyper" and should be the default
This commit is contained in:
Bartek Iwańczuk 2023-12-27 17:59:57 +01:00 committed by GitHub
parent 33acd437f5
commit c2414db1f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
33 changed files with 252 additions and 256 deletions

View file

@ -25,11 +25,11 @@ fastwebsockets.workspace = true
flate2 = { workspace = true, features = ["default"] }
futures.workspace = true
glob.workspace = true
h2 = "0.4"
http = "1.0"
h2.workspace = true
http.workspace = true
http-body-util.workspace = true
hyper.workspace = true
hyper-util.workspace = true
hyper1.workspace = true
lazy-regex.workspace = true
libc.workspace = true
lsp-types.workspace = true

View file

@ -2,8 +2,8 @@
use futures::StreamExt;
use h2;
use hyper1::header::HeaderName;
use hyper1::header::HeaderValue;
use hyper::header::HeaderName;
use hyper::header::HeaderValue;
use rustls_tokio_stream::TlsStream;
use tokio::net::TcpStream;
use tokio::task::LocalSet;
@ -48,7 +48,7 @@ pub async fn h2_grpc_server(h2_grpc_port: u16, h2s_grpc_port: u16) {
}
async fn handle_request(
mut request: hyper1::Request<h2::RecvStream>,
mut request: hyper::Request<h2::RecvStream>,
mut respond: h2::server::SendResponse<bytes::Bytes>,
) -> Result<(), anyhow::Error> {
let body = request.body_mut();
@ -59,11 +59,11 @@ pub async fn h2_grpc_server(h2_grpc_port: u16, h2s_grpc_port: u16) {
let maybe_recv_trailers = body.trailers().await?;
let response = hyper1::Response::new(());
let response = hyper::Response::new(());
let mut send = respond.send_response(response, false)?;
send.send_data(bytes::Bytes::from_static(b"hello "), false)?;
send.send_data(bytes::Bytes::from_static(b"world\n"), false)?;
let mut trailers = hyper1::HeaderMap::new();
let mut trailers = hyper::HeaderMap::new();
trailers.insert(
HeaderName::from_static("abc"),
HeaderValue::from_static("def"),

View file

@ -9,7 +9,6 @@ use http;
use http::Request;
use http::Response;
use http_body_util::combinators::UnsyncBoxBody;
use hyper1 as hyper;
use hyper_util::rt::TokioIo;
use std::convert::Infallible;
use std::io;
@ -46,7 +45,7 @@ where
loop {
let (stream, _) = listener.accept().await?;
let io = TokioIo::new(stream);
deno_unsync::spawn(hyper1_serve_connection(
deno_unsync::spawn(hyper_serve_connection(
io,
handler,
options.error_msg,
@ -76,7 +75,7 @@ pub async fn run_server_with_acceptor<'a, A, F, S>(
while let Some(result) = acceptor.next().await {
let stream = result?;
let io = TokioIo::new(stream);
deno_unsync::spawn(hyper1_serve_connection(
deno_unsync::spawn(hyper_serve_connection(
io, handler, error_msg, kind,
));
}
@ -89,7 +88,7 @@ pub async fn run_server_with_acceptor<'a, A, F, S>(
}
}
async fn hyper1_serve_connection<I, F, S>(
async fn hyper_serve_connection<I, F, S>(
io: I,
handler: F,
error_msg: &'static str,
@ -99,7 +98,7 @@ async fn hyper1_serve_connection<I, F, S>(
F: Fn(Request<hyper::body::Incoming>) -> S + Copy + 'static,
S: Future<Output = HandlerOutput> + 'static,
{
let service = hyper1::service::service_fn(handler);
let service = hyper::service::service_fn(handler);
let result: Result<(), anyhow::Error> = match kind {
ServerKind::Auto => {
@ -111,7 +110,7 @@ async fn hyper1_serve_connection<I, F, S>(
.map_err(|e| anyhow::anyhow!("{}", e))
}
ServerKind::OnlyHttp1 => {
let builder = hyper1::server::conn::http1::Builder::new();
let builder = hyper::server::conn::http1::Builder::new();
builder
.serve_connection(io, service)
.await
@ -119,7 +118,7 @@ async fn hyper1_serve_connection<I, F, S>(
}
ServerKind::OnlyHttp2 => {
let builder =
hyper1::server::conn::http2::Builder::new(DenoUnsyncExecutor);
hyper::server::conn::http2::Builder::new(DenoUnsyncExecutor);
builder
.serve_connection(io, service)
.await

View file

@ -24,7 +24,6 @@ use http_body_util::combinators::UnsyncBoxBody;
use http_body_util::BodyExt;
use http_body_util::Empty;
use http_body_util::Full;
use hyper1 as hyper;
use pretty_assertions::assert_eq;
use prost::Message;
use std::collections::HashMap;

View file

@ -7,10 +7,10 @@ use bytes::Bytes;
use http_body_util::combinators::UnsyncBoxBody;
use http_body_util::Empty;
use http_body_util::Full;
use hyper1::body::Incoming;
use hyper1::Request;
use hyper1::Response;
use hyper1::StatusCode;
use hyper::body::Incoming;
use hyper::Request;
use hyper::Response;
use hyper::StatusCode;
use serde_json::json;
use std::convert::Infallible;
use std::net::SocketAddr;

View file

@ -15,11 +15,11 @@ use h2::server::Handshake;
use h2::server::SendResponse;
use h2::Reason;
use h2::RecvStream;
use hyper1::upgrade::Upgraded;
use hyper1::Method;
use hyper1::Request;
use hyper1::Response;
use hyper1::StatusCode;
use hyper::upgrade::Upgraded;
use hyper::Method;
use hyper::Request;
use hyper::Response;
use hyper::StatusCode;
use hyper_util::rt::TokioIo;
use pretty_assertions::assert_eq;
use std::pin::Pin;
@ -126,8 +126,8 @@ fn spawn_ws_server<S>(stream: S, handler: WsHandler)
where
S: tokio::io::AsyncRead + tokio::io::AsyncWrite + Unpin + Send + 'static,
{
let service = hyper1::service::service_fn(
move |mut req: http::Request<hyper1::body::Incoming>| async move {
let service = hyper::service::service_fn(
move |mut req: http::Request<hyper::body::Incoming>| async move {
let (response, upgrade_fut) = fastwebsockets::upgrade::upgrade(&mut req)
.map_err(|e| anyhow!("Error upgrading websocket connection: {}", e))?;
@ -148,7 +148,7 @@ where
let io = TokioIo::new(stream);
tokio::spawn(async move {
let conn = hyper1::server::conn::http1::Builder::new()
let conn = hyper::server::conn::http1::Builder::new()
.serve_connection(io, service)
.with_upgrades();