Skip to content

Commit 21a7283

Browse files
committed
dependencies: update to tonic 0.12
Pending hyperium/tonic#1740. DNM until its released. This lets us drop a few shims
1 parent 1963cd7 commit 21a7283

File tree

10 files changed

+341
-333
lines changed

10 files changed

+341
-333
lines changed

Cargo.lock

Lines changed: 248 additions & 301 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ hickory-client = "0.24"
5151
hickory-proto = "0.24"
5252
hickory-resolver = "0.24"
5353
hickory-server = { version = "0.24", features = [ "hickory-resolver" ] }
54-
http-02 = { package = "http", version = "0.2.9" }
55-
http-body-04 = { package = "http-body", version = "0.4" }
56-
http-body-1 = { package = "http-body", version = "1.0.0-rc.2" }
54+
http-body = { package = "http-body", version = "1" }
5755
http-body-util = "0.1"
5856
http-types = { version = "2.12", default-features = false }
5957
hyper = { version = "1.3", features = ["full"] }
@@ -87,9 +85,8 @@ tls-listener = { version = "0.10" }
8785
tokio = { version = "1.0", features = ["full", "test-util"] }
8886
tokio-rustls = { version = "0.26", default-features = false }
8987
tokio-stream = { version = "0.1", features = ["net"] }
90-
tonic = { version = "0.11", default-features = false, features = ["prost", "codegen"] }
88+
tonic = { git ="https://github.com/hyperium/tonic", default-features = false, features = ["prost", "codegen"] }
9189
tower = { version = "0.4", features = ["full"] }
92-
tower-hyper-http-body-compat = { git = "https://github.com/howardjohn/tower-hyper-http-body-compat", branch = "deps/hyper-1.0.0-snapshot1", features = ["server", "http2"] }
9390
tracing = { version = "0.1"}
9491
tracing-subscriber = { version = "0.3", features = ["registry", "env-filter", "json"] }
9592
url = "2.2"

