Skip to content

Commit

Permalink
重构serve函数以简化连接处理逻辑,直接在错误处理部分创建连接
Browse files Browse the repository at this point in the history
  • Loading branch information
arloor committed Jan 9, 2025
1 parent a001837 commit 0f0a535
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions rust_http_proxy/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,15 @@ async fn serve<T: AsyncRead + AsyncWrite + Send + Sync + Unpin + 'static>(
proxy_handler: Arc<ProxyHandler>,
client_socket_addr: SocketAddr,
) {
let binding = auto::Builder::new(TokioExecutor::new());
let timed_io = TimeoutIO::new(io, IDLE_TIMEOUT);
let timed_io = Box::pin(timed_io);
let connection = binding.serve_connection_with_upgrades(
TokioIo::new(timed_io),
service_fn(|req| proxy(req, client_socket_addr, proxy_handler.clone())),
);
if let Err(err) = connection.await {
if let Err(err) = auto::Builder::new(TokioExecutor::new())
.serve_connection_with_upgrades(
TokioIo::new(timed_io),
service_fn(|req| proxy(req, client_socket_addr, proxy_handler.clone())),
)
.await
{
handle_hyper_error(client_socket_addr, err);
}
}
Expand Down

0 comments on commit 0f0a535

Please sign in to comment.