From 08b8a9ef1fb8a027f60282053f7b9e2f4cda1a41 Mon Sep 17 00:00:00 2001 From: JLTRY Date: Sun, 21 Sep 2025 14:29:23 +0200 Subject: [PATCH 1/2] JSon response not detected case of header = Array ( [0] => application/json; charset=utf-8 ) --- src/Client.php | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index 74153081..bb262798 100644 --- a/src/Client.php +++ b/src/Client.php @@ -79,6 +79,28 @@ 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) + { + foreach (['Content-Type', 'content-type'] as $type) { + if (array_key_exists($type, $response->headers)) { + $content_type = is_array($response->headers[$type]) ? + $response->headers[$type][0] : $response->headers[$type]; + if (strpos($content_type, 'application/json') !== false) { + return true; + } + } + } + return false; + } + /** * Get the access token or redirect to the authentication URL. * @@ -112,7 +134,7 @@ public function authenticate() ); } - if (in_array('application/json', $response->getHeader('Content-Type'))) { + if ($this->isJsonResponse($response)) { $token = array_merge(json_decode($response->body, true), ['created' => time()]); } else { parse_str($response->body, $token); From a9a38827e22962ab45ae73fef7a44cbb36e81184 Mon Sep 17 00:00:00 2001 From: JLTRY Date: Sun, 21 Sep 2025 16:26:33 +0200 Subject: [PATCH 2/2] correct phpstan --- src/Client.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Client.php b/src/Client.php index bb262798..93916786 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; @@ -82,12 +83,12 @@ public function __construct($options = [], ?Http $http = null, ?Input $input = n /** * Tests if given response contains JSON header * - * @param Response $response The response object + * @param Response $response The response object * * @return boolean * */ - private static function isJsonResponse($response) + private static function isJsonResponse(Response $response) { foreach (['Content-Type', 'content-type'] as $type) { if (array_key_exists($type, $response->headers)) {