@@ -7,6 +7,7 @@ use axum_server::Handle;
77use bittorrent_http_tracker_core:: container:: HttpTrackerCoreContainer ;
88use derive_more:: Constructor ;
99use futures:: future:: BoxFuture ;
10+ use reqwest:: Url ;
1011use tokio:: sync:: oneshot:: { Receiver , Sender } ;
1112use torrust_axum_server:: custom_axum_server:: { self , TimeoutAcceptor } ;
1213use torrust_axum_server:: signals:: graceful_shutdown;
@@ -63,8 +64,10 @@ impl Launcher {
6364
6465 let tls = self . tls . clone ( ) ;
6566 let protocol = if tls. is_some ( ) { "https" } else { "http" } ;
67+ let listen_url =
68+ Url :: parse ( & format ! ( "{protocol}://{address}" ) ) . expect ( "Could not parse internal service url for HTTP tracker." ) ;
6669
67- tracing:: info!( target: HTTP_TRACKER_LOG_TARGET , "Starting on: {protocol}://{}" , address ) ;
70+ tracing:: info!( target: HTTP_TRACKER_LOG_TARGET , "Starting on: {protocol}://{address}" ) ;
6871
6972 let app = router ( http_tracker_container, address) ;
7073
@@ -90,7 +93,7 @@ impl Launcher {
9093 tracing:: info!( target: HTTP_TRACKER_LOG_TARGET , "{STARTED_ON}: {protocol}://{}" , address) ;
9194
9295 tx_start
93- . send ( Started { address } )
96+ . send ( Started { listen_url , address } )
9497 . expect ( "the HTTP(s) Tracker service should not be dropped" ) ;
9598
9699 running
@@ -177,9 +180,12 @@ impl HttpServer<Stopped> {
177180 launcher
178181 } ) ;
179182
180- let binding = rx_start. await . expect ( "it should be able to start the service" ) . address ;
183+ let started = rx_start. await . expect ( "it should be able to start the service" ) ;
181184
182- form. send ( ServiceRegistration :: new ( binding, check_fn) )
185+ let listen_url = started. listen_url ;
186+ let binding = started. address ;
187+
188+ form. send ( ServiceRegistration :: new ( listen_url, binding, check_fn) )
183189 . expect ( "it should be able to send service registration" ) ;
184190
185191 Ok ( HttpServer {
@@ -220,7 +226,7 @@ impl HttpServer<Running> {
220226/// This function will return an error if unable to connect.
221227/// Or if the request returns an error.
222228#[ must_use]
223- pub fn check_fn ( binding : & SocketAddr ) -> ServiceHealthCheckJob {
229+ pub fn check_fn ( listen_url : & Url , binding : & SocketAddr ) -> ServiceHealthCheckJob {
224230 let url = format ! ( "http://{binding}/health_check" ) ; // DevSkim: ignore DS137138
225231
226232 let info = format ! ( "checking http tracker health check at: {url}" ) ;
@@ -232,7 +238,7 @@ pub fn check_fn(binding: &SocketAddr) -> ServiceHealthCheckJob {
232238 }
233239 } ) ;
234240
235- ServiceHealthCheckJob :: new ( * binding, info, TYPE_STRING . to_string ( ) , job)
241+ ServiceHealthCheckJob :: new ( listen_url . clone ( ) , * binding, info, TYPE_STRING . to_string ( ) , job)
236242}
237243
238244#[ cfg( test) ]
0 commit comments