diff --git a/Octokit.Tests/Exceptions/AbuseExceptionTests.cs b/Octokit.Tests/Exceptions/AbuseExceptionTests.cs index 17b2616c14..80285bc11f 100644 --- a/Octokit.Tests/Exceptions/AbuseExceptionTests.cs +++ b/Octokit.Tests/Exceptions/AbuseExceptionTests.cs @@ -53,6 +53,17 @@ public void WithRetryAfterHeader_PopulatesRetryAfterSeconds() Assert.Equal(30, abuseException.RetryAfterSeconds); } + [Fact] + public void WithRetryAfterCaseInsensitiveHeader_PopulatesRetryAfterSeconds() + { + var headerDictionary = new Dictionary { { "retry-after", "20" } }; + + var response = new Response(HttpStatusCode.Forbidden, null, headerDictionary, "application/json"); + var abuseException = new AbuseException(response); + + Assert.Equal(20, abuseException.RetryAfterSeconds); + } + [Fact] public void WithZeroHeaderValue_RetryAfterSecondsIsZero() { diff --git a/Octokit/Exceptions/AbuseException.cs b/Octokit/Exceptions/AbuseException.cs index 8fceec4f3a..5e94754b95 100644 --- a/Octokit/Exceptions/AbuseException.cs +++ b/Octokit/Exceptions/AbuseException.cs @@ -1,6 +1,8 @@ using System; +using System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; +using System.Linq; using System.Net; #if !NO_SERIALIZABLE using System.Runtime.Serialization; @@ -44,11 +46,11 @@ public AbuseException(IResponse response, Exception innerException) private static int? ParseRetryAfterSeconds(IResponse response) { - string secondsValue; - if (!response.Headers.TryGetValue("Retry-After", out secondsValue)) { return null; } + var header = response.Headers.FirstOrDefault(h => string.Equals(h.Key, "Retry-After", StringComparison.OrdinalIgnoreCase)); + if (header.Equals(default(KeyValuePair))) { return null; } int retrySeconds; - if (!int.TryParse(secondsValue, out retrySeconds)) { return null; } + if (!int.TryParse(header.Value, out retrySeconds)) { return null; } if (retrySeconds < 0) { return null; } return retrySeconds;