Skip to content

Commit 08b8a9e

Browse files
author
JLTRY
committed
JSon response not detected
case of header = Array ( [0] => application/json; charset=utf-8 )
1 parent 58ca7b9 commit 08b8a9e

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/Client.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,28 @@ public function __construct($options = [], ?Http $http = null, ?Input $input = n
7979
$this->application = $application;
8080
}
8181

82+
/**
83+
* Tests if given response contains JSON header
84+
*
85+
* @param Response $response The response object
86+
*
87+
* @return boolean
88+
*
89+
*/
90+
private static function isJsonResponse($response)
91+
{
92+
foreach (['Content-Type', 'content-type'] as $type) {
93+
if (array_key_exists($type, $response->headers)) {
94+
$content_type = is_array($response->headers[$type]) ?
95+
$response->headers[$type][0] : $response->headers[$type];
96+
if (strpos($content_type, 'application/json') !== false) {
97+
return true;
98+
}
99+
}
100+
}
101+
return false;
102+
}
103+
82104
/**
83105
* Get the access token or redirect to the authentication URL.
84106
*
@@ -112,7 +134,7 @@ public function authenticate()
112134
);
113135
}
114136

115-
if (in_array('application/json', $response->getHeader('Content-Type'))) {
137+
if ($this->isJsonResponse($response)) {
116138
$token = array_merge(json_decode($response->body, true), ['created' => time()]);
117139
} else {
118140
parse_str($response->body, $token);

0 commit comments

Comments
 (0)