fix: fix message handler (changed this inside Arc)
This commit is contained in:
parent
6a616b1603
commit
3d60175c11
7 changed files with 32 additions and 12 deletions
|
|
@ -40,7 +40,7 @@ where
|
|||
{
|
||||
pub listening_on: SocketAddr,
|
||||
pub tls_enabled: bool, // TCP待受がTLSかどうか
|
||||
pub msg_handler: HttpMessageHandler<T, U>,
|
||||
pub msg_handler: Arc<HttpMessageHandler<T, U>>,
|
||||
pub globals: Arc<Globals<U>>,
|
||||
}
|
||||
|
||||
|
|
@ -49,6 +49,21 @@ where
|
|||
T: Connect + Clone + Sync + Send + 'static,
|
||||
U: CryptoSource + Clone + Sync + Send,
|
||||
{
|
||||
/// Wrapper function to handle request
|
||||
async fn serve(
|
||||
handler: Arc<HttpMessageHandler<T, U>>,
|
||||
req: Request<Body>,
|
||||
client_addr: SocketAddr,
|
||||
listen_addr: SocketAddr,
|
||||
tls_enabled: bool,
|
||||
tls_server_name: Option<ServerNameBytesExp>,
|
||||
) -> Result<hyper::Response<Body>> {
|
||||
handler
|
||||
.handle_request(req, client_addr, listen_addr, tls_enabled, tls_server_name)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Serves requests from clients
|
||||
pub(super) fn client_serve<I>(
|
||||
self,
|
||||
stream: I,
|
||||
|
|
@ -72,7 +87,8 @@ where
|
|||
.serve_connection(
|
||||
stream,
|
||||
service_fn(move |req: Request<Body>| {
|
||||
self.msg_handler.clone().handle_request(
|
||||
Self::serve(
|
||||
self.msg_handler.clone(),
|
||||
req,
|
||||
peer_addr,
|
||||
self.listening_on,
|
||||
|
|
@ -91,11 +107,11 @@ where
|
|||
});
|
||||
}
|
||||
|
||||
/// Start without TLS (HTTP cleartext)
|
||||
async fn start_without_tls(self, server: Http<LocalExecutor>) -> Result<()> {
|
||||
let listener_service = async {
|
||||
let tcp_socket = bind_tcp_socket(&self.listening_on)?;
|
||||
let tcp_listener = tcp_socket.listen(self.globals.proxy_config.tcp_listen_backlog)?;
|
||||
// let tcp_listener = TcpListener::bind(&self.listening_on).await?;
|
||||
info!("Start TCP proxy serving with HTTP request for configured host names");
|
||||
while let Ok((stream, _client_addr)) = tcp_listener.accept().await {
|
||||
self.clone().client_serve(stream, server.clone(), _client_addr, None);
|
||||
|
|
@ -106,6 +122,7 @@ where
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Entrypoint for HTTP/1.1 and HTTP/2 servers
|
||||
pub async fn start(self) -> Result<()> {
|
||||
let mut server = Http::new();
|
||||
server.http1_keep_alive(self.globals.proxy_config.keepalive);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue