diff options
author | Bryan Newbold <bnewbold@archive.org> | 2020-08-24 23:08:03 -0700 |
---|---|---|
committer | Bryan Newbold <bnewbold@archive.org> | 2020-08-24 23:08:03 -0700 |
commit | 01e5348c1c0ca9fbf2826e4e35d71a743ba28741 (patch) | |
tree | 1a3eb4dbe09cb2f1e37388b4dfd2cc0fbf09ff92 /src/main.rs | |
parent | 2601c7b7dc32ca40f57b5c9d05aba860feca8910 (diff) | |
download | es-public-proxy-01e5348c1c0ca9fbf2826e4e35d71a743ba28741.tar.gz es-public-proxy-01e5348c1c0ca9fbf2826e4e35d71a743ba28741.zip |
more progress on parsing/validating
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/main.rs b/src/main.rs index 017b8c8..632c159 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,21 +1,21 @@ use hyper::service::{make_service_fn, service_fn}; -use hyper::{Body, Client, Request, Response, Server, Uri, StatusCode}; +use hyper::{Body, Client, Request, Response, Server, StatusCode}; use std::net::SocketAddr; use std::env; use toml; -use es_public_proxy::{ProxyConfig, ParsedRequest, parse_request}; +use es_public_proxy::{ProxyConfig, ProxyError, parse_request}; async fn upstream_req(req: Request<Body>, config: ProxyConfig) -> Result<Response<Body>, hyper::Error> { println!("hit: {}", req.uri()); - let parsed = parse_request(req, &config); + let parsed = parse_request(req, &config).await; let resp = match parsed { - ParsedRequest::Allowed(upstream_req) => { + Ok(upstream_req) => { println!("sending request..."); Client::new().request(upstream_req).await? } - other => { + Err(other) => { Response::builder() .status(StatusCode::NOT_FOUND) .body(format!("oh noooo! {:?}", other).into()) @@ -68,6 +68,7 @@ fn load_config() -> ProxyConfig { let args: Vec<String> = env::args().collect(); let args: Vec<&str> = args.iter().map(|x| x.as_str()).collect(); let mut config_path: Option<String> = None; + let mut allow_all_indices = false; // first parse CLI arg match args.as_slice() { @@ -77,6 +78,7 @@ fn load_config() -> ProxyConfig { std::process::exit(0); }, [_, "--config", p] => { config_path = Some(p.to_string()) }, + [_, "--allow-all-indices"] => { allow_all_indices = true }, _ => { eprintln!("{}", usage()); eprintln!("couldn't parse arguments"); @@ -90,13 +92,17 @@ fn load_config() -> ProxyConfig { } // then either load config file (TOML), or use default config - if let Some(config_path) = config_path { + let mut config = if let Some(config_path) = config_path { let config_toml = std::fs::read_to_string(config_path).unwrap(); let config: ProxyConfig = toml::from_str(&config_toml).unwrap(); config } else { ProxyConfig::default() + }; + if allow_all_indices { + config.allow_all_indices = Some(true); } + config } #[tokio::main] |