Skip to content
Snippets Groups Projects
Commit b104e877 authored by catch's avatar catch
Browse files

Revert "Issue #2811133 by Wim Leers, neclimdul, dawehner: Confusing error...

Revert "Issue #2811133 by Wim Leers, neclimdul, dawehner: Confusing error response set by ContentTypeHeaderMatcher when forgetting the Content-Type request header"

This reverts commit 97f0d43d.
parent 1b5802d0
No related branches found
No related tags found
No related merge requests found
...@@ -42,12 +42,7 @@ public function filter(RouteCollection $collection, Request $request) { ...@@ -42,12 +42,7 @@ public function filter(RouteCollection $collection, Request $request) {
// We do not throw a // We do not throw a
// \Symfony\Component\Routing\Exception\ResourceNotFoundException here // \Symfony\Component\Routing\Exception\ResourceNotFoundException here
// because we don't want to return a 404 status code, but rather a 415. // because we don't want to return a 404 status code, but rather a 415.
if (!$request->headers->has('Content-Type')) { throw new UnsupportedMediaTypeHttpException('No route found that matches "Content-Type: ' . $request->headers->get('Content-Type') . '"');
throw new UnsupportedMediaTypeHttpException('No "Content-Type" request header specified');
}
else {
throw new UnsupportedMediaTypeHttpException('No route found that matches "Content-Type: ' . $request->headers->get('Content-Type') . '"');
}
} }
/** /**
......
...@@ -4,16 +4,12 @@ ...@@ -4,16 +4,12 @@
use Drupal\Core\Routing\ContentTypeHeaderMatcher; use Drupal\Core\Routing\ContentTypeHeaderMatcher;
use Drupal\Tests\UnitTestCase; use Drupal\Tests\UnitTestCase;
use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\UnsupportedMediaTypeHttpException;
/** /**
* Confirm that the content types partial matcher is functioning properly. * Confirm that the content types partial matcher is functioning properly.
* *
* @group Routing * @group Routing
*
* @coversDefaultClass \Drupal\Core\Routing\ContentTypeHeaderMatcher
*/ */
class ContentTypeHeaderMatcherTest extends UnitTestCase { class ContentTypeHeaderMatcherTest extends UnitTestCase {
...@@ -92,7 +88,8 @@ public function testPostForm() { ...@@ -92,7 +88,8 @@ public function testPostForm() {
/** /**
* Confirms that the matcher throws an exception for no-route. * Confirms that the matcher throws an exception for no-route.
* *
* @covers ::filter * @expectedException \Symfony\Component\HttpKernel\Exception\UnsupportedMediaTypeHttpException
* @expectedExceptionMessage No route found that matches "Content-Type: application/hal+json"
*/ */
public function testNoRouteFound() { public function testNoRouteFound() {
$matcher = new ContentTypeHeaderMatcher(); $matcher = new ContentTypeHeaderMatcher();
...@@ -100,24 +97,8 @@ public function testNoRouteFound() { ...@@ -100,24 +97,8 @@ public function testNoRouteFound() {
$routes = $this->fixtures->contentRouteCollection(); $routes = $this->fixtures->contentRouteCollection();
$request = Request::create('path/two', 'POST'); $request = Request::create('path/two', 'POST');
$request->headers->set('Content-type', 'application/hal+json'); $request->headers->set('Content-type', 'application/hal+json');
$this->setExpectedException(UnsupportedMediaTypeHttpException::class, 'No route found that matches "Content-Type: application/hal+json"');
$matcher->filter($routes, $request);
}
/**
* Confirms that the matcher throws an exception for missing request header.
*
* @covers ::filter
*/
public function testContentTypeRequestHeaderMissing() {
$matcher = new ContentTypeHeaderMatcher();
$routes = $this->fixtures->contentRouteCollection();
$request = Request::create('path/two', 'POST');
// Delete all request headers that Request::create() sets by default.
$request->headers = new ParameterBag();
$this->setExpectedException(UnsupportedMediaTypeHttpException::class, 'No "Content-Type" request header specified.');
$matcher->filter($routes, $request); $matcher->filter($routes, $request);
$this->fail('No exception was thrown.');
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment