From d3adecf58370cd5961db968c2b49f5f102b0d8de Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Mon, 20 Mar 2023 21:42:14 +0100 Subject: [PATCH] Fix github header handling to be case insensitive, fixes rate limit extraction (#11366) --- src/Composer/Util/GitHub.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Composer/Util/GitHub.php b/src/Composer/Util/GitHub.php index 2ac30e3b8..43a635450 100644 --- a/src/Composer/Util/GitHub.php +++ b/src/Composer/Util/GitHub.php @@ -161,15 +161,15 @@ class GitHub foreach ($headers as $header) { $header = trim($header); - if (false === strpos($header, 'X-RateLimit-')) { + if (false === stripos($header, 'x-ratelimit-')) { continue; } [$type, $value] = explode(':', $header, 2); - switch ($type) { - case 'X-RateLimit-Limit': + switch (strtolower($type)) { + case 'x-ratelimit-limit': $rateLimit['limit'] = (int) trim($value); break; - case 'X-RateLimit-Reset': + case 'x-ratelimit-reset': $rateLimit['reset'] = date('Y-m-d H:i:s', (int) trim($value)); break; } @@ -206,7 +206,7 @@ class GitHub public function isRateLimited(array $headers): bool { 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; } } @@ -224,7 +224,7 @@ class GitHub public function requiresSso(array $headers): bool { 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; } }