Skip to content

Commit ce7e664

Browse files
authored
refactor(app/integration): remove Request, Response aliases (#3692)
* refactor(app/integration): remove `Request`, `Response` aliases see linkerd/linkerd2#8733. this commit removes two type aliases from our test server implementation. these are each tied to the defunct `hyper::Body` type. since much of this code was originally written (between 2017 and 2020) we've since developed some patterns / idioms elsewhere for dealing with request and response bodies. to help set the stage for tweaks to which interfaces need `hyper::body::Incoming`, which types work with our general default of `BoxBody`, and which can be generic across arbitrary `B`-typed bodies, we remove these aliases and provide the body parameter to `Request` and `Response`. Signed-off-by: katelyn martin <[email protected]> * refactor(app/integration): remove `Request`, `Response` aliases see linkerd/linkerd2#8733. this commit removes two type aliases from our test client implementation. these are each tied to the defunct `hyper::Body` type. since much of this code was originally written (between 2017 and 2020) we've since developed some patterns / idioms elsewhere for dealing with request and response bodies. to help set the stage for tweaks to which interfaces need `hyper::body::Incoming`, which types work with our general default of `BoxBody`, and which can be generic across arbitrary `B`-typed bodies, we remove these aliases and provide the body parameter to `Request` and `Response`. Signed-off-by: katelyn martin <[email protected]> --------- Signed-off-by: katelyn martin <[email protected]>
1 parent 84c3b84 commit ce7e664

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

linkerd/app/integration/src/client.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use super::*;
2+
use http::{Request, Response};
23
use linkerd_app_core::proxy::http::TracingExecutor;
34
use parking_lot::Mutex;
45
use std::io;
@@ -7,9 +8,10 @@ use tokio_rustls::rustls::{self, ClientConfig};
78
use tracing::info_span;
89

910
type ClientError = hyper::Error;
10-
type Request = http::Request<hyper::Body>;
11-
type Response = http::Response<hyper::Body>;
12-
type Sender = mpsc::UnboundedSender<(Request, oneshot::Sender<Result<Response, ClientError>>)>;
11+
type Sender = mpsc::UnboundedSender<(
12+
Request<hyper::Body>,
13+
oneshot::Sender<Result<Response<hyper::Body>, ClientError>>,
14+
)>;
1315

1416
#[derive(Clone)]
1517
pub struct TlsConfig {
@@ -133,11 +135,12 @@ impl Client {
133135
pub fn request(
134136
&self,
135137
builder: http::request::Builder,
136-
) -> impl Future<Output = Result<Response, ClientError>> + Send + Sync + 'static {
138+
) -> impl Future<Output = Result<Response<hyper::Body>, ClientError>> + Send + Sync + 'static
139+
{
137140
self.send_req(builder.body(Bytes::new().into()).unwrap())
138141
}
139142

140-
pub async fn request_body(&self, req: Request) -> Response {
143+
pub async fn request_body(&self, req: Request<hyper::Body>) -> Response<hyper::Body> {
141144
self.send_req(req).await.expect("response")
142145
}
143146

@@ -156,8 +159,9 @@ impl Client {
156159
#[tracing::instrument(skip(self))]
157160
pub(crate) fn send_req(
158161
&self,
159-
mut req: Request,
160-
) -> impl Future<Output = Result<Response, ClientError>> + Send + Sync + 'static {
162+
mut req: Request<hyper::Body>,
163+
) -> impl Future<Output = Result<Response<hyper::Body>, ClientError>> + Send + Sync + 'static
164+
{
161165
if req.uri().scheme().is_none() {
162166
if self.tls.is_some() {
163167
*req.uri_mut() = format!("https://{}{}", self.authority, req.uri().path())
@@ -228,8 +232,10 @@ fn run(
228232
version: Run,
229233
tls: Option<TlsConfig>,
230234
) -> (Sender, JoinHandle<()>, Running) {
231-
let (tx, rx) =
232-
mpsc::unbounded_channel::<(Request, oneshot::Sender<Result<Response, ClientError>>)>();
235+
let (tx, rx) = mpsc::unbounded_channel::<(
236+
Request<hyper::Body>,
237+
oneshot::Sender<Result<Response<hyper::Body>, ClientError>>,
238+
)>();
233239

234240
let test_name = thread_name();
235241
let absolute_uris = if let Run::Http1 { absolute_uris } = version {

linkerd/app/integration/src/server.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use super::app_core::svc::http::TracingExecutor;
22
use super::*;
3+
use http::{Request, Response};
34
use std::{
45
io,
56
sync::atomic::{AtomicUsize, Ordering},
@@ -41,9 +42,8 @@ pub struct Listening {
4142
pub(super) http_version: Option<Run>,
4243
}
4344

44-
type Request = http::Request<hyper::Body>;
45-
type Response = http::Response<hyper::Body>;
46-
type RspFuture = Pin<Box<dyn Future<Output = Result<Response, Error>> + Send + Sync + 'static>>;
45+
type RspFuture =
46+
Pin<Box<dyn Future<Output = Result<Response<hyper::Body>, Error>> + Send + Sync + 'static>>;
4747

4848
impl Listening {
4949
pub fn connections(&self) -> usize {
@@ -123,7 +123,7 @@ impl Server {
123123
/// to send back.
124124
pub fn route_fn<F>(self, path: &str, cb: F) -> Self
125125
where
126-
F: Fn(Request) -> Response + Send + Sync + 'static,
126+
F: Fn(Request<hyper::Body>) -> Response<hyper::Body> + Send + Sync + 'static,
127127
{
128128
self.route_async(path, move |req| {
129129
let res = cb(req);
@@ -135,8 +135,8 @@ impl Server {
135135
/// a response to send back.
136136
pub fn route_async<F, U>(mut self, path: &str, cb: F) -> Self
137137
where
138-
F: Fn(Request) -> U + Send + Sync + 'static,
139-
U: TryFuture<Ok = Response> + Send + Sync + 'static,
138+
F: Fn(Request<hyper::Body>) -> U + Send + Sync + 'static,
139+
U: TryFuture<Ok = Response<hyper::Body>> + Send + Sync + 'static,
140140
U::Error: Into<Error> + Send + 'static,
141141
{
142142
let func = move |req| Box::pin(cb(req).map_err(Into::into)) as RspFuture;
@@ -258,7 +258,7 @@ pub(super) enum Run {
258258
Http2,
259259
}
260260

261-
struct Route(Box<dyn Fn(Request) -> RspFuture + Send + Sync>);
261+
struct Route(Box<dyn Fn(Request<hyper::Body>) -> RspFuture + Send + Sync>);
262262

263263
impl Route {
264264
fn string(body: &str) -> Route {
@@ -284,7 +284,7 @@ impl std::fmt::Debug for Route {
284284
struct Svc(Arc<HashMap<String, Route>>);
285285

286286
impl Svc {
287-
fn route(&mut self, req: Request) -> RspFuture {
287+
fn route(&mut self, req: Request<hyper::Body>) -> RspFuture {
288288
match self.0.get(req.uri().path()) {
289289
Some(Route(ref func)) => {
290290
tracing::trace!(path = %req.uri().path(), "found route for path");
@@ -302,16 +302,16 @@ impl Svc {
302302
}
303303
}
304304

305-
impl tower::Service<Request> for Svc {
306-
type Response = Response;
305+
impl tower::Service<Request<hyper::Body>> for Svc {
306+
type Response = Response<hyper::Body>;
307307
type Error = Error;
308308
type Future = RspFuture;
309309

310310
fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
311311
Poll::Ready(Ok(()))
312312
}
313313

314-
fn call(&mut self, req: Request) -> Self::Future {
314+
fn call(&mut self, req: Request<hyper::Body>) -> Self::Future {
315315
self.route(req)
316316
}
317317
}

0 commit comments

Comments
 (0)