Skip to content

Commit

Permalink
Merge pull request #4081 from caswell-wc/bug-fix-isJson
Browse files Browse the repository at this point in the history
Fixing a bug in Message::isJSON
  • Loading branch information
samsonasik authored Jan 10, 2021
2 parents d09a546 + 50de15c commit 6861a58
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
11 changes: 9 additions & 2 deletions system/HTTP/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,14 @@ public function getProtocolVersion(): string
*/
public function isJSON()
{
return $this->hasHeader('Content-Type')
&& $this->header('Content-Type')->getValue() === 'application/json';
if (! $this->hasHeader('Content-Type'))
{
return false;
}

$header = $this->header('Content-Type')->getValue();
$parts = explode(';', $header);

return in_array('application/json', $parts, true);
}
}
6 changes: 6 additions & 0 deletions tests/system/HTTP/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,4 +349,10 @@ public function testIsJsonReturnsTrue()
$this->assertTrue($this->message->isJSON());
}

public function testIsJsonWorksWithExtendedContentType()
{
$this->message->setHeader('Content-Type', 'application/json;charset=UTF-8');
$this->assertTrue($this->message->isJSON());
}

}

0 comments on commit 6861a58

Please sign in to comment.