Skip to content

Commit 1e51908

Browse files
committed
chore(proxy/http): address hyper::client::conn::SendRequest deprecation
this commit updates code in `linkerd-proxy-http`'s HTTP/2 client code, and the `linkerd-app-test` crate's `TestServer`, to use the new `hyper::client::conn::http2::SendRequest` backported from the 1.x major release. see <hyperium/hyper#2960> for more information. this commit refrains from updating the broader client connection system, and addresses the breaking changes to `SendRequest` made in the 1.0 major release, namely: * send request is no longer a tower service: * <https://docs.rs/hyper/0.14.31/hyper/client/conn/struct.SendRequest.html#impl-Service%3CRequest%3CB%3E%3E-for-SendRequest%3CB%3E> * <https://docs.rs/hyper/1.5.1/hyper/client/conn/http2/struct.SendRequest.html#trait-implementations> * `send_request()` now returns an anonymous `impl Future` and not a named `ResponseFuture`, as in `0.14`. * <https://docs.rs/hyper/0.14.31/hyper/client/conn/struct.ResponseFuture.html> * <https://docs.rs/hyper/1.5.1/hyper/client/conn/http2/struct.SendRequest.html#method.send_request> NB: this change depends on <hyperium/hyper#3798>.
1 parent 4f3e611 commit 1e51908

File tree

4 files changed

+23
-17
lines changed

4 files changed

+23
-17
lines changed

linkerd/app/test/src/http_util.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ use crate::{
33
io, ContextError,
44
};
55
use futures::FutureExt;
6-
use hyper::{body::HttpBody, Body, Request, Response};
6+
use hyper::{body::HttpBody, client::conn::http2::SendRequest, Body, Request, Response};
77
use parking_lot::Mutex;
88
use std::{future::Future, sync::Arc};
99
use tokio::task::JoinHandle;
1010
use tower::{util::ServiceExt, Service};
1111
use tracing::Instrument;
1212

1313
#[allow(deprecated)] // linkerd/linkerd2#8733
14-
use hyper::client::conn::{Builder as ClientBuilder, SendRequest};
14+
use hyper::client::conn::Builder as ClientBuilder;
1515

1616
pub struct Server {
1717
#[allow(deprecated)] // linkerd/linkerd2#8733
@@ -72,7 +72,7 @@ pub async fn connect_client(
7272
res.map_err(Into::into)
7373
})
7474
.instrument(tracing::info_span!("client_bg"));
75-
(client, tokio::spawn(client_bg))
75+
(client.into(), tokio::spawn(client_bg))
7676
}
7777

7878
#[allow(deprecated)] // linkerd/linkerd2#8733
@@ -98,19 +98,21 @@ pub async fn connect_and_accept(
9898
}
9999

100100
#[tracing::instrument(skip(client))]
101-
#[allow(deprecated)] // linkerd/linkerd2#8733
102101
pub async fn http_request(
103102
client: &mut SendRequest<Body>,
104103
request: Request<Body>,
105104
) -> Result<Response<Body>, Error> {
106-
let rsp = client
105+
// Wait for the dispatcher to be ready for a request.
106+
client
107107
.ready()
108108
.await
109-
.map_err(ContextError::ctx("HTTP client poll_ready failed"))?
110-
.call(request)
109+
.map_err(ContextError::ctx("HTTP client poll_ready failed"))?;
110+
111+
// Send the request, awaiting a response.
112+
let rsp = client
113+
.send_request(request)
111114
.await
112115
.map_err(ContextError::ctx("HTTP client request failed"))?;
113-
114116
tracing::info!(?rsp);
115117

116118
Ok(rsp)

linkerd/proxy/http/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ http = "0.2"
2121
http-body = "0.4"
2222
httparse = "1"
2323
hyper = { version = "0.14", features = [
24+
"backports",
2425
"client",
2526
"deprecated",
2627
"http1",

linkerd/proxy/http/src/h2.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ pub struct Connect<C, B> {
2323

2424
#[derive(Debug)]
2525
pub struct Connection<B> {
26-
#[allow(deprecated)] // linkerd/linkerd2#8733
27-
tx: hyper::client::conn::SendRequest<B>,
26+
tx: hyper::client::conn::http2::SendRequest<B>,
2827
}
2928

3029
// === impl Connect ===
@@ -136,7 +135,7 @@ where
136135
.instrument(trace_span!("conn").or_current()),
137136
);
138137

139-
Ok(Connection { tx })
138+
Ok(Connection { tx: tx.into() })
140139
}
141140
.instrument(debug_span!("h2").or_current()),
142141
)
@@ -153,7 +152,7 @@ where
153152
{
154153
type Response = http::Response<hyper::Body>;
155154
type Error = hyper::Error;
156-
type Future = conn::ResponseFuture;
155+
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send>>;
157156

158157
#[inline]
159158
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
@@ -175,6 +174,6 @@ where
175174
*req.version_mut() = http::Version::HTTP_11;
176175
}
177176

178-
self.tx.send_request(req)
177+
self.tx.send_request(req).boxed()
179178
}
180179
}

linkerd/proxy/http/src/server/tests.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::vec;
22

33
use super::*;
44
use bytes::Bytes;
5+
use futures::FutureExt;
56
use http_body::Body;
67
use linkerd_stack::CloneParam;
78
use tokio::time;
@@ -144,8 +145,7 @@ async fn h2_stream_window_exhaustion() {
144145
const LOG_LEVEL: &str = "h2::proto=trace,hyper=trace,linkerd=trace,info";
145146

146147
struct TestServer {
147-
#[allow(deprecated)] // linkerd/linkerd2#8733
148-
client: hyper::client::conn::SendRequest<BoxBody>,
148+
client: hyper::client::conn::http2::SendRequest<BoxBody>,
149149
server: Handle,
150150
}
151151

@@ -202,7 +202,10 @@ impl TestServer {
202202
.expect("client connect");
203203
tokio::spawn(task.instrument(info_span!("client")));
204204

205-
Self { client, server }
205+
Self {
206+
client: client.into(),
207+
server,
208+
}
206209
}
207210

208211
#[allow(deprecated)] // linkerd/linkerd2#8733
@@ -228,7 +231,8 @@ impl TestServer {
228231
self.server.allow(1);
229232
let mut call0 = self
230233
.client
231-
.send_request(http::Request::new(BoxBody::default()));
234+
.send_request(http::Request::new(BoxBody::default()))
235+
.boxed();
232236
let (_req, next) = tokio::select! {
233237
_ = (&mut call0) => unreachable!("client cannot receive a response"),
234238
next = self.server.next_request() => next.expect("server not dropped"),

0 commit comments

Comments
 (0)