bug #38551 Remove content-type check on toArray methods (jderusse)

This PR was merged into the 4.4 branch.

Discussion
----------

Remove content-type check on toArray methods

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | /
| License       | MIT
| Doc PR        | /

Sometime the server provides a generic content type `text/plain` and prevent people using the `toArray` method. (ie. AWS metadata endpoint).

This PR removes the check on the content-type.
People trying to json_decode something else will ends with a `JsonException` anyway.

Commits
-------

1c8fff18f9 Remove content-type check on toArray methods
This commit is contained in:
Fabien Potencier 2020-10-13 19:09:02 +02:00
commit 9cc3baa57e

View File

@ -143,12 +143,6 @@ trait ResponseTrait
return $this->jsonData;
}
$contentType = $this->headers['content-type'][0] ?? 'application/json';
if (!preg_match('/\bjson\b/i', $contentType)) {
throw new JsonException(sprintf('Response content-type is "%s" while a JSON-compatible one was expected for "%s".', $contentType, $this->getInfo('url')));
}
try {
$content = json_decode($content, true, 512, \JSON_BIGINT_AS_STRING | (\PHP_VERSION_ID >= 70300 ? \JSON_THROW_ON_ERROR : 0));
} catch (\JsonException $e) {