Unverified Commit a46090e0 authored by larowlan's avatar larowlan

Issue #2934152 by Wim Leers, neclimdul: ContentTypeHeaderMatcher should not...

Issue #2934152 by Wim Leers, neclimdul: ContentTypeHeaderMatcher should not run for GET, HEAD, OPTIONS or TRACE requests
parent 891c39b3
......@@ -16,8 +16,9 @@ class ContentTypeHeaderMatcher implements FilterInterface {
*/
public function filter(RouteCollection $collection, Request $request) {
// The Content-type header does not make sense on GET requests, because GET
// requests do not carry any content. Nothing to filter in this case.
if ($request->isMethod('GET')) {
// requests do not carry any content. Nothing to filter in this case. Same
// for all other safe methods.
if ($request->isMethodSafe(FALSE)) {
return $collection;
}
......
......@@ -42,17 +42,28 @@ protected function setUp() {
}
/**
* Tests that routes are not filtered on GET requests.
* Tests that routes are not filtered on safe requests.
*
* @dataProvider providerTestSafeRequestFilter
*/
public function testGetRequestFilter() {
public function testSafeRequestFilter($method) {
$collection = $this->fixtures->sampleRouteCollection();
$collection->addCollection($this->fixtures->contentRouteCollection());
$request = Request::create('path/two', 'GET');
$request = Request::create('path/two', $method);
$routes = $this->matcher->filter($collection, $request);
$this->assertEquals(count($routes), 7, 'The correct number of routes was found.');
}
public function providerTestSafeRequestFilter() {
return [
['GET'],
['HEAD'],
['OPTIONS'],
['TRACE'],
];
}
/**
* Tests that XML-restricted routes get filtered out on JSON requests.
*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment