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 e3a7c3c commit fedae0c
Showing 1 changed file with 37 additions and 25 deletions.
62 changes: 37 additions & 25 deletions rust_http_proxy/src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,42 +187,54 @@ impl ProxyHandler {
client_socket_addr: SocketAddr,
username: String,
) -> Result<Response<BoxBody<Bytes, io::Error>>, io::Error> {
let addr = host_addr(req.uri()).ok_or_else(|| {
io::Error::new(
ErrorKind::InvalidData,
format!("URI missing host: {}", req.uri()),
)
})?;
let access_label = AccessLabel {
client: client_socket_addr.ip().to_canonical().to_string(),
target: addr.to_string(),
username,
};
let stream_map_func = |stream: TcpStream, access_label: AccessLabel| {
CounterIO::new(
stream,
self.metrics.proxy_traffic.clone(),
LabelImpl::new(access_label),
)
};
let access_label = self.parse_req_meta(&req, client_socket_addr, username)?;
mod_http1_proxy_req(&mut req);
if let Ok(resp) = self
match self
.http1_client
.send_request(req, &access_label, stream_map_func)
.send_request(
req,
&access_label,
|stream: TcpStream, access_label: AccessLabel| {
CounterIO::new(
stream,
self.metrics.proxy_traffic.clone(),
LabelImpl::new(access_label),
)
},
)
.await
{
Ok(resp.map(|b| {
b.map_err(|e| {
Ok(resp) => Ok(resp.map(|body| {
body.map_err(|e| {
let e = e;
io::Error::new(ErrorKind::InvalidData, e)
})
.boxed()
}))
} else {
Err(io::Error::new(ErrorKind::ConnectionAborted, "连接失败"))
})),
Err(e) => Err(e),
}
}

fn parse_req_meta(
&self,
req: &Request<Incoming>,
client_socket_addr: SocketAddr,
username: String,
) -> Result<AccessLabel, io::Error> {
let addr = host_addr(req.uri()).ok_or_else(|| {
io::Error::new(
ErrorKind::InvalidData,
format!("URI missing host: {}", req.uri()),
)
})?;
let access_label = AccessLabel {
client: client_socket_addr.ip().to_canonical().to_string(),
target: addr.to_string(),
username,
};
Ok(access_label)
}

/// 代理CONNECT请求
/// HTTP/1.1 CONNECT
fn tunnel_proxy(
Expand Down

0 comments on commit fedae0c

Please sign in to comment.