Skip to content

Commit

Permalink
refactor: Update reverse_proxy.yaml with new upstream locations
Browse files Browse the repository at this point in the history
  • Loading branch information
arloor committed Sep 19, 2024
1 parent f3329c1 commit 3d036f7
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions rust_http_proxy/src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ impl ProxyHandler {
req.headers_mut()
.remove(http::header::PROXY_AUTHORIZATION.to_string());
req.headers_mut().remove("Proxy-Connection");
let path_and_query = req.uri().path_and_query();
// debug!("proxy: {:?}", req);
let addr = match host_addr(req.uri()) {
Some(h) => h,
Expand All @@ -206,13 +205,8 @@ impl ProxyHandler {
LabelImpl::new(access_label),
)
};
// http/1.1 req url
let mut parts = Parts::default();
parts.path_and_query = path_and_query.cloned();
let _ = mem::replace(
req.uri_mut(),
Uri::from_parts(parts).map_err(|e| io::Error::new(ErrorKind::InvalidData, e))?,
);
// change absoulte uri to relative uri
origin_form(req.uri_mut());
if let Ok(resp) = self
.http1_client
.send_request(req, &access_label, stream_map_func)
Expand Down Expand Up @@ -695,9 +689,24 @@ pub(crate) fn check_auth(
}
(username, authed)
}

fn origin_form(uri: &mut Uri) {
let path = match uri.path_and_query() {
Some(path) if path.as_str() != "/" => {
let mut parts = ::http::uri::Parts::default();
parts.path_and_query = Some(path.clone());
Uri::from_parts(parts).expect("path is valid uri")
}
_none_or_just_slash => {
debug_assert!(Uri::default() == "/");
Uri::default()
}
};
*uri = path
}

// Create a TCP connection to host:port, build a tunnel between the connection and
// the upgraded connection

async fn tunnel(
upgraded: Upgraded,
target_io: CounterIO<TcpStream, LabelImpl<AccessLabel>>,
Expand Down

0 comments on commit 3d036f7

Please sign in to comment.