Skip to content

Commit 57c2e48

Browse files
author
Eirini
committed
feat: added possibilty to inject custom http agent and removed usage of custom tls stack
1 parent a4bfbc8 commit 57c2e48

File tree

3 files changed

+16
-75
lines changed

3 files changed

+16
-75
lines changed

src/Tinify/Client.cs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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
{

src/Tinify/Internal/SSL.cs

Lines changed: 0 additions & 60 deletions
This file was deleted.

src/Tinify/Tinify.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<AssemblyName>Tinify</AssemblyName>
1010
<AssemblyTitle>Tinify</AssemblyTitle>
1111
<Product>Tinify</Product>
12-
<Copyright>Copyright © 2017-2022</Copyright>
12+
<Copyright>Copyright © 2017-2025</Copyright>
1313
<PackageId>Tinify</PackageId>
1414
<PackageTags>tinify;tinypng;tinyjpg;compress;images;api</PackageTags>
1515
<PackageIcon>tinifyicon.png</PackageIcon>

0 commit comments

Comments
 (0)