Skip to content

Commit 9940135

Browse files
authored
Use HttpMessageHandler instead of HttpClientHandler (#26)
Co-authored-by: Eric Busch <ebusch@gowithfloat.com>
1 parent 221043f commit 9940135

4 files changed

Lines changed: 10 additions & 10 deletions

File tree

Float.FileDownloader.Tests/DownloadRequest.Tests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public async Task TestCustomHandler()
8888
{
8989
var mock = new Mock<HttpClientHandler>();
9090
mock.Protected().Setup<Task<HttpResponseMessage>>("SendAsync", ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>()).Returns(Task.FromResult(new HttpResponseMessage()));
91-
await DownloadRequest.Download(new HttpRequestMessage(HttpMethod.Get, TestUriString()), TempFilePath(), clientHandler: mock.Object);
91+
await DownloadRequest.Download(new HttpRequestMessage(HttpMethod.Get, TestUriString()), TempFilePath(), messageHandler: mock.Object);
9292
mock.Protected().Verify("SendAsync", Times.AtLeastOnce(), ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>());
9393
}
9494
}

Float.FileDownloader.Tests/FileDownloadRequest.Tests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public async Task TestCustomHandler()
165165
var destination = new Uri(TempFilePath());
166166
var mock = new Mock<HttpClientHandler>();
167167
mock.Protected().Setup<Task<HttpResponseMessage>>("SendAsync", ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>()).Returns(Task.FromResult(new HttpResponseMessage()));
168-
await FileDownloadRequest.DownloadFile(provider, file, destination, clientHandler: mock.Object);
168+
await FileDownloadRequest.DownloadFile(provider, file, destination, messageHandler: mock.Object);
169169
mock.Protected().Verify("SendAsync", Times.AtLeastOnce(), ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>());
170170
}
171171

Float.FileDownloader/DownloadRequest.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ public static class DownloadRequest
2020
/// <param name="progressReporter">Optionally, a progress reporter can be provided to receive updated on download status.</param>
2121
/// <param name="cancellationTokenSource">Optionally, a cancellation token can be specified to allow the caller to cancel the download.</param>
2222
/// <param name="bufferSize">The size of the buffer for writing to disk. 4096 by default.</param>
23-
/// <param name="clientHandler">Optionally, the client handler.</param>
24-
public static async Task<HttpResponseMessage> Download(HttpRequestMessage request, string destination, IProgress<IDownloadBytesProgress> progressReporter = null, CancellationTokenSource cancellationTokenSource = null, int bufferSize = 4096, HttpClientHandler clientHandler = null)
23+
/// <param name="messageHandler">Optionally, the message handler.</param>
24+
public static async Task<HttpResponseMessage> Download(HttpRequestMessage request, string destination, IProgress<IDownloadBytesProgress> progressReporter = null, CancellationTokenSource cancellationTokenSource = null, int bufferSize = 4096, HttpMessageHandler messageHandler = null)
2525
{
2626
if (request == null)
2727
{
@@ -33,12 +33,12 @@ public static async Task<HttpResponseMessage> Download(HttpRequestMessage reques
3333
throw new ArgumentException(nameof(destination));
3434
}
3535

36-
if (clientHandler == null)
36+
if (messageHandler == null)
3737
{
38-
clientHandler = new HttpClientHandler();
38+
messageHandler = new HttpClientHandler();
3939
}
4040

41-
using (var client = new HttpClient(clientHandler))
41+
using (var client = new HttpClient(messageHandler))
4242
{
4343
if (cancellationTokenSource == null)
4444
{

Float.FileDownloader/FileDownloadRequest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ public static class FileDownloadRequest
3131
/// <param name="downloadDestination">Absolute URI of the location to save the downloaded file.</param>
3232
/// <param name="status">Optionally, receive status updates about the download progress of the file.</param>
3333
/// <param name="fileProcessor">Optionally, specify an IFileProcessor to process or manipulate the file after it downloads.</param>
34-
/// <param name="clientHandler">Optionally, the client handler.</param>
35-
public static async Task<HttpResponseMessage> DownloadFile(IRemoteFileProvider fileProvider, IRemoteFile file, Uri downloadDestination, DownloadStatus status = null, IRemoteFileProcessor fileProcessor = null, HttpClientHandler clientHandler = null)
34+
/// <param name="messageHandler">Optionally, the message handler.</param>
35+
public static async Task<HttpResponseMessage> DownloadFile(IRemoteFileProvider fileProvider, IRemoteFile file, Uri downloadDestination, DownloadStatus status = null, IRemoteFileProcessor fileProcessor = null, HttpMessageHandler messageHandler = null)
3636
{
3737
if (fileProvider == null)
3838
{
@@ -80,7 +80,7 @@ public static async Task<HttpResponseMessage> DownloadFile(IRemoteFileProvider f
8080

8181
try
8282
{
83-
response = await DownloadRequest.Download(request, temporaryDownloadPath, progressReporter, token, clientHandler: clientHandler);
83+
response = await DownloadRequest.Download(request, temporaryDownloadPath, progressReporter, token, messageHandler: messageHandler);
8484
}
8585
catch (Exception e)
8686
{

0 commit comments

Comments
 (0)