mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-02 19:00:47 +00:00
handle case insensitive headers when parsing for API rate limiting (#2175)
This commit is contained in:
@@ -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 @@ namespace Octokit
|
||||
|
||||
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<string, string>))) { 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;
|
||||
|
||||
Reference in New Issue
Block a user