@@ -20,6 +20,16 @@ pub mod modded;
2020/// Custom version comparison for Minecraft versions
2121pub mod version;
2222
23+ /// HTTP client configuration constants
24+ /// TCP keepalive interval for persistent connections
25+ const TCP_KEEPALIVE_SECS : u64 = 10 ;
26+ /// Overall request timeout including reading response
27+ const REQUEST_TIMEOUT_SECS : u64 = 120 ;
28+ /// Connection establishment timeout
29+ const CONNECT_TIMEOUT_SECS : u64 = 30 ;
30+ /// Maximum idle connections per host in the pool
31+ const MAX_IDLE_CONNECTIONS_PER_HOST : usize = 10 ;
32+
2333/// Your branding, used for the user agent and similar
2434#[ derive( Debug ) ]
2535pub struct Branding {
@@ -33,6 +43,11 @@ pub struct Branding {
3343pub static BRANDING : OnceCell < Branding > = OnceCell :: new ( ) ;
3444
3545/// Global HTTP client with connection pooling and TCP keepalive
46+ ///
47+ /// # Panics
48+ /// Panics if the HTTP client fails to initialize. This is intentional as
49+ /// the application cannot function without a working HTTP client (e.g., if
50+ /// TLS initialization fails, which is extremely rare on modern systems).
3651static HTTP_CLIENT : LazyLock < reqwest:: Client > = LazyLock :: new ( || {
3752 let mut headers = reqwest:: header:: HeaderMap :: new ( ) ;
3853 if let Ok ( header) = reqwest:: header:: HeaderValue :: from_str (
@@ -42,11 +57,11 @@ static HTTP_CLIENT: LazyLock<reqwest::Client> = LazyLock::new(|| {
4257 }
4358
4459 reqwest:: Client :: builder ( )
45- . tcp_keepalive ( Some ( Duration :: from_secs ( 10 ) ) )
46- . timeout ( Duration :: from_secs ( 120 ) )
47- . connect_timeout ( Duration :: from_secs ( 30 ) )
60+ . tcp_keepalive ( Some ( Duration :: from_secs ( TCP_KEEPALIVE_SECS ) ) )
61+ . timeout ( Duration :: from_secs ( REQUEST_TIMEOUT_SECS ) )
62+ . connect_timeout ( Duration :: from_secs ( CONNECT_TIMEOUT_SECS ) )
4863 . default_headers ( headers)
49- . pool_max_idle_per_host ( 10 )
64+ . pool_max_idle_per_host ( MAX_IDLE_CONNECTIONS_PER_HOST )
5065 . build ( )
5166 . expect ( "Failed to create HTTP client" )
5267} ) ;
@@ -121,7 +136,6 @@ pub enum Error {
121136 MirrorsFailed ( String ) ,
122137}
123138
124- #[ cfg_attr( feature = "bincode" , derive( Encode , Decode ) ) ]
125139#[ derive( PartialEq , Eq , PartialOrd , Ord , Hash , Debug , Clone , Default ) ]
126140/// A specifier string for Gradle
127141pub struct GradleSpecifier {
@@ -205,7 +219,7 @@ impl GradleSpecifier {
205219 "{}:{}:{}" ,
206220 self . package,
207221 self . artifact,
208- self . identifier. clone ( ) . unwrap_or( "" . to_string ( ) )
222+ self . identifier. as_deref ( ) . unwrap_or( "" )
209223 )
210224 }
211225
@@ -214,17 +228,12 @@ impl GradleSpecifier {
214228 /// Returns Ordering::Greater if self is greater than other
215229 /// Returns Ordering::Less if self is less than other
216230 pub fn compare_versions ( & self , other : & Self ) -> Result < Ordering , Error > {
217- let x = lenient_semver:: parse ( self . version . as_str ( ) ) ;
218- let y = lenient_semver:: parse ( other. version . as_str ( ) ) ;
219-
220- if x. is_err ( ) || y. is_err ( ) {
221- return Err ( Error :: ParseError (
222- "Unable to parse version" . to_string ( ) ,
223- ) ) ;
224- }
231+ let x = lenient_semver:: parse ( self . version . as_str ( ) )
232+ . map_err ( |_| Error :: ParseError ( "Unable to parse version" . to_string ( ) ) ) ?;
233+ let y = lenient_semver:: parse ( other. version . as_str ( ) )
234+ . map_err ( |_| Error :: ParseError ( "Unable to parse version" . to_string ( ) ) ) ?;
225235
226- // safe to unwrap because we already checked for errors
227- Ok ( x. unwrap ( ) . cmp ( & y. unwrap ( ) ) )
236+ Ok ( x. cmp ( & y) )
228237 }
229238}
230239
0 commit comments