Skip to content

Commit

Permalink
Merge 2fe5abb into d46ac32
Browse files Browse the repository at this point in the history
  • Loading branch information
dunglas committed Jul 1, 2019
2 parents d46ac32 + 2fe5abb commit bbdfb96
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion features/security/validate_incoming_content-types.feature
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ Feature: Validate incoming content type
"""
something
"""
Then the response status code should be 406
Then the response status code should be 415
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
And the JSON node "hydra:description" should be equal to 'The content-type "text/plain" is not supported. Supported MIME types are "application/ld+json", "application/hal+json", "application/vnd.api+json", "application/xml", "text/xml", "application/json", "text/html".'
5 changes: 3 additions & 2 deletions src/EventListener/DeserializeListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException;
use Symfony\Component\HttpKernel\Exception\UnsupportedMediaTypeHttpException;
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
use Symfony\Component\Serializer\SerializerInterface;

Expand Down Expand Up @@ -113,7 +114,7 @@ private function getFormat(Request $request): string
*/
$contentType = $request->headers->get('CONTENT_TYPE');
if (null === $contentType) {
throw new NotAcceptableHttpException('The "Content-Type" header must exist.');
throw new UnsupportedMediaTypeHttpException('The "Content-Type" header must exist.');
}

$format = $this->formatMatcher->getFormat($contentType);
Expand All @@ -125,7 +126,7 @@ private function getFormat(Request $request): string
}
}

throw new NotAcceptableHttpException(sprintf(
throw new UnsupportedMediaTypeHttpException(sprintf(
'The content-type "%s" is not supported. Supported MIME types are "%s".',
$contentType,
implode('", "', $supportedMimeTypes)
Expand Down
6 changes: 3 additions & 3 deletions tests/EventListener/DeserializeListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
use Prophecy\Argument;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException;
use Symfony\Component\HttpKernel\Exception\UnsupportedMediaTypeHttpException;
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
use Symfony\Component\Serializer\SerializerInterface;

Expand Down Expand Up @@ -227,7 +227,7 @@ public function testContentNegotiation()

public function testNotSupportedContentType()
{
$this->expectException(NotAcceptableHttpException::class);
$this->expectException(UnsupportedMediaTypeHttpException::class);
$this->expectExceptionMessage('The content-type "application/rdf+xml" is not supported. Supported MIME types are "application/ld+json", "text/xml".');

$eventProphecy = $this->prophesize(GetResponseEvent::class);
Expand Down Expand Up @@ -257,7 +257,7 @@ public function testNotSupportedContentType()

public function testNoContentType()
{
$this->expectException(NotAcceptableHttpException::class);
$this->expectException(UnsupportedMediaTypeHttpException::class);
$this->expectExceptionMessage('The "Content-Type" header must exist.');

$eventProphecy = $this->prophesize(GetResponseEvent::class);
Expand Down

0 comments on commit bbdfb96

Please sign in to comment.