mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 07:14:47 -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:
parent
92b2e28c64
commit
e1bfb29868
7 changed files with 18 additions and 38 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -5987,7 +5987,9 @@ dependencies = [
|
|||
"futures",
|
||||
"glob",
|
||||
"h2 0.3.22",
|
||||
"h2 0.4.0",
|
||||
"hyper 0.14.27",
|
||||
"hyper 1.1.0",
|
||||
"lazy-regex",
|
||||
"libc",
|
||||
"lsp-types",
|
||||
|
|
|
@ -106,7 +106,9 @@ hex = "0.4"
|
|||
http = "0.2.9"
|
||||
h2 = { version = "0.3.17", features = ["unstable"] }
|
||||
httparse = "1.8.0"
|
||||
hyper-util = { version = "=0.1.2", features = ["tokio", "server", "server-auto"] }
|
||||
hyper = { version = "0.14.26", features = ["runtime", "http1"] }
|
||||
hyper1 = { package = "hyper", version = "=1.1.0", features = ["full"] }
|
||||
indexmap = { version = "2", features = ["serde"] }
|
||||
libc = "0.2.126"
|
||||
libz-sys = { version = "1.1", default-features = false }
|
||||
|
|
|
@ -35,8 +35,8 @@ http.workspace = true
|
|||
http_1 = { package = "http", version = "=1.0.0" }
|
||||
httparse.workspace = true
|
||||
hyper = { workspace = true, features = ["server", "stream", "http1", "http2", "runtime"] }
|
||||
hyper-util = { version = "=0.1.2", features = ["tokio"] }
|
||||
hyper1 = { package = "hyper", features = ["full"], version = "=1.1.0" }
|
||||
hyper-util.workspace = true
|
||||
hyper1.workspace = true
|
||||
itertools = "0.10"
|
||||
memmem.workspace = true
|
||||
mime = "0.3.16"
|
||||
|
|
|
@ -105,8 +105,8 @@ http.workspace = true
|
|||
http-body-util = "0.1"
|
||||
http_1 = { package = "http", version = "1.0" }
|
||||
hyper = { workspace = true, features = ["server", "stream", "http1", "http2", "runtime"] }
|
||||
hyper-util = { version = "0.1", features = ["server", "server-auto"] }
|
||||
hyper1 = { package = "hyper", version = "1.0.1", features = ["server"] }
|
||||
hyper-util.workspace = true
|
||||
hyper1.workspace = true
|
||||
libc.workspace = true
|
||||
log.workspace = true
|
||||
netif = "0.1.6"
|
||||
|
|
|
@ -25,7 +25,9 @@ flate2 = { workspace = true, features = ["default"] }
|
|||
futures.workspace = true
|
||||
glob.workspace = true
|
||||
h2.workspace = true
|
||||
h2_04 = { package = "h2", version = "0.4" }
|
||||
hyper = { workspace = true, features = ["server", "http1", "http2", "runtime"] }
|
||||
hyper1.workspace = true
|
||||
lazy-regex.workspace = true
|
||||
libc.workspace = true
|
||||
lsp-types.workspace = true
|
||||
|
|
|
@ -11,10 +11,8 @@ use regex::Regex;
|
|||
use serde::Serialize;
|
||||
use std::collections::HashMap;
|
||||
use std::env;
|
||||
use std::io;
|
||||
use std::io::Write;
|
||||
use std::path::PathBuf;
|
||||
use std::pin::Pin;
|
||||
use std::process::Child;
|
||||
use std::process::Command;
|
||||
use std::process::Output;
|
||||
|
@ -22,8 +20,6 @@ use std::process::Stdio;
|
|||
use std::result::Result;
|
||||
use std::sync::Mutex;
|
||||
use std::sync::MutexGuard;
|
||||
use std::task::Context;
|
||||
use std::task::Poll;
|
||||
use tokio::net::TcpStream;
|
||||
use url::Url;
|
||||
|
||||
|
@ -201,29 +197,6 @@ async fn get_tcp_listener_stream(
|
|||
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)]
|
||||
struct HttpServerCount {
|
||||
count: usize,
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
use futures::StreamExt;
|
||||
use hyper::header::HeaderValue;
|
||||
use hyper::http;
|
||||
use h2_04 as h2;
|
||||
use hyper1::header::HeaderName;
|
||||
use hyper1::header::HeaderValue;
|
||||
use rustls_tokio_stream::TlsStream;
|
||||
use tokio::net::TcpStream;
|
||||
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(
|
||||
mut request: http::Request<h2::RecvStream>,
|
||||
mut request: hyper1::Request<h2::RecvStream>,
|
||||
mut respond: h2::server::SendResponse<bytes::Bytes>,
|
||||
) -> Result<(), anyhow::Error> {
|
||||
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 response = http::Response::new(());
|
||||
let response = hyper1::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 = http::HeaderMap::new();
|
||||
let mut trailers = hyper1::HeaderMap::new();
|
||||
trailers.insert(
|
||||
http::HeaderName::from_static("abc"),
|
||||
HeaderName::from_static("abc"),
|
||||
HeaderValue::from_static("def"),
|
||||
);
|
||||
trailers.insert(
|
||||
http::HeaderName::from_static("opr"),
|
||||
HeaderName::from_static("opr"),
|
||||
HeaderValue::from_static("stv"),
|
||||
);
|
||||
if let Some(recv_trailers) = maybe_recv_trailers {
|
||||
|
|
Loading…
Reference in a new issue