Skip to content

Commit

Permalink
Updating client to be compliant with RFC 2616: case-insensitive headers
Browse files Browse the repository at this point in the history
  • Loading branch information
douglasmiller committed Oct 1, 2020
1 parent 68b2bdb commit 13e2099
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 20 deletions.
17 changes: 10 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
language: php
php:
- 7.1
- 7.0
- 5.6
- 5.5
- 5.4
- hhvm
jobs:
include:
- php: 7.1
- php: 7.0
- php: 5.6
- php: 5.5
dist: precise
- php: 5.4
dist: precise
- php: hhvm
sudo: false
dist: trusty
install:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Recurly PHP Client Library CHANGELOG

## Version 2.9.1 (October 1, 2020)

* Fixed issue with RFC 2616 compliance: headers should be treated as case-insensitive.

## Version 2.9.0 (October 6th, 2017)

This release will upgrade us to API version 2.8.
Expand Down
3 changes: 2 additions & 1 deletion Tests/Recurly/Pager_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ public function testFromStub() {
$relative_url = '/mocks';
$this->client->addResponse('GET', $relative_url, 'pager/index-1-200.xml');

$pager = (new Recurly_Stub('mocks', $relative_url, $this->client))->get();
$stub = new Recurly_Stub('mocks', $relative_url, $this->client);
$pager = $stub->get();
$this->assertInstanceOf('Mock_Pager', $pager);

// Until we've fetched a second page with a next link we'll keep using the
Expand Down
6 changes: 4 additions & 2 deletions Tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ protected function responseFromFixture($filename) {
break;
}
preg_match('/([^:]+): (.*)/', $fixture[$i], $matches);
if (sizeof($matches) > 2)
$headers[$matches[1]] = $matches[2];
if (sizeof($matches) > 2) {
$headerKey = strtolower($matches[1]);
$headers[$headerKey] = $matches[2];
}
}

if ($bodyLineNumber < sizeof($fixture))
Expand Down
8 changes: 5 additions & 3 deletions lib/recurly/client.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Recurly_Client
*/
private $_acceptLanguage = 'en-US';

const API_CLIENT_VERSION = '2.9.0';
const API_CLIENT_VERSION = '2.9.1';
const DEFAULT_ENCODING = 'UTF-8';

const GET = 'GET';
Expand Down Expand Up @@ -193,8 +193,10 @@ private function _getHeaders($headerText)
$returnHeaders = array();
foreach ($headers as &$header) {
preg_match('/([^:]+): (.*)/', $header, $matches);
if (sizeof($matches) > 2)
$returnHeaders[$matches[1]] = $matches[2];
if (sizeof($matches) > 2) {
$headerKey = strtolower($matches[1]);
$returnHeaders[$headerKey] = $matches[2];
}
}
return $returnHeaders;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/recurly/coupon.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function generate($number) {
$response->assertValidResponse();

$coupons = array();
foreach (new Recurly_UniqueCouponCodeList($response->headers['Location'], $this->_client) as $coupon) {
foreach (new Recurly_UniqueCouponCodeList($response->headers['location'], $this->_client) as $coupon) {
$coupons[] = $coupon;
if (count($coupons) == $number) break;
}
Expand Down
8 changes: 4 additions & 4 deletions lib/recurly/pager.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ abstract class Recurly_Pager extends Recurly_Base implements Iterator, Countable
public function count() {
if (isset($this->_href)) {
$headers = Recurly_Base::_head($this->_href, $this->_client);
if (isset($headers['X-Records'])) {
return intval($headers['X-Records']);
if (isset($headers['x-records'])) {
return intval($headers['x-records']);
}
} elseif (isset($this->_objects) && is_array($this->_objects)) {
return count($this->_objects);
Expand Down Expand Up @@ -119,8 +119,8 @@ protected static function _setState($params, $state) {
private function _loadLinks($response) {
$this->_links = array();

if (isset($response->headers['Link'])) {
$links = $response->headers['Link'];
if (isset($response->headers['link'])) {
$links = $response->headers['link'];
preg_match_all('/\<([^>]+)\>; rel=\"([^"]+)\"/', $links, $matches);
if (sizeof($matches) > 2) {
for ($i = 0; $i < sizeof($matches[1]); $i++) {
Expand Down
4 changes: 2 additions & 2 deletions lib/recurly/response.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public function assertSuccessResponse($object)

public function assertValidResponse()
{
if (!empty($this->headers['Recurly-Deprecated'])) {
error_log("WARNING: API version {$this->headers['X-Api-Version']} is deprecated and will only be available until {$this->headers['Recurly-Sunset-Date']}. Please upgrade the Recurly PHP client.");
if (!empty($this->headers['recurly-deprecated'])) {
error_log("WARNING: API version {$this->headers['x-api-version']} is deprecated and will only be available until {$this->headers['recurly-sunset-date']}. Please upgrade the Recurly PHP client.");
}

// Successful response code
Expand Down

0 comments on commit 13e2099

Please sign in to comment.