From 1c8fff18f9ee979cd4eb32e8a8b782258f31d34b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Tue, 13 Oct 2020 17:26:48 +0200 Subject: [PATCH 1/2] Remove content-type check on toArray methods --- src/Symfony/Component/HttpClient/Response/ResponseTrait.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/Symfony/Component/HttpClient/Response/ResponseTrait.php b/src/Symfony/Component/HttpClient/Response/ResponseTrait.php index 4a3dfce062..d6ddae6def 100644 --- a/src/Symfony/Component/HttpClient/Response/ResponseTrait.php +++ b/src/Symfony/Component/HttpClient/Response/ResponseTrait.php @@ -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) { From 91122492e8786417878b53401d57526f89f2cf45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Tue, 13 Oct 2020 22:48:16 +0200 Subject: [PATCH 2/2] Fix tests --- .../HttpClient/Tests/Response/MockResponseTest.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/Symfony/Component/HttpClient/Tests/Response/MockResponseTest.php b/src/Symfony/Component/HttpClient/Tests/Response/MockResponseTest.php index a531da3535..b4a4a22083 100644 --- a/src/Symfony/Component/HttpClient/Tests/Response/MockResponseTest.php +++ b/src/Symfony/Component/HttpClient/Tests/Response/MockResponseTest.php @@ -41,12 +41,6 @@ class MockResponseTest extends TestCase 'message' => 'Response body is empty.', ]; - yield [ - 'content' => '{}', - 'responseHeaders' => ['content-type' => 'plain/text'], - 'message' => 'Response content-type is "plain/text" while a JSON-compatible one was expected for "https://example.com/file.json".', - ]; - yield [ 'content' => 'not json', 'responseHeaders' => [],