Skip to content

Commit

Permalink
Clean up HttpUtils (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaviny82 authored Sep 9, 2024
1 parent 3bb5197 commit 6d73680
Showing 1 changed file with 0 additions and 31 deletions.
31 changes: 0 additions & 31 deletions Natsurainko.FluentCore/Utils/HttpUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,13 @@

namespace Nrk.FluentCore.Utils;

#nullable disable
// TODO: refactor downloading system later

// TOOD: use internal
public static class HttpUtils
{
public static readonly HttpClient HttpClient = new();
public static readonly IDownloader Downloader = new MultipartDownloader(HttpClient, 1024 * 1024, 8, 64);
public static readonly MemoryPool<byte> MemoryPool = MemoryPool<byte>.Shared;

public static HttpResponseMessage HttpGet(
string url,
Tuple<string, string> authorization = default,
HttpCompletionOption httpCompletionOption = HttpCompletionOption.ResponseContentRead)
{
using var requestMessage = new HttpRequestMessage(HttpMethod.Get, url);

if (authorization != null)
requestMessage.Headers.Authorization = new AuthenticationHeaderValue(
authorization.Item1,
authorization.Item2
);

var responseMessage = HttpClient.Send(requestMessage, httpCompletionOption, CancellationToken.None);

if (responseMessage.StatusCode.Equals(HttpStatusCode.Found))
{
string redirectUrl = responseMessage.Headers.Location.AbsoluteUri;

responseMessage.Dispose();
GC.Collect();

return HttpGet(redirectUrl, authorization, httpCompletionOption);
}

return responseMessage;
}

public static string ReadAsString(this HttpContent content)
{
using var stream = content.ReadAsStream();
Expand Down

0 comments on commit 6d73680

Please sign in to comment.