Fix github header handling to be case insensitive, fixes rate limit extraction (#11366)
parent
685a2e6be2
commit
d3adecf583
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue