Skip to content

Commit 804f313

Browse files
committed
Also use custom http client (added in #5) for downloading files
1 parent 1e29fdd commit 804f313

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

Modio/Client.Download.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,10 @@ public async Task Download(File file, FileInfo dest, CancellationToken cancellat
9393
/// </summary>
9494
public async Task Download(File file, Stream stream, CancellationToken cancellationToken = default)
9595
{
96-
var client = new HttpClient();
9796
try
9897
{
99-
using (var input = await client.GetStreamAsync(file.Download?.BinaryUrl))
100-
{
101-
await input.CopyToAsync(stream, 81920 /* default buffer size */, cancellationToken);
102-
}
98+
using var input = await httpClient.GetStreamAsync(file.Download?.BinaryUrl);
99+
await input.CopyToAsync(stream, 81920 /* default buffer size */, cancellationToken);
103100
}
104101
catch (NotFoundException ex)
105102
{

Modio/Client.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ public partial class Client
2424

2525
private static readonly string X_MODIO_PLATFORM_HDR = "X-Modio-Platform";
2626

27-
private IConnection connection;
27+
private readonly HttpClient httpClient;
28+
29+
private readonly IConnection connection;
2830

2931
/// <summary>
3032
/// Client for the Authentication API.
@@ -49,7 +51,7 @@ public Client(Options options)
4951
var apiKey = options.ApiKey;
5052
var token = options.Token;
5153
var baseAddress = FixBaseUrl(options.BaseUrl);
52-
var httpClient = options.HttpClient ?? new HttpClient();
54+
httpClient = options.HttpClient ?? new HttpClient();
5355

5456
if (options.TargetPlatform != null && !httpClient.DefaultRequestHeaders.Contains(X_MODIO_PLATFORM_HDR))
5557
{
@@ -82,12 +84,13 @@ public Client(Uri baseUrl, Credentials credentials) : this(new Connection(FixBas
8284
/// Initializes a new instance of <see cref="Client"/> with a custom host, custom <paramref name="credentials"/>, and a custom <paramref name="httpClient"/>.
8385
/// </summary>
8486
[Obsolete("Use `Client(Client.Options)` or `Client.GetBuilder(apiKey)` instead")]
85-
public Client(Uri baseUrl, Credentials credentials, HttpClient httpClient) : this(new Connection(FixBaseUrl(baseUrl), credentials.ApiKey, credentials.Token, httpClient))
87+
public Client(Uri baseUrl, Credentials credentials, HttpClient httpClient) : this(new Connection(FixBaseUrl(baseUrl), credentials.ApiKey, credentials.Token, httpClient), httpClient)
8688
{
8789
}
8890

89-
private Client(IConnection connection)
91+
private Client(IConnection connection, HttpClient? httpClient = null)
9092
{
93+
this.httpClient = httpClient ?? new HttpClient();;
9194
this.connection = connection;
9295
Auth = new AuthClient(connection);
9396
Games = new GamesClient(connection);

0 commit comments

Comments
 (0)