mirror of
https://github.com/Sarsoo/Spotify.NET.git
synced 2024-12-23 14:46:26 +00:00
Made retry-after case insensitive, fixes #475
This commit is contained in:
parent
17a7fd577c
commit
d7baa8f45c
@ -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()
|
||||
{
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user