mirror of
https://github.com/C9Glax/tranga.git
synced 2025-09-12 04:39:14 +02:00
Custom Request Limits #109
This commit is contained in:
@@ -15,6 +15,14 @@ internal abstract class DownloadClient : GlobalBase
|
||||
foreach (KeyValuePair<byte, int> limit in rateLimitRequestsPerMinute)
|
||||
_rateLimit.Add(limit.Key, TimeSpan.FromMinutes(1).Divide(limit.Value));
|
||||
}
|
||||
|
||||
internal void SetCustomRequestLimit(byte requestType, int limit)
|
||||
{
|
||||
if (_rateLimit.ContainsKey(requestType))
|
||||
_rateLimit[requestType] = TimeSpan.FromMinutes(1).Divide(limit);
|
||||
else
|
||||
_rateLimit.Add(requestType, TimeSpan.FromMinutes(1).Divide(limit));
|
||||
}
|
||||
|
||||
public RequestResult MakeRequest(string url, byte requestType, string? referrer = null, string? clickButton = null)
|
||||
{
|
||||
|
@@ -8,20 +8,16 @@ internal class HttpDownloadClient : DownloadClient
|
||||
{
|
||||
private static readonly HttpClient Client = new()
|
||||
{
|
||||
Timeout = TimeSpan.FromSeconds(60),
|
||||
DefaultRequestHeaders =
|
||||
{
|
||||
UserAgent =
|
||||
{
|
||||
new ProductInfoHeaderValue("Tranga", "0.1")
|
||||
}
|
||||
}
|
||||
Timeout = TimeSpan.FromSeconds(10)
|
||||
};
|
||||
|
||||
|
||||
public HttpDownloadClient(GlobalBase clone, Dictionary<byte, int> rateLimitRequestsPerMinute) : base(clone, rateLimitRequestsPerMinute)
|
||||
{
|
||||
|
||||
if (settings.customUserAgent is null || settings.customUserAgent.Length < 1)
|
||||
Client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("Tranga", "1.0"));
|
||||
else
|
||||
Client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", settings.customUserAgent);
|
||||
}
|
||||
|
||||
protected override RequestResult MakeRequestInternal(string url, string? referrer = null, string? clickButton = null)
|
||||
|
Reference in New Issue
Block a user