mirror of
https://github.com/lidarr/lidarr.git
synced 2025-07-16 10:03:51 -07:00
Added RateLimit service to globally manager short duration ratelimits.
This commit is contained in:
parent
fac6b05bb4
commit
78ade3250c
14 changed files with 218 additions and 250 deletions
|
@ -6,6 +6,7 @@ using NLog;
|
|||
using NzbDrone.Common.Cache;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Common.TPL;
|
||||
|
||||
namespace NzbDrone.Common.Http
|
||||
{
|
||||
|
@ -23,12 +24,13 @@ namespace NzbDrone.Common.Http
|
|||
public class HttpClient : IHttpClient
|
||||
{
|
||||
private readonly Logger _logger;
|
||||
|
||||
private readonly IRateLimitService _rateLimitService;
|
||||
private readonly ICached<CookieContainer> _cookieContainerCache;
|
||||
|
||||
public HttpClient(ICacheManager cacheManager, Logger logger)
|
||||
public HttpClient(ICacheManager cacheManager, IRateLimitService rateLimitService, Logger logger)
|
||||
{
|
||||
_logger = logger;
|
||||
_rateLimitService = rateLimitService;
|
||||
ServicePointManager.DefaultConnectionLimit = 12;
|
||||
|
||||
_cookieContainerCache = cacheManager.GetCache<CookieContainer>(typeof(HttpClient));
|
||||
|
@ -36,6 +38,11 @@ namespace NzbDrone.Common.Http
|
|||
|
||||
public HttpResponse Execute(HttpRequest request)
|
||||
{
|
||||
if (request.RateLimit != TimeSpan.Zero)
|
||||
{
|
||||
_rateLimitService.WaitAndPulse(request.Url.Host, request.RateLimit);
|
||||
}
|
||||
|
||||
_logger.Trace(request);
|
||||
|
||||
var webRequest = (HttpWebRequest)WebRequest.Create(request.Url);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue