From 7ef1ca8a007bc8184e15e1a06bda508cd0ea8677 Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Thu, 29 Sep 2016 21:40:52 +0200 Subject: [PATCH] Fixed: Tweaked ratelimit logic for rarbg api. --- src/NzbDrone.Common/Http/HttpRequestBuilder.cs | 13 +++++++++++-- .../Indexers/Rarbg/RarbgTokenProvider.cs | 3 ++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/NzbDrone.Common/Http/HttpRequestBuilder.cs b/src/NzbDrone.Common/Http/HttpRequestBuilder.cs index 95d7b5c10..b75be10f1 100644 --- a/src/NzbDrone.Common/Http/HttpRequestBuilder.cs +++ b/src/NzbDrone.Common/Http/HttpRequestBuilder.cs @@ -22,6 +22,7 @@ public class HttpRequestBuilder public bool UseSimplifiedUserAgent { get; set; } public bool AllowAutoRedirect { get; set; } public bool ConnectionKeepAlive { get; set; } + public TimeSpan RateLimit { get; set; } public bool LogResponseContent { get; set; } public NetworkCredential NetworkCredential { get; set; } public Dictionary Cookies { get; private set; } @@ -75,7 +76,7 @@ public virtual HttpRequestBuilder Clone() protected virtual HttpUri CreateUri() { var url = BaseUrl.CombinePath(ResourceUrl).AddQueryParams(QueryParams.Concat(SuffixQueryParams)); - + if (Segments.Any()) { var fullUri = url.FullUri; @@ -103,6 +104,7 @@ protected virtual void Apply(HttpRequest request) request.UseSimplifiedUserAgent = UseSimplifiedUserAgent; request.AllowAutoRedirect = AllowAutoRedirect; request.ConnectionKeepAlive = ConnectionKeepAlive; + request.RateLimit = RateLimit; request.LogResponseContent = LogResponseContent; if (NetworkCredential != null) @@ -245,6 +247,13 @@ public virtual HttpRequestBuilder KeepAlive(bool keepAlive = true) return this; } + public virtual HttpRequestBuilder WithRateLimit(double seconds) + { + RateLimit = TimeSpan.FromSeconds(seconds); + + return this; + } + public virtual HttpRequestBuilder Post() { Method = HttpMethod.POST; @@ -371,4 +380,4 @@ public virtual HttpRequestBuilder AddFormUpload(string name, string fileName, by } } -} \ No newline at end of file +} diff --git a/src/NzbDrone.Core/Indexers/Rarbg/RarbgTokenProvider.cs b/src/NzbDrone.Core/Indexers/Rarbg/RarbgTokenProvider.cs index f7ed23bcb..628faac41 100644 --- a/src/NzbDrone.Core/Indexers/Rarbg/RarbgTokenProvider.cs +++ b/src/NzbDrone.Core/Indexers/Rarbg/RarbgTokenProvider.cs @@ -30,7 +30,8 @@ public string GetToken(RarbgSettings settings) return _tokenCache.Get(settings.BaseUrl, () => { var requestBuilder = new HttpRequestBuilder(settings.BaseUrl.Trim('/')) - .Resource("/pubapi_v2.php?get_token=get_token") + .WithRateLimit(3.0) + .Resource("/pubapi_v2.php?get_token=get_token&app_id=Sonarr") .Accept(HttpAccept.Json); if (settings.CaptchaToken.IsNotNullOrWhiteSpace())