Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HTTP] Remove Message::isJson() #4242

Merged
merged 3 commits into from
Feb 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion system/HTTP/IncomingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down
20 changes: 0 additions & 20 deletions system/HTTP/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion system/Validation/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 0 additions & 24 deletions tests/system/HTTP/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

}