Initial implementation of proxy module

main
Brian Picciano 12 months ago
parent a86020eedf
commit 4a2ac7460f
  1. 12
      Cargo.lock
  2. 1
      Cargo.toml
  3. 1
      src/origin.rs
  4. 21
      src/origin/proxy.rs

12
Cargo.lock generated

@ -466,6 +466,7 @@ dependencies = [
"hex",
"http",
"hyper",
"hyper-reverse-proxy",
"log",
"mime_guess",
"mockall",
@ -1538,6 +1539,17 @@ dependencies = [
"want",
]
[[package]]
name = "hyper-reverse-proxy"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cc1af9b1b483fb9f33bd1cda26b35eacf902f0d116fcf0d56075ea5e5923b935"
dependencies = [
"hyper",
"lazy_static",
"unicase",
]
[[package]]
name = "hyper-rustls"
version = "0.24.1"

@ -44,3 +44,4 @@ env_logger = "0.10.0"
serde_yaml = "0.9.22"
rand = "0.8.5"
reqwest = "0.11.18"
hyper-reverse-proxy = "0.5.1"

@ -2,6 +2,7 @@ mod config;
mod descr;
pub mod git;
pub mod mux;
pub mod proxy;
pub use config::*;
pub use descr::Descr;

@ -0,0 +1,21 @@
use crate::error::unexpected;
use std::net;
// proxy is a special case because it is so tied to the underlying protocol that a request is
// being served on, it can't be abstracted out into a simple "get_file" operation like other
// origins.
pub async fn serve_http_request(
client_ip: net::IpAddr,
proxy_url: &str,
req: hyper::Request<hyper::Body>,
) -> unexpected::Result<hyper::Response<hyper::Body>> {
match hyper_reverse_proxy::call(client_ip, proxy_url, req).await {
Ok(res) => Ok(res),
// ProxyError doesn't actually implement Error :facepalm: so we have to format the error
// manually
Err(e) => Err(unexpected::Error::from(
format!("error while proxying: {e:?}").as_str(),
)),
}
}
Loading…
Cancel
Save