mirror of
https://github.com/C9Glax/tranga.git
synced 2025-07-05 10:24:17 +02:00
More logging
This commit is contained in:
API
MangaDownloadClients
Schema
LibraryConnectors
@ -1,48 +1,52 @@
|
||||
using System.Net;
|
||||
using System.Net.Http.Headers;
|
||||
using log4net;
|
||||
|
||||
namespace API.Schema.LibraryConnectors;
|
||||
|
||||
public class NetClient
|
||||
{
|
||||
private static ILog Log = LogManager.GetLogger(typeof(NetClient));
|
||||
|
||||
public static Stream MakeRequest(string url, string authScheme, string auth)
|
||||
{
|
||||
Log.Debug($"Requesting {url}");
|
||||
HttpClient client = new();
|
||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(authScheme, auth);
|
||||
|
||||
HttpRequestMessage requestMessage = new()
|
||||
{
|
||||
HttpClient client = new();
|
||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(authScheme, auth);
|
||||
|
||||
HttpRequestMessage requestMessage = new ()
|
||||
{
|
||||
Method = HttpMethod.Get,
|
||||
RequestUri = new Uri(url)
|
||||
};
|
||||
try
|
||||
{
|
||||
Method = HttpMethod.Get,
|
||||
RequestUri = new Uri(url)
|
||||
};
|
||||
try
|
||||
{
|
||||
HttpResponseMessage response = client.Send(requestMessage);
|
||||
|
||||
HttpResponseMessage response = client.Send(requestMessage);
|
||||
|
||||
if (response.StatusCode is HttpStatusCode.Unauthorized &&
|
||||
response.RequestMessage!.RequestUri!.AbsoluteUri != url)
|
||||
return MakeRequest(response.RequestMessage!.RequestUri!.AbsoluteUri, authScheme, auth);
|
||||
else if (response.IsSuccessStatusCode)
|
||||
return response.Content.ReadAsStream();
|
||||
else
|
||||
return Stream.Null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
switch (e)
|
||||
{
|
||||
case HttpRequestException:
|
||||
|
||||
break;
|
||||
default:
|
||||
throw;
|
||||
}
|
||||
if (response.StatusCode is HttpStatusCode.Unauthorized &&
|
||||
response.RequestMessage!.RequestUri!.AbsoluteUri != url)
|
||||
return MakeRequest(response.RequestMessage!.RequestUri!.AbsoluteUri, authScheme, auth);
|
||||
else if (response.IsSuccessStatusCode)
|
||||
return response.Content.ReadAsStream();
|
||||
else
|
||||
return Stream.Null;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
switch (e)
|
||||
{
|
||||
case HttpRequestException:
|
||||
Log.Debug(e);
|
||||
break;
|
||||
default:
|
||||
throw;
|
||||
}
|
||||
Log.Info("Failed to make request");
|
||||
return Stream.Null;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool MakePost(string url, string authScheme, string auth)
|
||||
public static bool MakePost(string url, string authScheme, string auth)
|
||||
{
|
||||
HttpClient client = new()
|
||||
{
|
||||
|
Reference in New Issue
Block a user