From 0580d1d74b889907210bd4848f7159b3bf746d92 Mon Sep 17 00:00:00 2001 From: JLTRY Date: Sun, 21 Sep 2025 14:29:23 +0200 Subject: [PATCH 1/5] JSon response not detected case of header = Array ( [0] => application/json; charset=utf-8 ) correct phpstan --- src/Client.php | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index 4228b73e..289a3310 100644 --- a/src/Client.php +++ b/src/Client.php @@ -13,6 +13,7 @@ use Joomla\Http\Exception\UnexpectedResponseException; use Joomla\Http\Http; use Joomla\Http\HttpFactory; +use Joomla\Http\Response; use Joomla\Input\Input; use Joomla\Uri\Uri; @@ -79,6 +80,25 @@ public function __construct($options = [], ?Http $http = null, ?Input $input = n $this->application = $application; } + /** + * Tests if given response contains JSON header + * + * @param Response $response The response object + * + * @return boolean + * + */ + private static function isJsonResponse(Response $response) + { + foreach (['Content-Type', 'content-type'] as $type) { + $content_type = $response->getHeader($type)[0]; + if (strpos($content_type, 'application/json') !== false) { + return true; + } + } + return false; + } + /** * Get the access token or redirect to the authentication URL. * @@ -114,7 +134,7 @@ public function authenticate() ); } - if (in_array('application/json', $response->getHeader('Content-Type'))) { + if ($this->isJsonResponse($response)) { $token = array_merge(json_decode((string) $response->getBody(), true), ['created' => time()]); } else { parse_str((string) $response->getBody(), $token); From 37762da806dd8c5a152d7cfac0bd28ef8920243f Mon Sep 17 00:00:00 2001 From: JLTRY Date: Wed, 7 Jan 2026 19:38:02 +0100 Subject: [PATCH 2/5] Remove static function attribute following review --- src/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index 289a3310..e43561cc 100644 --- a/src/Client.php +++ b/src/Client.php @@ -88,7 +88,7 @@ public function __construct($options = [], ?Http $http = null, ?Input $input = n * @return boolean * */ - private static function isJsonResponse(Response $response) + private function isJsonResponse(Response $response) { foreach (['Content-Type', 'content-type'] as $type) { $content_type = $response->getHeader($type)[0]; From d9e66b9de9cc1742f7813434ca00f7cfe06bfa93 Mon Sep 17 00:00:00 2001 From: JLTRY Date: Thu, 8 Jan 2026 15:15:58 +0100 Subject: [PATCH 3/5] update after review do not use strpos use str_starts_with instead. getHeader() is case insensitive --- src/Client.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Client.php b/src/Client.php index e43561cc..4a021635 100644 --- a/src/Client.php +++ b/src/Client.php @@ -90,9 +90,8 @@ public function __construct($options = [], ?Http $http = null, ?Input $input = n */ private function isJsonResponse(Response $response) { - foreach (['Content-Type', 'content-type'] as $type) { - $content_type = $response->getHeader($type)[0]; - if (strpos($content_type, 'application/json') !== false) { + foreach ($response->getHeader('Content-Type') as $type) { + if (str_starts_with($type, 'application/json')) { return true; } } From ba96484c6ae4b26399139d9f55e121fd40d34074 Mon Sep 17 00:00:00 2001 From: JLTRY Date: Fri, 30 Jan 2026 14:27:23 +0100 Subject: [PATCH 4/5] correct refresh token for json UTF8 --- src/Client.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index 4a021635..25606376 100644 --- a/src/Client.php +++ b/src/Client.php @@ -407,7 +407,8 @@ public function refreshToken($token = null) ); } - if (in_array('application/json', $response->getHeader('Content-Type'))) { + + if ($this->isJsonResponse($response)) { $token = array_merge(json_decode((string) $response->getBody(), true), ['created' => time()]); } else { parse_str((string) $response->getBody(), $token); From aaedd8f37c8bd6c85b8c81441f238234c00e34a2 Mon Sep 17 00:00:00 2001 From: JLTRY Date: Thu, 2 Apr 2026 12:26:48 +0200 Subject: [PATCH 5/5] change private to protected for isJsonResponse --- src/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index 25606376..b6eb8b7b 100644 --- a/src/Client.php +++ b/src/Client.php @@ -88,7 +88,7 @@ public function __construct($options = [], ?Http $http = null, ?Input $input = n * @return boolean * */ - private function isJsonResponse(Response $response) + protected function isJsonResponse(Response $response) { foreach ($response->getHeader('Content-Type') as $type) { if (str_starts_with($type, 'application/json')) {