Added common language enum. Fixed "romaji" spelling. More UI updates.
This commit is contained in:
@@ -1,16 +1,25 @@
|
||||
namespace MangaReader.Core.HttpService;
|
||||
|
||||
public class HttpService : IHttpService
|
||||
public class HttpService(HttpClient httpClient) : IHttpService
|
||||
{
|
||||
private readonly HttpClient _httpClient;
|
||||
public Task<string> GetStringAsync(string url, CancellationToken cancellationToken)
|
||||
=> GetStringAsync(url, new Dictionary<string, string>(), cancellationToken);
|
||||
|
||||
public HttpService(HttpClient httpClient)
|
||||
public async Task<string> GetStringAsync(string url, IDictionary<string, string> headers, CancellationToken cancellationToken)
|
||||
{
|
||||
using HttpRequestMessage request = new(HttpMethod.Get, url);
|
||||
|
||||
foreach (KeyValuePair<string, string> header in headers)
|
||||
{
|
||||
request.Headers.TryAddWithoutValidation(header.Key, header.Value);
|
||||
}
|
||||
|
||||
//httpClient.DefaultRequestHeaders.UserAgent.ParseAdd("MangaReader/1.0");
|
||||
httpClient.DefaultRequestHeaders.UserAgent.ParseAdd("Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:139.0) Gecko/20100101 Firefox/139.0");
|
||||
|
||||
_httpClient = httpClient;
|
||||
}
|
||||
using HttpResponseMessage response = await httpClient.SendAsync(request, cancellationToken);
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
public Task<string> GetStringAsync(string url, CancellationToken cancellationToken)
|
||||
=> _httpClient.GetStringAsync(url, cancellationToken);
|
||||
return await response.Content.ReadAsStringAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user