From 9f4d16eb0f7fefba4f6f8c5ccaf7700a94e303c8 Mon Sep 17 00:00:00 2001 From: Ramon Kleiss Date: Tue, 9 Mar 2021 13:30:47 +0100 Subject: [PATCH 1/2] Reset response headers before sending requests --- src/Client.php | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/Client.php b/src/Client.php index 2e818a5..25515dd 100644 --- a/src/Client.php +++ b/src/Client.php @@ -232,7 +232,7 @@ public function addProductPart($idproduct, $params) public function updateProductPartAmount($idproduct, $idproductpart, $amount) { $params = ['amount' => $amount]; - + return $this->sendRequest('/products/' . $idproduct . '/parts/'.$idproductpart, $params, self::METHOD_PUT); } @@ -497,7 +497,7 @@ public function getSuppliers($filters = []) { return $this->sendRequest('/suppliers', null, null, $filters); } - + public function getAllSuppliers($filters = []) { return $this->getAllResults('supplier', $filters); @@ -699,7 +699,7 @@ public function getTags($filters = []) { return $this->sendRequest('/tags', [], self::METHOD_GET, $filters); } - + public function getAllTags($filters = []) { return $this->getAllResults('tag', $filters); @@ -763,7 +763,7 @@ public function processBackorders() { return $this->sendRequest('/backorders/process', null, self::METHOD_POST); } - + public function deleteBackorder($idbackorder) { return $this->sendRequest('/backorders/' . $idbackorder, null, self::METHOD_DELETE); @@ -807,7 +807,7 @@ public function getShippingProviders() { return $this->sendRequest('/shippingproviders'); } - + /* * Product fields */ @@ -820,7 +820,7 @@ public function getProductField($idproductfield) { return $this->sendRequest('/productfields/' . $idproductfield); } - + /* * Order fields */ @@ -833,7 +833,7 @@ public function getOrderField($idorderfield) { return $this->sendRequest('/orderfields/' . $idorderfield); } - + /* * Customer fields */ @@ -953,7 +953,7 @@ public function getAllResults($entity, $filters = []) return ['success' => true, 'data' => $collection]; } - + /* * Yield all results from the API */ @@ -1051,6 +1051,7 @@ public function enableRetryOnRateLimitHit() public function sendRequest($endpoint, $params = [], $method = self::METHOD_GET, $filters = []) { $endpoint = $this->getEndpoint($endpoint, $filters); + $this->debug('URL: ' . $this->getUrl($endpoint)); $curlSession = curl_init(); @@ -1073,6 +1074,7 @@ public function sendRequest($endpoint, $params = [], $method = self::METHOD_GET, $this->setPostData($curlSession, $method, $params); $this->setSslVerification($curlSession); + $this->resetRawResponseHeaders(); $apiResult = curl_exec($curlSession); $headerInfo = curl_getinfo($curlSession); @@ -1171,6 +1173,11 @@ protected function parseRawHeaders() return $parsedHeaders; } + protected function resetRawResponseHeaders() + { + $this->rawResponseHeaders = []; + } + protected function getRemainingRateLimit(array $apiResultHeaders) { return (array_key_exists('x-ratelimit-remaining', $apiResultHeaders)) ? $apiResultHeaders['x-ratelimit-remaining'] : null; From 2d00defc6eb32a277e655cf5bcc617d7768ea8f2 Mon Sep 17 00:00:00 2001 From: Ramon Kleiss Date: Tue, 9 Mar 2021 13:37:25 +0100 Subject: [PATCH 2/2] Reset response headers after receiving response --- src/Client.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Client.php b/src/Client.php index 25515dd..6877e4f 100644 --- a/src/Client.php +++ b/src/Client.php @@ -1074,7 +1074,6 @@ public function sendRequest($endpoint, $params = [], $method = self::METHOD_GET, $this->setPostData($curlSession, $method, $params); $this->setSslVerification($curlSession); - $this->resetRawResponseHeaders(); $apiResult = curl_exec($curlSession); $headerInfo = curl_getinfo($curlSession); @@ -1083,6 +1082,7 @@ public function sendRequest($endpoint, $params = [], $method = self::METHOD_GET, $apiResultJson = json_decode($apiResult, true); $apiResultHeaders = $this->parseRawHeaders(); + $this->resetRawHeaders(); $result = []; $result['success'] = false; @@ -1173,7 +1173,7 @@ protected function parseRawHeaders() return $parsedHeaders; } - protected function resetRawResponseHeaders() + protected function resetRawHeaders() { $this->rawResponseHeaders = []; }