Skip to content

Commit

Permalink
less is more
Browse files Browse the repository at this point in the history
  • Loading branch information
piscisaureus committed Jul 4, 2020
1 parent 35122ee commit bbb0ccb
Showing 1 changed file with 26 additions and 30 deletions.
56 changes: 26 additions & 30 deletions test_util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,8 @@ pub async fn run_all_servers() {
let u = url.parse::<Uri>().unwrap();
warp::redirect(u)
});
let redirect_server_fut = warp::serve(routes)
.bind(([127, 0, 0, 1], REDIRECT_PORT))
.boxed();
let redirect_server_fut =
warp::serve(routes).bind(([127, 0, 0, 1], REDIRECT_PORT));

let routes = warp::path::full().map(|path: warp::path::FullPath| {
let p = path.as_str();
Expand All @@ -98,9 +97,8 @@ pub async fn run_all_servers() {
let u = url.parse::<Uri>().unwrap();
warp::redirect(u)
});
let another_redirect_server_fut = warp::serve(routes)
.bind(([127, 0, 0, 1], ANOTHER_REDIRECT_PORT))
.boxed();
let another_redirect_server_fut =
warp::serve(routes).bind(([127, 0, 0, 1], ANOTHER_REDIRECT_PORT));

let routes = warp::path::full().map(|path: warp::path::FullPath| {
let p = path.as_str();
Expand All @@ -109,9 +107,8 @@ pub async fn run_all_servers() {
let u = url.parse::<Uri>().unwrap();
warp::redirect(u)
});
let double_redirect_server_fut = warp::serve(routes)
.bind(([127, 0, 0, 1], DOUBLE_REDIRECTS_PORT))
.boxed();
let double_redirect_server_fut =
warp::serve(routes).bind(([127, 0, 0, 1], DOUBLE_REDIRECTS_PORT));

let routes = warp::path::full().map(|path: warp::path::FullPath| {
let p = path.as_str();
Expand All @@ -120,9 +117,8 @@ pub async fn run_all_servers() {
let u = url.parse::<Uri>().unwrap();
warp::redirect(u)
});
let inf_redirect_server_fut = warp::serve(routes)
.bind(([127, 0, 0, 1], INF_REDIRECTS_PORT))
.boxed();
let inf_redirect_server_fut =
warp::serve(routes).bind(([127, 0, 0, 1], INF_REDIRECTS_PORT));

// redirect server that redirect to absolute paths under same host
// redirects /REDIRECT/file_name to /file_name
Expand All @@ -140,9 +136,8 @@ pub async fn run_all_servers() {
.and(warp::fs::dir(root_path()))
.map(custom_headers),
);
let absolute_redirect_server_fut = warp::serve(routes)
.bind(([127, 0, 0, 1], REDIRECT_ABSOLUTE_PORT))
.boxed();
let absolute_redirect_server_fut =
warp::serve(routes).bind(([127, 0, 0, 1], REDIRECT_ABSOLUTE_PORT));

let echo_server = warp::path("echo_server")
.and(warp::post())
Expand Down Expand Up @@ -314,27 +309,28 @@ pub async fn run_all_servers() {
.or(echo_multipart_file)
.or(multipart_form_data);

let http_fut = warp::serve(content_type_handler.clone())
.bind(([127, 0, 0, 1], PORT))
.boxed();
let http_fut =
warp::serve(content_type_handler.clone()).bind(([127, 0, 0, 1], PORT));

let https_fut = warp::serve(content_type_handler.clone())
.tls()
.cert_path("std/http/testdata/tls/localhost.crt")
.key_path("std/http/testdata/tls/localhost.key")
.bind(([127, 0, 0, 1], HTTPS_PORT))
.boxed();

let mut server_fut = future::join_all(vec![
http_fut,
https_fut,
redirect_server_fut,
another_redirect_server_fut,
inf_redirect_server_fut,
double_redirect_server_fut,
absolute_redirect_server_fut,
])
.bind(([127, 0, 0, 1], HTTPS_PORT));

let mut server_fut = async {
futures::join!(
http_fut,
https_fut,
redirect_server_fut,
another_redirect_server_fut,
inf_redirect_server_fut,
double_redirect_server_fut,
absolute_redirect_server_fut,
)
}
.boxed();

let mut did_print_ready = false;
future::poll_fn(move |cx| {
let poll_result = server_fut.poll_unpin(cx);
Expand Down

0 comments on commit bbb0ccb

Please sign in to comment.