Permalink
Browse files

Re-introduce "Add `$strict` parameter to `getBest()` to enable except…

…ions for invalid media types.""
  • Loading branch information...
1 parent 1f210db commit 93c3cbf7f04bb4b2c38c01316b3642536e12b0ee @willdurand committed Oct 14, 2016
Showing with 15 additions and 2 deletions.
  1. +4 −2 src/Negotiation/AbstractNegotiator.php
  2. +11 −0 tests/Negotiation/Tests/NegotiatorTest.php
@@ -13,7 +13,7 @@
*
* @return AcceptHeader|null best matching type
*/
- public function getBest($header, array $priorities)
+ public function getBest($header, array $priorities, $strict = false)
{
if (empty($priorities)) {
throw new InvalidArgument('A set of server priorities should be given.');
@@ -33,7 +33,9 @@ public function getBest($header, array $priorities)
try {
$acceptedHeaders[] = $this->acceptFactory($h);
} catch (Exception\Exception $e) {
- // silently skip in case of invalid headers coming in from a client
+ if ($strict) {
+ throw $e;
+ }
}
}
$acceptedPriorities = array();
@@ -104,6 +104,17 @@ public function testGetBestRespectsQualityOfSource()
$this->assertEquals('text/plain', $accept->getType());
}
+ /**
+ * @expectedException Negotiation\Exception\InvalidMediaType
+ */
+ public function testGetBestInvalidMediaType()
+ {
+ $header = 'sdlfkj20ff; wdf';
+ $priorities = array('foo/qwer');
+
+ $this->negotiator->getBest($header, $priorities, true);
+ }
+
/**
* @dataProvider dataProviderForTestParseHeader
*/

0 comments on commit 93c3cbf

Please sign in to comment.