Made retry-after case insensitive, fixes #475

This commit is contained in:
Jonas Dellinger 2020-07-03 22:59:39 +02:00
parent 17a7fd577c
commit d7baa8f45c
2 changed files with 32 additions and 1 deletions

View File

@ -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<string, string> {
{ "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()
{

View File

@ -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);
}