diff options
author | Bryan Newbold <bnewbold@archive.org> | 2020-08-26 18:21:52 -0700 |
---|---|---|
committer | Bryan Newbold <bnewbold@archive.org> | 2020-08-26 18:21:52 -0700 |
commit | 13220ca46bbc9fd0001c1c942c3b7238e0f596ee (patch) | |
tree | f96acce59fa7d5b93ca5a8bcbd78132f29f2de26 /src/main.rs | |
parent | c848647acf7aa967da4f2b9ec89843f208fb4e24 (diff) | |
download | es-public-proxy-13220ca46bbc9fd0001c1c942c3b7238e0f596ee.tar.gz es-public-proxy-13220ca46bbc9fd0001c1c942c3b7238e0f596ee.zip |
refactor errors; fix header names; fmt
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/main.rs b/src/main.rs index 5f6b574..b55999b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,5 @@ use hyper::service::{make_service_fn, service_fn}; -use hyper::{Body, Client, Request, Response, Server, StatusCode, header::HeaderValue}; +use hyper::{header::HeaderValue, Body, Client, Request, Response, Server}; use std::env; use std::net::SocketAddr; use toml; @@ -23,22 +23,22 @@ async fn upstream_req( Client::new().request(upstream_req).await? } Err(other) => Response::builder() - .status(StatusCode::INTERNAL_SERVER_ERROR) + .status(other.http_status_code()) .header("Content-Type", "application/json; charset=UTF-8") - .body(serde_json::to_string(&other.to_json()).unwrap().into()) + .body( + serde_json::to_string(&other.to_json_value()) + .unwrap() + .into(), + ) .unwrap(), }; - resp.headers_mut().insert( - "Via", - HeaderValue::from_static("es-public-proxy"), - ); + resp.headers_mut() + .insert("Via", HeaderValue::from_static("1.1 es-public-proxy")); if config.enable_cors == Some(true) { + resp.headers_mut() + .insert("Access-Control-Allow-Origin", HeaderValue::from_static("*")); resp.headers_mut().insert( - "Access-Control-Allow-Origin", - HeaderValue::from_static("*"), - ); - resp.headers_mut().insert( - "Access-Control-Allow-Origin", + "Access-Control-Allow-Methods", HeaderValue::from_static("GET, POST, DELETE, HEAD, OPTIONS"), ); resp.headers_mut().insert( |