aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@archive.org>2020-08-24 21:31:58 -0700
committerBryan Newbold <bnewbold@archive.org>2020-08-24 21:31:58 -0700
commitae6aafc3d936e7e5211cf117ee581298ed74c8de (patch)
treed6c25e13da7f7dc9d4cd47100866b7b9d4045c96 /src/main.rs
parentf06449b68574bf141c1727fb02d13c1f0aeef406 (diff)
downloades-public-proxy-ae6aafc3d936e7e5211cf117ee581298ed74c8de.tar.gz
es-public-proxy-ae6aafc3d936e7e5211cf117ee581298ed74c8de.zip
validation progress
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs30
1 files changed, 17 insertions, 13 deletions
diff --git a/src/main.rs b/src/main.rs
index 62cfd37..017b8c8 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,25 +1,29 @@
use hyper::service::{make_service_fn, service_fn};
-use hyper::{Body, Client, Request, Response, Server, Uri};
+use hyper::{Body, Client, Request, Response, Server, Uri, StatusCode};
use std::net::SocketAddr;
use std::env;
use toml;
-use es_public_proxy::ProxyConfig;
+use es_public_proxy::{ProxyConfig, ParsedRequest, parse_request};
-async fn upstream_req(req: Request<Body>, _config: ProxyConfig) -> Result<Response<Body>, hyper::Error> {
+async fn upstream_req(req: Request<Body>, config: ProxyConfig) -> Result<Response<Body>, hyper::Error> {
println!("hit: {}", req.uri());
- let req_uri = req.uri();
- let upstream_uri = Uri::builder()
- .scheme("http")
- .authority("localhost:9200")
- .path_and_query(req_uri.path_and_query().unwrap().as_str())
- .build()
- .unwrap();
-
- let res = Client::new().get(upstream_uri).await?;
+ let parsed = parse_request(req, &config);
+ let resp = match parsed {
+ ParsedRequest::Allowed(upstream_req) => {
+ println!("sending request...");
+ Client::new().request(upstream_req).await?
+ }
+ other => {
+ Response::builder()
+ .status(StatusCode::NOT_FOUND)
+ .body(format!("oh noooo! {:?}", other).into())
+ .unwrap()
+ },
+ };
println!("resp!");
- Ok(res)
+ Ok(resp)
}
async fn shutdown_signal() {