Revert "Issue #2811133 by Wim Leers, neclimdul, dawehner: Confusing error response set by ContentTypeHeaderMatcher when forgetting the Content-Type request header"
This reverts commit 97f0d43d67
.
8.3.x
parent
1b5802d05e
commit
b104e87731
|
@ -42,12 +42,7 @@ class ContentTypeHeaderMatcher implements RouteFilterInterface {
|
||||||
// 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 @@ namespace Drupal\Tests\Core\Routing;
|
||||||
|
|
||||||
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 @@ class ContentTypeHeaderMatcherTest extends UnitTestCase {
|
||||||
/**
|
/**
|
||||||
* 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 @@ class ContentTypeHeaderMatcherTest extends UnitTestCase {
|
||||||
$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.');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue