@@ -26,33 +26,34 @@ internal sealed class ErrorData
2626 public static readonly Uri ApiEndpoint = new ( "https://api.tinify.com" ) ;
2727
2828 public static readonly short RetryCount = 1 ;
29- public static ushort RetryDelay { get ; internal set ; } = 500 ;
29+ public static ushort RetryDelay { get ; internal set ; } = 500 ;
3030
3131 public static readonly string UserAgent = Internal . Platform . UserAgent ;
3232
3333 private readonly HttpClient _client ;
3434
35- public Client ( string key , string appIdentifier = null , string proxy = null )
35+ public Client ( string key , string appIdentifier = null , string proxy = null , HttpClient customHttpClient = null )
3636 {
3737 var handler = new HttpClientHandler ( ) ;
38- if ( ! RuntimeInformation . IsOSPlatform ( OSPlatform . OSX ) )
39- {
40- // TLS is extremely spotty and differs per version on MacOS
41- handler . ServerCertificateCustomValidationCallback = Internal . SSL . ValidationCallback ;
42- } ;
43-
4438 if ( proxy != null )
4539 {
4640 handler . Proxy = new Internal . Proxy ( proxy ) ;
4741 handler . UseProxy = true ;
4842 }
4943
50- _client = new HttpClient ( handler )
44+ if ( customHttpClient != null )
5145 {
52- BaseAddress = ApiEndpoint ,
53- Timeout = Timeout . InfiniteTimeSpan ,
54- } ;
55-
46+ _client = customHttpClient ;
47+ _client . BaseAddress = ApiEndpoint ;
48+ }
49+ else
50+ {
51+ _client = new HttpClient ( handler )
52+ {
53+ BaseAddress = ApiEndpoint ,
54+ Timeout = Timeout . InfiniteTimeSpan ,
55+ } ;
56+ }
5657
5758 var userAgent = UserAgent ;
5859 if ( appIdentifier != null )
@@ -155,7 +156,7 @@ public async Task<HttpResponseMessage> Request(Method method, Uri url, HttpConte
155156 {
156157 var content = await response . Content . ReadAsStringAsync ( ) . ConfigureAwait ( false ) ;
157158 data = JsonSerializer . Deserialize < ErrorData > ( content ) ??
158- new ErrorData ( ) { Message = "Response content was empty." , Error = "ParseError" } ;
159+ new ErrorData ( ) { Message = "Response content was empty." , Error = "ParseError" } ;
159160 }
160161 catch ( Exception err )
161162 {
0 commit comments