Implement proxy_all for proxying entire domains
I wanted to add another domain behind a reverse proxy. The existing reverse proxy functionality seemed to only work for subpaths so I implemented this. (I'm happy with another better way if you can point one to me.) I also implemented streaming responses when reverse proxying. That way the responses stay as similar as possible to the upstream server.
This commit is contained in:
committed by
int 80h
parent
cb4ee95620
commit
7f3248e92d
19
src/main.rs
19
src/main.rs
@@ -238,6 +238,25 @@ async fn handle_connection(
|
||||
None => {}
|
||||
}
|
||||
|
||||
#[cfg(feature = "proxy")]
|
||||
if let Some(pr) = &srv.server.proxy_all {
|
||||
let host_port: Vec<&str> = pr.splitn(2, ':').collect();
|
||||
let host = host_port[0];
|
||||
let port: Option<u16>;
|
||||
if host_port.len() == 2 {
|
||||
port = host_port[1].parse().ok();
|
||||
} else {
|
||||
port = None;
|
||||
}
|
||||
|
||||
let mut upstream_url = url.clone();
|
||||
upstream_url.set_host(Some(host)).unwrap();
|
||||
upstream_url.set_port(port).unwrap();
|
||||
|
||||
revproxy::proxy_all(pr, upstream_url, con).await?;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
#[cfg(feature = "proxy")]
|
||||
match &srv.server.proxy {
|
||||
Some(pr) => match url.path_segments().map(|c| c.collect::<Vec<_>>()) {
|
||||
|
||||
Reference in New Issue
Block a user