Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions linkerd/app/integration/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::*;
use http::{Request, Response};
use linkerd_app_core::proxy::http::TracingExecutor;
use parking_lot::Mutex;
use std::io;
Expand All @@ -7,9 +8,10 @@ use tokio_rustls::rustls::{self, ClientConfig};
use tracing::info_span;

type ClientError = hyper::Error;
type Request = http::Request<hyper::Body>;
type Response = http::Response<hyper::Body>;
type Sender = mpsc::UnboundedSender<(Request, oneshot::Sender<Result<Response, ClientError>>)>;
type Sender = mpsc::UnboundedSender<(
Request<hyper::Body>,
oneshot::Sender<Result<Response<hyper::Body>, ClientError>>,
)>;

#[derive(Clone)]
pub struct TlsConfig {
Expand Down Expand Up @@ -133,11 +135,12 @@ impl Client {
pub fn request(
&self,
builder: http::request::Builder,
) -> impl Future<Output = Result<Response, ClientError>> + Send + Sync + 'static {
) -> impl Future<Output = Result<Response<hyper::Body>, ClientError>> + Send + Sync + 'static
{
self.send_req(builder.body(Bytes::new().into()).unwrap())
}

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

Expand All @@ -156,8 +159,9 @@ impl Client {
#[tracing::instrument(skip(self))]
pub(crate) fn send_req(
&self,
mut req: Request,
) -> impl Future<Output = Result<Response, ClientError>> + Send + Sync + 'static {
mut req: Request<hyper::Body>,
) -> impl Future<Output = Result<Response<hyper::Body>, ClientError>> + Send + Sync + 'static
{
if req.uri().scheme().is_none() {
if self.tls.is_some() {
*req.uri_mut() = format!("https://{}{}", self.authority, req.uri().path())
Expand Down Expand Up @@ -228,8 +232,10 @@ fn run(
version: Run,
tls: Option<TlsConfig>,
) -> (Sender, JoinHandle<()>, Running) {
let (tx, rx) =
mpsc::unbounded_channel::<(Request, oneshot::Sender<Result<Response, ClientError>>)>();
let (tx, rx) = mpsc::unbounded_channel::<(
Request<hyper::Body>,
oneshot::Sender<Result<Response<hyper::Body>, ClientError>>,
)>();

let test_name = thread_name();
let absolute_uris = if let Run::Http1 { absolute_uris } = version {
Expand Down
22 changes: 11 additions & 11 deletions linkerd/app/integration/src/server.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::app_core::svc::http::TracingExecutor;
use super::*;
use http::{Request, Response};
use std::{
io,
sync::atomic::{AtomicUsize, Ordering},
Expand Down Expand Up @@ -41,9 +42,8 @@ pub struct Listening {
pub(super) http_version: Option<Run>,
}

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

impl Listening {
pub fn connections(&self) -> usize {
Expand Down Expand Up @@ -123,7 +123,7 @@ impl Server {
/// to send back.
pub fn route_fn<F>(self, path: &str, cb: F) -> Self
where
F: Fn(Request) -> Response + Send + Sync + 'static,
F: Fn(Request<hyper::Body>) -> Response<hyper::Body> + Send + Sync + 'static,
{
self.route_async(path, move |req| {
let res = cb(req);
Expand All @@ -135,8 +135,8 @@ impl Server {
/// a response to send back.
pub fn route_async<F, U>(mut self, path: &str, cb: F) -> Self
where
F: Fn(Request) -> U + Send + Sync + 'static,
U: TryFuture<Ok = Response> + Send + Sync + 'static,
F: Fn(Request<hyper::Body>) -> U + Send + Sync + 'static,
U: TryFuture<Ok = Response<hyper::Body>> + Send + Sync + 'static,
U::Error: Into<Error> + Send + 'static,
{
let func = move |req| Box::pin(cb(req).map_err(Into::into)) as RspFuture;
Expand Down Expand Up @@ -258,7 +258,7 @@ pub(super) enum Run {
Http2,
}

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

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

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

impl tower::Service<Request> for Svc {
type Response = Response;
impl tower::Service<Request<hyper::Body>> for Svc {
type Response = Response<hyper::Body>;
type Error = Error;
type Future = RspFuture;

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

fn call(&mut self, req: Request) -> Self::Future {
fn call(&mut self, req: Request<hyper::Body>) -> Self::Future {
self.route(req)
}
}
Expand Down