1
- use std:: { convert:: Infallible , sync :: Arc , time:: Duration } ;
1
+ use std:: { convert:: Infallible , time:: Duration } ;
2
2
3
3
use config:: Config ;
4
4
use http_body_util:: combinators:: BoxBody ;
@@ -28,7 +28,7 @@ async fn main() -> anyhow::Result<()> {
28
28
tracing:: subscriber:: set_global_default ( tracing_subscriber:: fmt ( ) . with_env_filter ( EnvFilter :: builder ( ) . with_default_directive ( LevelFilter :: INFO . into ( ) ) . from_env_lossy ( ) ) . finish ( ) ) ?;
29
29
banner:: print_banner ( ) ;
30
30
let config = Config :: load ( ) . await ?;
31
- let config2 = config . clone ( ) ;
31
+ let config : & ' static _ = Box :: leak ( Box :: new ( config ) ) ;
32
32
let client = config. client . clone ( ) ;
33
33
let client2 = client. clone ( ) ;
34
34
banner:: print_startup_app_config ( & config) ;
@@ -42,7 +42,7 @@ async fn main() -> anyhow::Result<()> {
42
42
let mut timer= std:: pin:: pin!( tokio:: time:: sleep( Duration :: from_secs( 60 ) ) ) ;
43
43
loop {
44
44
debug ! ( "Waiting for next request ..." ) ;
45
- if let Err ( e) = logic_reply:: process_requests ( config2 . clone ( ) , client2. clone ( ) ) . await {
45
+ if let Err ( e) = logic_reply:: process_requests ( config , client2. clone ( ) ) . await {
46
46
match e {
47
47
BeamConnectError :: ProxyTimeoutError => {
48
48
debug ! ( "{e}" ) ;
@@ -71,11 +71,9 @@ async fn main() -> anyhow::Result<()> {
71
71
#[ allow( unused_mut) ]
72
72
let mut executers = vec ! [ http_executor] ;
73
73
#[ cfg( feature = "sockets" ) ]
74
- executers. push ( sockets:: spawn_socket_task_poller ( config. clone ( ) ) ) ;
74
+ executers. push ( sockets:: spawn_socket_task_poller ( config) ) ;
75
75
76
- let config = Arc :: new ( config. clone ( ) ) ;
77
-
78
- if let Err ( e) = server ( & config) . await {
76
+ if let Err ( e) = server ( config) . await {
79
77
error ! ( "Server error: {}" , e) ;
80
78
}
81
79
info ! ( "Shutting down..." ) ;
@@ -84,7 +82,7 @@ async fn main() -> anyhow::Result<()> {
84
82
}
85
83
86
84
// See https://github.com/hyperium/hyper-util/blob/master/examples/server_graceful.rs
87
- async fn server ( config : & Arc < Config > ) -> anyhow:: Result < ( ) > {
85
+ async fn server ( config : & ' static Config ) -> anyhow:: Result < ( ) > {
88
86
let listener = TcpListener :: bind ( config. bind_addr . clone ( ) ) . await ?;
89
87
90
88
let server = hyper_util:: server:: conn:: auto:: Builder :: new ( TokioExecutor :: new ( ) ) ;
@@ -106,9 +104,7 @@ async fn server(config: &Arc<Config>) -> anyhow::Result<()> {
106
104
107
105
let stream = hyper_util:: rt:: TokioIo :: new( stream) ;
108
106
109
- let config = config. clone( ) ;
110
107
let conn = server. serve_connection_with_upgrades( stream, service_fn( move |req| {
111
- let config = config. clone( ) ;
112
108
handler_http_wrapper( req, config)
113
109
} ) ) ;
114
110
@@ -146,7 +142,7 @@ pub type Response<T = BoxBody<Bytes, anyhow::Error>> = hyper::Response<T>;
146
142
147
143
pub ( crate ) async fn handler_http_wrapper (
148
144
req : Request < Incoming > ,
149
- config : Arc < Config > ,
145
+ config : & ' static Config ,
150
146
) -> Result < Response , Infallible > {
151
147
// On https connections we want to emulate that we successfully connected to get the actual http request
152
148
if req. method ( ) == Method :: CONNECT {
@@ -162,7 +158,6 @@ pub(crate) async fn handler_http_wrapper(
162
158
Ok ( s) => s,
163
159
} ;
164
160
server:: conn:: auto:: Builder :: new ( TokioExecutor :: new ( ) ) . serve_connection_with_upgrades ( TokioIo :: new ( tls_connection) , service_fn ( |req| {
165
- let config = config. clone ( ) ;
166
161
let authority = authority. clone ( ) ;
167
162
async move {
168
163
match handler_http ( req, config, authority) . await {
0 commit comments