From 3accc6c1b4c7dba8377ea9b820e65b17a67403f6 Mon Sep 17 00:00:00 2001 From: Doug Miller Date: Thu, 1 Oct 2020 11:02:13 -0500 Subject: [PATCH] Updating client to be compliant with RFC 2616: case-insensitive headers --- CHANGELOG.md | 5 ++ lib/recurly/client.php | 8 +-- lib/recurly/pager.php | 8 +-- test/fixtures/transactions/show-200-error.xml | 54 +++++++++++++++++++ test/recurly/recurlyjs_test.php | 2 +- test/test_helpers.php | 6 ++- 6 files changed, 73 insertions(+), 10 deletions(-) create mode 100644 test/fixtures/transactions/show-200-error.xml diff --git a/CHANGELOG.md b/CHANGELOG.md index 14580013..deebf4e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Recurly PHP Client Library CHANGELOG +## Version 2.0.9 (October 1, 2020) + +* Fixed issue with RFC 2616 compliance: headers should be treated as case-insensitive. + +## Version 2.0.8 (February 7, 2012) * Better parsing of transaction errors on one-time transaction requests. * Parse an array of plan_codes as strings in the coupon response. diff --git a/lib/recurly/client.php b/lib/recurly/client.php index e4299d7e..7d7ef3e4 100644 --- a/lib/recurly/client.php +++ b/lib/recurly/client.php @@ -29,7 +29,7 @@ class Recurly_Client */ private $_acceptLanguage = 'en-US'; - const API_CLIENT_VERSION = '2.0.7'; + const API_CLIENT_VERSION = '2.0.9'; const DEFAULT_ENCODING = 'UTF-8'; const GET = 'GET'; @@ -160,8 +160,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; } diff --git a/lib/recurly/pager.php b/lib/recurly/pager.php index cb695ac1..a6c496e8 100644 --- a/lib/recurly/pager.php +++ b/lib/recurly/pager.php @@ -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++) { @@ -135,8 +135,8 @@ private function _loadLinks($response) { */ private function _loadRecordCount($response) { - if (empty($this->_count) && isset($response->headers['X-Records'])) - $this->_count = intval($response->headers['X-Records']); + if (empty($this->_count) && isset($response->headers['x-records'])) + $this->_count = intval($response->headers['x-records']); } /** diff --git a/test/fixtures/transactions/show-200-error.xml b/test/fixtures/transactions/show-200-error.xml new file mode 100644 index 00000000..ea35bd73 --- /dev/null +++ b/test/fixtures/transactions/show-200-error.xml @@ -0,0 +1,54 @@ +HTTP/1.1 200 OK +Content-Type: application/xml; charset=utf-8 + + + + + abcdef1234567890 + purchase + 30000 + 0 + USD + declined + + true + true + true + + invalid_card_number + hard + The credit card number is not valid. The customer needs to try a different number. + Your card number is not valid. Please update your card number. + + + + + + 2011-04-30T12:00:00Z +
+ + gob + George Oscar + Bluth + + gobias@bluth-company.com + + + + + + + + + + + + visa + 2011 + 12 + 411111 + 1111 + + +
+
diff --git a/test/recurly/recurlyjs_test.php b/test/recurly/recurlyjs_test.php index b5df3768..86c17813 100644 --- a/test/recurly/recurlyjs_test.php +++ b/test/recurly/recurlyjs_test.php @@ -7,7 +7,7 @@ function time_difference($timestamp) { } // Expose a protected static method for testing - function testGenerateSignature($claim, $values, $timestamp = null) { + static function testGenerateSignature($claim, $values, $timestamp = null) { return Recurly_js::_generateSignature($claim, $values, $timestamp); } } diff --git a/test/test_helpers.php b/test/test_helpers.php index 938d6cf3..630a89d6 100644 --- a/test/test_helpers.php +++ b/test/test_helpers.php @@ -19,8 +19,10 @@ function loadFixture($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))