diff --git a/system/HTTP/IncomingRequest.php b/system/HTTP/IncomingRequest.php index d5b34d2c0b2b..a05c00710a95 100755 --- a/system/HTTP/IncomingRequest.php +++ b/system/HTTP/IncomingRequest.php @@ -294,7 +294,7 @@ public function isSecure(): bool */ public function getVar($index = null, $filter = null, $flags = null) { - if ($this->isJSON()) + if (strpos($this->getHeaderLine('Content-Type'), 'application/json') !== false) { if (is_null($index)) { diff --git a/system/HTTP/Message.php b/system/HTTP/Message.php index 93dbe3f318a0..edcf23215244 100644 --- a/system/HTTP/Message.php +++ b/system/HTTP/Message.php @@ -132,24 +132,4 @@ public function getProtocolVersion(): string { return $this->protocolVersion ?? '1.1'; } - - /** - * Determines if this is a json message based on the Content-Type header - * - * @return boolean - * - * @deprecated Use header calls directly - */ - public function isJSON() - { - if (! $this->hasHeader('Content-Type')) - { - return false; - } - - $header = $this->header('Content-Type')->getValue(); - $parts = explode(';', $header); - - return in_array('application/json', $parts, true); - } } diff --git a/system/Validation/Validation.php b/system/Validation/Validation.php index ea3a00958e32..1d52edc9f558 100644 --- a/system/Validation/Validation.php +++ b/system/Validation/Validation.php @@ -346,7 +346,7 @@ protected function processRules(string $field, string $label = null, $value, $ru */ public function withRequest(RequestInterface $request): ValidationInterface { - if ($request->isJSON()) + if (strpos($request->getHeaderLine('Content-Type'), 'application/json') !== false) { $this->data = $request->getJSON(true); return $this; diff --git a/tests/system/HTTP/MessageTest.php b/tests/system/HTTP/MessageTest.php index 3972a63fdd33..f94826d41701 100644 --- a/tests/system/HTTP/MessageTest.php +++ b/tests/system/HTTP/MessageTest.php @@ -331,28 +331,4 @@ public function testPopulateHeaders() $this->message->removeHeader('accept-language'); $_SERVER = $original; // restore so code coverage doesn't break } - - public function testIsJsonReturnsFalseWithNoHeader() - { - $this->assertFalse($this->message->isJSON()); - } - - public function testIsJsonReturnsFalseWithWrongContentType() - { - $this->message->setHeader('Content-Type', 'application/xml'); - $this->assertFalse($this->message->isJSON()); - } - - public function testIsJsonReturnsTrue() - { - $this->message->setHeader('Content-Type', 'application/json'); - $this->assertTrue($this->message->isJSON()); - } - - public function testIsJsonWorksWithExtendedContentType() - { - $this->message->setHeader('Content-Type', 'application/json;charset=UTF-8'); - $this->assertTrue($this->message->isJSON()); - } - }