Skip to content

Commit

Permalink
Fix support of the lowercase response headers
Browse files Browse the repository at this point in the history
  • Loading branch information
const-cloudinary authored Feb 1, 2022
1 parent 9fd5228 commit e52e5cc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Api/ApiResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ class ApiResponse extends ArrayObject
public function __construct($responseJson, $headers)
{
$this->headers = $headers;
// According to RFC 2616, header names are case-insensitive.
$lcHeaders = array_change_key_case($headers, CASE_LOWER);

$this->rateLimitResetAt = strtotime(ArrayUtils::get($headers, ['X-FeatureRateLimit-Reset', 0], 0));
$this->rateLimitAllowed = (int)ArrayUtils::get($headers, ['X-FeatureRateLimit-Limit', 0], 0);
$this->rateLimitRemaining = (int)ArrayUtils::get($headers, ['X-FeatureRateLimit-Remaining', 0], 0);
$this->rateLimitResetAt = strtotime(ArrayUtils::get($lcHeaders, ['x-featureratelimit-reset', 0], 0));
$this->rateLimitAllowed = (int)ArrayUtils::get($lcHeaders, ['x-featureratelimit-limit', 0], 0);
$this->rateLimitRemaining = (int)ArrayUtils::get($lcHeaders, ['x-featureratelimit-remaining', 0], 0);

parent::__construct($responseJson);
}
Expand Down
4 changes: 4 additions & 0 deletions tests/Integration/Admin/UsageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ public function testRateLimits()
'rateLimitRemaining' => IsType::TYPE_INT
]
);

self::assertGreaterThan(0, $result->rateLimitAllowed);
self::assertGreaterThan(0, $result->rateLimitRemaining);
self::assertGreaterThan(0, $result->rateLimitResetAt);
}
}

Expand Down

0 comments on commit e52e5cc

Please sign in to comment.