diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 30 |
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() { |