@@ -420,51 +420,19 @@ async fn check_port(
420420 host : String , // The host name
421421 timeout : Duration , // The timeout duration for the TCP connection
422422) -> ( String , String ) {
423- let https_with_port = format ! ( "https://{host}:{port}" ) ; // Construct the HTTPS URL with the port
424- let http_with_port = format ! ( "http://{host}:{port}" ) ; // Construct the HTTP URL with the port
423+ let http_protocol = if port == 80 { "http" } else { "https" } ;
425424 let socket_address = SocketAddr :: new ( ip_addr, port) ; // Create a socket address using the IP address and port
426- match port {
427- 80 => {
428- // If the TCP connection is successful, print the HTTP URL with the port
429- let ip = format ! ( "http://{ip_addr}:{port}" ) ;
430-
431- match tokio:: time:: timeout ( timeout, TcpStream :: connect ( & socket_address) ) . await {
432- Ok ( Ok ( _) ) => {
433- return ( http_with_port, ip) ; // Return the HTTP URL and IP address
434- }
435- _ => {
436- // If the TCP connection fails, return early
437- return ( "" . to_string ( ) , "" . to_string ( ) ) ; // Return empty strings
438- }
439- }
440- }
441- 443 => {
442- // If the TCP connection is successful, print the HTTPS URL with the port
443- let ip = format ! ( "https://{ip_addr}:{port}" ) ;
444425
445- match tokio:: time:: timeout ( timeout, TcpStream :: connect ( & socket_address) ) . await {
446- Ok ( Ok ( _) ) => {
447- return ( https_with_port, ip) ; // Return the HTTPS URL and IP address
448- }
449- _ => {
450- // If the TCP connection fails, return early
451- return ( "" . to_string ( ) , "" . to_string ( ) ) ; // Return empty strings
452- }
453- }
426+ match tokio:: time:: timeout ( timeout, TcpStream :: connect ( & socket_address) ) . await {
427+ Ok ( Ok ( _) ) => {
428+ (
429+ format ! ( "{http_protocol}://{host}:{port}" ) ,
430+ format ! ( "{http_protocol}://{ip_addr}:{port}" ) ,
431+ ) // Return the HTTP URL and IP address
454432 }
455433 _ => {
456- // If the TCP connection is successful, print the HTTPS URL with the port
457- let ip = format ! ( "https://{ip_addr}:{port}" ) ;
458-
459- match tokio:: time:: timeout ( timeout, TcpStream :: connect ( & socket_address) ) . await {
460- Ok ( Ok ( _) ) => {
461- return ( https_with_port, ip) ; // Return the HTTPS URL and IP address
462- }
463- _ => {
464- // If the TCP connection fails, return early
465- return ( "" . to_string ( ) , "" . to_string ( ) ) ; // Return empty strings
466- }
467- }
434+ // If the TCP connection fails, return early
435+ ( "" . to_string ( ) , "" . to_string ( ) ) // Return empty strings
468436 }
469437 }
470438}
0 commit comments