Skip to content

Commit

Permalink
Merge pull request #14 from SimonSimCity/null-for-inacceptable-mimetype
Browse files Browse the repository at this point in the history
Fail if the Accept-header doesn’t match one of the supported mime types
  • Loading branch information
willdurand committed Jan 9, 2014
2 parents 1757fc4 + a1511ae commit 8b32a05
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Negotiation/FormatNegotiator.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ public function getBest($header, array $priorities = array())
}
}

return array_shift($acceptHeaders) ?: null;
// If $priorities is empty or contains a catch-all mime type
if ($catchAllEnabled) {
return array_shift($acceptHeaders) ?: null;
}

return null;
}

/**
Expand Down
9 changes: 9 additions & 0 deletions tests/Negotiation/Tests/FormatNegotiatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,14 @@ public static function dataProviderForGetBest()
'parameters' => array(),
),
),
// Incompatible
array(
'text/html',
array(
'application/rss'
),
null
),
);
}

Expand All @@ -263,6 +271,7 @@ public static function dataProviderForGetBestFormat()
array('text/html,application/xhtml+xml,application/xml', array('json'), null),
array('text/plain; q=0.5, text/html, text/x-dvi; q=0.8, text/x-c', array('*/*'), 'html'),
array('text/html, application/json;q=0.8, text/csv;q=0.7', array(), 'html'),
array('text/html', array('text/xml'), null),
);
}

Expand Down

0 comments on commit 8b32a05

Please sign in to comment.