@@ -11,7 +11,14 @@ namespace NGitLab.Http;
1111/// </summary>
1212internal static class HttpClientManager
1313{
14- private static readonly Lazy < HttpClient > s_defaultClient = new ( ( ) => CreateHttpClient ( null , null ) ) ;
14+ /// <summary>
15+ /// Configure the default client-side timeout when calling GitLab.
16+ /// Some GitLab endpoints are really slow, so use a much larger value
17+ /// than .NET's 100-second default.
18+ /// </summary>
19+ private static readonly TimeSpan s_defaultHttpClientTimeout = TimeSpan . FromMinutes ( 5 ) ;
20+
21+ private static readonly Lazy < HttpClient > s_defaultClient = new ( ( ) => CreateHttpClient ( proxy : null , timeout : null ) ) ;
1522
1623 /// <summary>
1724 /// Gets the singleton HttpClient instance for default scenarios.
@@ -31,18 +38,16 @@ public static HttpClient CreateHttpClient(IWebProxy proxy, TimeSpan? timeout)
3138 AutomaticDecompression = DecompressionMethods . GZip | DecompressionMethods . Deflate ,
3239 } ;
3340
34- if ( proxy != null )
41+ if ( proxy is not null )
3542 {
3643 handler . Proxy = proxy ;
3744 handler . UseProxy = true ;
3845 }
3946
40- var client = new HttpClient ( handler ) ;
41-
42- if ( timeout . HasValue )
47+ var client = new HttpClient ( handler )
4348 {
44- client . Timeout = timeout . Value ;
45- }
49+ Timeout = timeout ?? s_defaultHttpClientTimeout ,
50+ } ;
4651
4752 return client ;
4853 }
@@ -55,13 +60,13 @@ public static HttpClient CreateHttpClient(IWebProxy proxy, TimeSpan? timeout)
5560 /// <returns>An HttpClient instance.</returns>
5661 public static HttpClient GetOrCreateHttpClient ( RequestOptions options )
5762 {
58- if ( options . HttpClientFactory != null )
63+ if ( options . HttpClientFactory is not null )
5964 {
6065 return options . HttpClientFactory ( options ) ;
6166 }
6267
6368 // Use singleton if no custom proxy or timeout
64- if ( options . Proxy == null && ! options . HttpClientTimeout . HasValue )
69+ if ( options . Proxy is null && ! options . HttpClientTimeout . HasValue )
6570 {
6671 return DefaultClient ;
6772 }
0 commit comments