1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-22 15:06:54 -05:00

refactor: use hyper 1.0 in grpc test server (#21584)

Ref https://github.com/denoland/deno/issues/21578
This commit is contained in:
Bartek Iwańczuk 2023-12-24 14:14:29 +01:00 committed by GitHub
parent 92b2e28c64
commit e1bfb29868
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 18 additions and 38 deletions

2
Cargo.lock generated
View file

@ -5987,7 +5987,9 @@ dependencies = [
"futures", "futures",
"glob", "glob",
"h2 0.3.22", "h2 0.3.22",
"h2 0.4.0",
"hyper 0.14.27", "hyper 0.14.27",
"hyper 1.1.0",
"lazy-regex", "lazy-regex",
"libc", "libc",
"lsp-types", "lsp-types",

View file

@ -106,7 +106,9 @@ hex = "0.4"
http = "0.2.9" http = "0.2.9"
h2 = { version = "0.3.17", features = ["unstable"] } h2 = { version = "0.3.17", features = ["unstable"] }
httparse = "1.8.0" httparse = "1.8.0"
hyper-util = { version = "=0.1.2", features = ["tokio", "server", "server-auto"] }
hyper = { version = "0.14.26", features = ["runtime", "http1"] } hyper = { version = "0.14.26", features = ["runtime", "http1"] }
hyper1 = { package = "hyper", version = "=1.1.0", features = ["full"] }
indexmap = { version = "2", features = ["serde"] } indexmap = { version = "2", features = ["serde"] }
libc = "0.2.126" libc = "0.2.126"
libz-sys = { version = "1.1", default-features = false } libz-sys = { version = "1.1", default-features = false }

View file

@ -35,8 +35,8 @@ http.workspace = true
http_1 = { package = "http", version = "=1.0.0" } http_1 = { package = "http", version = "=1.0.0" }
httparse.workspace = true httparse.workspace = true
hyper = { workspace = true, features = ["server", "stream", "http1", "http2", "runtime"] } hyper = { workspace = true, features = ["server", "stream", "http1", "http2", "runtime"] }
hyper-util = { version = "=0.1.2", features = ["tokio"] } hyper-util.workspace = true
hyper1 = { package = "hyper", features = ["full"], version = "=1.1.0" } hyper1.workspace = true
itertools = "0.10" itertools = "0.10"
memmem.workspace = true memmem.workspace = true
mime = "0.3.16" mime = "0.3.16"

View file

@ -105,8 +105,8 @@ http.workspace = true
http-body-util = "0.1" http-body-util = "0.1"
http_1 = { package = "http", version = "1.0" } http_1 = { package = "http", version = "1.0" }
hyper = { workspace = true, features = ["server", "stream", "http1", "http2", "runtime"] } hyper = { workspace = true, features = ["server", "stream", "http1", "http2", "runtime"] }
hyper-util = { version = "0.1", features = ["server", "server-auto"] } hyper-util.workspace = true
hyper1 = { package = "hyper", version = "1.0.1", features = ["server"] } hyper1.workspace = true
libc.workspace = true libc.workspace = true
log.workspace = true log.workspace = true
netif = "0.1.6" netif = "0.1.6"

View file

@ -25,7 +25,9 @@ flate2 = { workspace = true, features = ["default"] }
futures.workspace = true futures.workspace = true
glob.workspace = true glob.workspace = true
h2.workspace = true h2.workspace = true
h2_04 = { package = "h2", version = "0.4" }
hyper = { workspace = true, features = ["server", "http1", "http2", "runtime"] } hyper = { workspace = true, features = ["server", "http1", "http2", "runtime"] }
hyper1.workspace = true
lazy-regex.workspace = true lazy-regex.workspace = true
libc.workspace = true libc.workspace = true
lsp-types.workspace = true lsp-types.workspace = true

View file

@ -11,10 +11,8 @@ use regex::Regex;
use serde::Serialize; use serde::Serialize;
use std::collections::HashMap; use std::collections::HashMap;
use std::env; use std::env;
use std::io;
use std::io::Write; use std::io::Write;
use std::path::PathBuf; use std::path::PathBuf;
use std::pin::Pin;
use std::process::Child; use std::process::Child;
use std::process::Command; use std::process::Command;
use std::process::Output; use std::process::Output;
@ -22,8 +20,6 @@ use std::process::Stdio;
use std::result::Result; use std::result::Result;
use std::sync::Mutex; use std::sync::Mutex;
use std::sync::MutexGuard; use std::sync::MutexGuard;
use std::task::Context;
use std::task::Poll;
use tokio::net::TcpStream; use tokio::net::TcpStream;
use url::Url; use url::Url;
@ -201,29 +197,6 @@ async fn get_tcp_listener_stream(
futures::stream::select_all(listeners) futures::stream::select_all(listeners)
} }
/// Taken from example in https://github.com/ctz/hyper-rustls/blob/a02ef72a227dcdf102f86e905baa7415c992e8b3/examples/server.rs
struct HyperAcceptor<'a> {
acceptor: Pin<
Box<dyn Stream<Item = io::Result<rustls_tokio_stream::TlsStream>> + 'a>,
>,
}
impl hyper::server::accept::Accept for HyperAcceptor<'_> {
type Conn = rustls_tokio_stream::TlsStream;
type Error = io::Error;
fn poll_accept(
mut self: Pin<&mut Self>,
cx: &mut Context,
) -> Poll<Option<Result<Self::Conn, Self::Error>>> {
Pin::new(&mut self.acceptor).poll_next(cx)
}
}
#[allow(clippy::non_send_fields_in_send_ty)]
// SAFETY: unsafe trait must have unsafe implementation
unsafe impl std::marker::Send for HyperAcceptor<'_> {}
#[derive(Default)] #[derive(Default)]
struct HttpServerCount { struct HttpServerCount {
count: usize, count: usize,

View file

@ -1,8 +1,9 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
use futures::StreamExt; use futures::StreamExt;
use hyper::header::HeaderValue; use h2_04 as h2;
use hyper::http; use hyper1::header::HeaderName;
use hyper1::header::HeaderValue;
use rustls_tokio_stream::TlsStream; use rustls_tokio_stream::TlsStream;
use tokio::net::TcpStream; use tokio::net::TcpStream;
use tokio::task::LocalSet; use tokio::task::LocalSet;
@ -47,7 +48,7 @@ pub async fn h2_grpc_server(h2_grpc_port: u16, h2s_grpc_port: u16) {
} }
async fn handle_request( async fn handle_request(
mut request: http::Request<h2::RecvStream>, mut request: hyper1::Request<h2::RecvStream>,
mut respond: h2::server::SendResponse<bytes::Bytes>, mut respond: h2::server::SendResponse<bytes::Bytes>,
) -> Result<(), anyhow::Error> { ) -> Result<(), anyhow::Error> {
let body = request.body_mut(); let body = request.body_mut();
@ -58,17 +59,17 @@ pub async fn h2_grpc_server(h2_grpc_port: u16, h2s_grpc_port: u16) {
let maybe_recv_trailers = body.trailers().await?; let maybe_recv_trailers = body.trailers().await?;
let response = http::Response::new(()); let response = hyper1::Response::new(());
let mut send = respond.send_response(response, false)?; 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"hello "), false)?;
send.send_data(bytes::Bytes::from_static(b"world\n"), false)?; send.send_data(bytes::Bytes::from_static(b"world\n"), false)?;
let mut trailers = http::HeaderMap::new(); let mut trailers = hyper1::HeaderMap::new();
trailers.insert( trailers.insert(
http::HeaderName::from_static("abc"), HeaderName::from_static("abc"),
HeaderValue::from_static("def"), HeaderValue::from_static("def"),
); );
trailers.insert( trailers.insert(
http::HeaderName::from_static("opr"), HeaderName::from_static("opr"),
HeaderValue::from_static("stv"), HeaderValue::from_static("stv"),
); );
if let Some(recv_trailers) = maybe_recv_trailers { if let Some(recv_trailers) = maybe_recv_trailers {