From 52c8213c0889f0ff16ff48c83121fb41bad56ba7 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Tue, 25 Aug 2020 18:59:34 -0700 Subject: fmt --- src/main.rs | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 2b25f32..0250976 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,13 +1,15 @@ - use hyper::service::{make_service_fn, service_fn}; use hyper::{Body, Client, Request, Response, Server, StatusCode}; -use std::net::SocketAddr; use std::env; +use std::net::SocketAddr; use toml; -use es_public_proxy::{ProxyConfig, filter_request}; +use es_public_proxy::{filter_request, ProxyConfig}; -async fn upstream_req(req: Request, config: ProxyConfig) -> Result, hyper::Error> { +async fn upstream_req( + req: Request, + config: ProxyConfig, +) -> Result, hyper::Error> { println!("hit: {}", req.uri()); let parsed = filter_request(req, &config).await; let resp = match parsed { @@ -15,13 +17,11 @@ async fn upstream_req(req: Request, config: ProxyConfig) -> Result { - Response::builder() - .status(StatusCode::INTERNAL_SERVER_ERROR) - .header("Content-Type", "application/json; charset=UTF-8") - .body(serde_json::to_string(&other.to_json()).unwrap().into()) - .unwrap() - }, + Err(other) => Response::builder() + .status(StatusCode::INTERNAL_SERVER_ERROR) + .header("Content-Type", "application/json; charset=UTF-8") + .body(serde_json::to_string(&other.to_json()).unwrap().into()) + .unwrap(), }; println!("resp!"); Ok(resp) @@ -35,7 +35,6 @@ async fn shutdown_signal() { } async fn run_server(config: ProxyConfig) { - let addr = match &config.bind_addr { None => SocketAddr::from(([127, 0, 0, 1], 9292)), Some(addr) => addr.parse().unwrap(), @@ -46,11 +45,7 @@ async fn run_server(config: ProxyConfig) { // TODO: possible to avoid cloning config on every connection? let make_svc = make_service_fn(move |_| { let inner = config.clone(); - async move { - Ok::<_, hyper::Error>(service_fn(move |req| { - upstream_req(req, inner.clone()) - })) - } + async move { Ok::<_, hyper::Error>(service_fn(move |req| upstream_req(req, inner.clone()))) } }); let serve_future = Server::bind(&addr).serve(make_svc); let graceful = serve_future.with_graceful_shutdown(shutdown_signal()); @@ -65,7 +60,6 @@ fn usage() -> String { } fn load_config() -> ProxyConfig { - let args: Vec = env::args().collect(); let args: Vec<&str> = args.iter().map(|x| x.as_str()).collect(); let mut config_path: Option = None; @@ -73,13 +67,13 @@ fn load_config() -> ProxyConfig { // first parse CLI arg match args.as_slice() { - [_] | [] => {}, + [_] | [] => {} [_, "-h"] | [_, "--help"] => { println!("{}", usage()); std::process::exit(0); - }, - [_, "--config", p] => { config_path = Some(p.to_string()) }, - [_, "--allow-all-indices"] => { allow_all_indices = true }, + } + [_, "--config", p] => config_path = Some(p.to_string()), + [_, "--allow-all-indices"] => allow_all_indices = true, _ => { eprintln!("{}", usage()); eprintln!("couldn't parse arguments"); -- cgit v1.2.3