diff --git a/SpotifyAPI.Web.Tests/Http/SimpleRetryHandlerTest.cs b/SpotifyAPI.Web.Tests/RetryHandlers/SimpleRetryHandlerTest.cs similarity index 86% rename from SpotifyAPI.Web.Tests/Http/SimpleRetryHandlerTest.cs rename to SpotifyAPI.Web.Tests/RetryHandlers/SimpleRetryHandlerTest.cs index 4e13f516..cc0e77fc 100644 --- a/SpotifyAPI.Web.Tests/Http/SimpleRetryHandlerTest.cs +++ b/SpotifyAPI.Web.Tests/RetryHandlers/SimpleRetryHandlerTest.cs @@ -11,6 +11,35 @@ namespace SpotifyAPI.Web [TestFixture] public class SimpleRetryHandlerTest { + [Test] + public void HandleRetry_WorksWithLowerCaseHeader() + { + var setup = new Setup(); + setup.Response.SetupGet(r => r.StatusCode).Returns(HttpStatusCode.TooManyRequests); + setup.Response.SetupGet(r => r.Headers).Returns(new Dictionary { + { "retry-after", "50" } + }); + + var retryCalled = 0; + setup.Retry = (IRequest request) => + { + retryCalled++; + return Task.FromResult(setup.Response.Object); + }; + + var handler = new SimpleRetryHandler(setup.Sleep.Object) + { + TooManyRequestsConsumesARetry = true, + RetryTimes = 1 + }; + Assert.DoesNotThrowAsync(async () => + { + var response = await handler.HandleRetry(setup.Request.Object, setup.Response.Object, setup.Retry); + }); + + Assert.AreEqual(1, retryCalled); + } + [Test] public async Task HandleRetry_TooManyRequestsWithNoSuccess() { diff --git a/SpotifyAPI.Web/RetryHandlers/SimpleRetryHandler.cs b/SpotifyAPI.Web/RetryHandlers/SimpleRetryHandler.cs index bd18ac38..275c7d8f 100644 --- a/SpotifyAPI.Web/RetryHandlers/SimpleRetryHandler.cs +++ b/SpotifyAPI.Web/RetryHandlers/SimpleRetryHandler.cs @@ -57,7 +57,9 @@ namespace SpotifyAPI.Web { return null; } - if (int.TryParse(response.Headers["Retry-After"], out int secondsToWait)) + if ( + int.TryParse(response.Headers.GetValueOrDefault("Retry-After"), out int secondsToWait) + || int.TryParse(response.Headers.GetValueOrDefault("retry-after"), out secondsToWait)) { return TimeSpan.FromSeconds(secondsToWait); }