1
0
Fork 0

Fix github header handling to be case insensitive, fixes rate limit extraction (#11366)

pull/11398/head
Jordi Boggiano 2023-03-20 21:42:14 +01:00
parent 685a2e6be2
commit d3adecf583
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
1 changed files with 6 additions and 6 deletions

View File

@ -161,15 +161,15 @@ class GitHub
foreach ($headers as $header) { foreach ($headers as $header) {
$header = trim($header); $header = trim($header);
if (false === strpos($header, 'X-RateLimit-')) { if (false === stripos($header, 'x-ratelimit-')) {
continue; continue;
} }
[$type, $value] = explode(':', $header, 2); [$type, $value] = explode(':', $header, 2);
switch ($type) { switch (strtolower($type)) {
case 'X-RateLimit-Limit': case 'x-ratelimit-limit':
$rateLimit['limit'] = (int) trim($value); $rateLimit['limit'] = (int) trim($value);
break; break;
case 'X-RateLimit-Reset': case 'x-ratelimit-reset':
$rateLimit['reset'] = date('Y-m-d H:i:s', (int) trim($value)); $rateLimit['reset'] = date('Y-m-d H:i:s', (int) trim($value));
break; break;
} }
@ -206,7 +206,7 @@ class GitHub
public function isRateLimited(array $headers): bool public function isRateLimited(array $headers): bool
{ {
foreach ($headers as $header) { foreach ($headers as $header) {
if (Preg::isMatch('{^X-RateLimit-Remaining: *0$}i', trim($header))) { if (Preg::isMatch('{^x-ratelimit-remaining: *0$}i', trim($header))) {
return true; return true;
} }
} }
@ -224,7 +224,7 @@ class GitHub
public function requiresSso(array $headers): bool public function requiresSso(array $headers): bool
{ {
foreach ($headers as $header) { foreach ($headers as $header) {
if (Preg::isMatch('{^X-GitHub-SSO: required}i', trim($header))) { if (Preg::isMatch('{^x-github-sso: required}i', trim($header))) {
return true; return true;
} }
} }