deny.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,4 @@ skip = [
7474

7575
allow-git = [
7676
"https://github.com/janrueth/boring-rustls-provider",
77-
"https://github.com/howardjohn/tower-hyper-http-body-compat"
7877
]

src/hyper_util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ pub fn http2_client() -> client::conn::http2::Builder<TokioExecutor> {
155155

156156
pub fn pooling_client<B>() -> ::hyper_util::client::legacy::Client<HttpConnector, B>
157157
where
158-
B: http_body_1::Body + Send,
158+
B: http_body::Body + Send,
159159
B::Data: Send,
160160
{
161161
::hyper_util::client::legacy::Client::builder(::hyper_util::rt::TokioExecutor::new())

src/identity/caclient.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ impl CaClient {
4343
secret_ttl: i64,
4444
) -> Result<CaClient, Error> {
4545
let svc = tls::grpc_connector(address, cert_provider.fetch_cert().await?)?;
46-
// let client = IstioCertificateServiceClient::new(svc);
47-
// let svc =
48-
// tower_hyper_http_body_compat::Hyper1HttpServiceAsTowerService03HttpService::new(svc);
46+
4947
let client = IstioCertificateServiceClient::with_interceptor(svc, auth);
5048
Ok(CaClient {
5149
client,

src/test_helpers.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ pub mod inpod;
5656
pub mod tcp;
5757
pub mod xds;
5858

59+
mod hyper_tower;
5960
#[cfg(target_os = "linux")]
6061
pub mod linux;
6162
#[cfg(target_os = "linux")]

src/test_helpers/ca.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use tracing::error;
2727
use crate::config::RootCert;
2828

2929
use crate::identity::{AuthSource, CaClient};
30+
use crate::test_helpers::hyper_tower;
3031
use crate::xds::istio::ca::istio_certificate_service_server::{
3132
IstioCertificateService, IstioCertificateServiceServer,
3233
};
@@ -67,7 +68,7 @@ impl CaServer {
6768
if let Err(err) = crate::hyper_util::http2_server()
6869
.serve_connection(
6970
TokioIo::new(socket),
70-
tower_hyper_http_body_compat::TowerService03HttpServiceAsHyper1HttpService::new(srv)
71+
hyper_tower::TowerToHyperService::new(srv),
7172
)
7273
.await
7374
{

src/test_helpers/hyper_tower.rs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
use pin_project_lite::pin_project;
2+
use tonic::body::BoxBody;
3+
use tonic::Status;
4+
use tower::{BoxError, ServiceExt};
5+
6+
// Copied from https://github.com/hyperium/tonic/blob/34b863b1d2a204ef3dd871ec86860fc92aafb451/examples/src/tls_rustls/server.rs
7+
8+
/// An adaptor which converts a [`tower::Service`] to a [`hyper::service::Service`].
9+
///
10+
/// The [`hyper::service::Service`] trait is used by hyper to handle incoming requests,
11+
/// and does not support the `poll_ready` method that is used by tower services.
12+
///
13+
/// This is provided here because the equivalent adaptor in hyper-util does not support
14+
/// tonic::body::BoxBody bodies.
15+
#[derive(Debug, Clone)]
16+
pub struct TowerToHyperService<S> {
17+
service: S,
18+
}
19+
20+
impl<S> TowerToHyperService<S> {
21+
/// Create a new `TowerToHyperService` from a tower service.
22+
pub fn new(service: S) -> Self {
23+
Self { service }
24+
}
25+
}
26+
27+
impl<S> hyper::service::Service<hyper::Request<hyper::body::Incoming>> for TowerToHyperService<S>
28+
where
29+
S: tower::Service<hyper::Request<BoxBody>> + Clone,
30+
S::Error: Into<BoxError> + 'static,
31+
{
32+
type Response = S::Response;
33+
type Error = BoxError;
34+
type Future = TowerToHyperServiceFuture<S, hyper::Request<BoxBody>>;
35+
36+
fn call(&self, req: hyper::Request<hyper::body::Incoming>) -> Self::Future {
37+
use http_body_util::BodyExt;
38+
let req = req.map(|incoming| {
39+
incoming
40+
.map_err(|err| Status::from_error(err.into()))
41+
.boxed_unsync()
42+
});
43+
TowerToHyperServiceFuture {
44+
future: self.service.clone().oneshot(req),
45+
}
46+
}
47+
}
48+
49+
pin_project! {
50+
/// Future returned by [`TowerToHyperService`].
51+
#[derive(Debug)]
52+
pub struct TowerToHyperServiceFuture<S, R>
53+
where
54+
S: tower::Service<R>,
55+
{
56+
#[pin]
57+
future: tower::util::Oneshot<S, R>,
58+
}
59+
}
60+
61+
impl<S, R> std::future::Future for TowerToHyperServiceFuture<S, R>
62+
where
63+
S: tower::Service<R>,
64+
S::Error: Into<BoxError> + 'static,
65+
{
66+
type Output = Result<S::Response, BoxError>;
67+
68+
#[inline]
69+
fn poll(
70+
self: std::pin::Pin<&mut Self>,
71+
cx: &mut std::task::Context<'_>,
72+
) -> std::task::Poll<Self::Output> {
73+
self.project().future.poll(cx).map_err(Into::into)
74+
}
75+
}

src/test_helpers/xds.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use tokio_stream::wrappers::ReceiverStream;
3131
use tonic::{Response, Status, Streaming};
3232
use tracing::{debug, error, info};
3333

34-
use super::test_config_with_port_xds_addr_and_root_cert;
34+
use super::{hyper_tower, test_config_with_port_xds_addr_and_root_cert};
3535
use crate::config::RootCert;
3636
use crate::hyper_util::TokioExecutor;
3737
use crate::metrics::sub_registry;
@@ -85,7 +85,7 @@ impl AdsServer {
8585
if let Err(err) = http2::Builder::new(TokioExecutor)
8686
.serve_connection(
8787
TokioIo::new(socket),
88-
tower_hyper_http_body_compat::TowerService03HttpServiceAsHyper1HttpService::new(srv)
88+
hyper_tower::TowerToHyperService::new(srv),
8989
)
9090
.await
9191
{

src/tls/control.rs

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ use crate::config::RootCert;
1616
use crate::tls::lib::provider;
1717
use crate::tls::{ClientCertProvider, Error, WorkloadCertificate};
1818
use bytes::Bytes;
19-
use http_body_1::{Body, Frame};
20-
use hyper::body::Incoming;
19+
use http_body::{Body, Frame};
2120
use hyper::Uri;
2221
use hyper_rustls::HttpsConnector;
2322
use hyper_util::client::legacy::connect::HttpConnector;
@@ -26,13 +25,11 @@ use std::future::Future;
2625
use std::io::Cursor;
2726
use std::pin::Pin;
2827

28+
use hyper::body::Incoming;
2929
use std::task::{Context, Poll};
3030
use std::time::Duration;
3131

3232
use tonic::body::BoxBody;
33-
use tower_hyper_http_body_compat::{
34-
http02_request_to_http1, http1_response_to_http02, HttpBody04ToHttpBody1, HttpBody1ToHttpBody04,
35-
};
3633

3734
async fn root_to_store(root_cert: &RootCert) -> Result<rustls::RootCertStore, Error> {
3835
let mut roots = rustls::RootCertStore::empty();
@@ -92,10 +89,11 @@ async fn control_plane_client_config(root_cert: &RootCert) -> Result<ClientConfi
9289
.with_no_client_auth())
9390
}
9491

92+
// pub type TlsGrpcChannel = hyper_util::client::legacy::Client<HttpsConnector<HttpConnector>, BoxBody>;
9593
#[derive(Clone, Debug)]
9694
pub struct TlsGrpcChannel {
9795
uri: Uri,
98-
client: hyper_util::client::legacy::Client<HttpsConnector<HttpConnector>, BoxBody1>,
96+
client: hyper_util::client::legacy::Client<HttpsConnector<HttpConnector>, BoxBody>,
9997
}
10098

10199
/// grpc_connector provides a client TLS channel for gRPC requests.
@@ -133,14 +131,10 @@ pub fn grpc_connector(uri: String, cc: ClientConfig) -> Result<TlsGrpcChannel, E
133131
.timer(crate::hyper_util::TokioTimer)
134132
.build(https);
135133

134+
// Ok(client)
136135
Ok(TlsGrpcChannel { uri, client })
137136
}
138137

139-
// Everything here is to hack hyper 1.0 onto tonic.
140-
// TODO(https://github.com/hyperium/tonic/issues/1307) remove all of this and use tonic 'transport'
141-
142-
type BoxBody1 = HttpBody04ToHttpBody1<BoxBody>;
143-
144138
#[derive(Default)]
145139
pub enum DefaultIncoming {
146140
Some(Incoming),
@@ -165,17 +159,16 @@ impl Body for DefaultIncoming {
165159
}
166160
}
167161

168-
impl tower::Service<http_02::Request<BoxBody>> for TlsGrpcChannel {
169-
type Response = http_02::Response<HttpBody1ToHttpBody04<DefaultIncoming>>;
162+
impl tower::Service<http::Request<BoxBody>> for TlsGrpcChannel {
163+
type Response = http::Response<DefaultIncoming>;
170164
type Error = hyper_util::client::legacy::Error;
171165
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send>>;
172166

173167
fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
174168
Ok(()).into()
175169
}
176170

177-
fn call(&mut self, req: http_02::Request<BoxBody>) -> Self::Future {
178-
let mut req = http02_request_to_http1(req.map(HttpBody04ToHttpBody1::new));
171+
fn call(&mut self, mut req: http::Request<BoxBody>) -> Self::Future {
179172
let mut uri = Uri::builder();
180173
if let Some(scheme) = self.uri.scheme() {
181174
uri = uri.scheme(scheme.to_owned());
@@ -191,10 +184,7 @@ impl tower::Service<http_02::Request<BoxBody>> for TlsGrpcChannel {
191184
let future = self.client.request(req);
192185
Box::pin(async move {
193186
let res = future.await?;
194-
Ok(http1_response_to_http02(
195-
res.map(DefaultIncoming::Some)
196-
.map(HttpBody1ToHttpBody04::new),
197-
))
187+
Ok(res.map(DefaultIncoming::Some))
198188
})
199189
}
200190
}

0 commit comments

Comments
 (0)