Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(app/test): remove unused test Server interfaces #3421

Merged
merged 1 commit into from
Dec 4, 2024
Merged
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
71 changes: 2 additions & 69 deletions linkerd/app/test/src/http_util.rs
Original file line number Diff line number Diff line change
@@ -1,43 +1,19 @@
use crate::{
app_core::{svc, tls, Error},
app_core::{svc, Error},
io, ContextError,
};
use futures::FutureExt;
use hyper::{body::HttpBody, Body, Request, Response};
use parking_lot::Mutex;
use std::{future::Future, sync::Arc};
use std::future::Future;
use tokio::task::JoinHandle;
use tower::{util::ServiceExt, Service};
use tracing::Instrument;

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

pub struct Server {
#[allow(deprecated)] // linkerd/linkerd2#8733
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is cherry-picked out of a draft branch i've been working on, addressing deprecated client connection interfaces. this type isn't used, so we can save ourselves the trouble and remove this type altogether.

settings: hyper::server::conn::Http,
f: HandleFuture,
}

type HandleFuture = Box<dyn (FnMut(Request<Body>) -> Result<Response<Body>, Error>) + Send>;

type BoxServer = svc::BoxTcp<io::DuplexStream>;

impl Default for Server {
fn default() -> Self {
Self {
#[allow(deprecated)] // linkerd/linkerd2#8733
settings: hyper::server::conn::Http::new(),
f: Box::new(|_| {
Ok(Response::builder()
.status(http::status::StatusCode::NOT_FOUND)
.body(Body::empty())
.expect("known status code is fine"))
}),
}
}
}

pub async fn run_proxy(mut server: BoxServer) -> (io::DuplexStream, JoinHandle<Result<(), Error>>) {
let (client_io, server_io) = io::duplex(4096);
let f = server
Expand Down Expand Up @@ -131,46 +107,3 @@ where
.to_owned();
Ok(body)
}

impl Server {
pub fn http1(mut self) -> Self {
self.settings.http1_only(true);
self
}

pub fn http2(mut self) -> Self {
self.settings.http2_only(true);
self
}

pub fn new(mut f: impl (FnMut(Request<Body>) -> Response<Body>) + Send + 'static) -> Self {
Self {
f: Box::new(move |req| Ok::<_, Error>(f(req))),
..Default::default()
}
}

pub fn run<E>(self) -> impl (FnMut(E) -> io::Result<io::BoxedIo>) + Send + 'static
where
E: std::fmt::Debug,
E: svc::Param<tls::ConditionalClientTls>,
{
let Self { f, settings } = self;
let f = Arc::new(Mutex::new(f));
move |endpoint| {
let span = tracing::debug_span!("server::run", ?endpoint).or_current();
let _e = span.enter();
let f = f.clone();
let (client_io, server_io) = crate::io::duplex(4096);
let svc = hyper::service::service_fn(move |request: Request<Body>| {
let f = f.clone();
async move {
tracing::info!(?request);
f.lock()(request)
}
});
tokio::spawn(settings.serve_connection(server_io, svc).in_current_span());
Ok(io::BoxedIo::new(client_io))
}
}
}
Loading