Skip to content

Commit cfebcf1

Browse files
committed
Fix requests without content type
1 parent df91030 commit cfebcf1

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

Request/RequestBodyParamConverter.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,16 @@ public function apply(Request $request, ParamConverter $configuration)
8181
}
8282
$this->configureContext($context = new Context(), $arrayContext);
8383

84+
$format = $request->getContentType();
85+
if (null === $format) {
86+
return $this->throwException(new UnsupportedMediaTypeHttpException(), $configuration);
87+
}
88+
8489
try {
8590
$object = $this->serializer->deserialize(
8691
$request->getContent(),
8792
$configuration->getClass(),
88-
$request->getContentType(),
93+
$format,
8994
$context
9095
);
9196
} catch (UnsupportedFormatException $e) {

Tests/Request/RequestBodyParamConverterTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,15 @@ public function testSupportsWithNoClass()
273273
$this->assertFalse($converter->supports($this->createConfiguration(null, 'post')));
274274
}
275275

276+
public function testNoContentTypeCausesUnsupportedMediaTypeException()
277+
{
278+
$converter = new RequestBodyParamConverter($this->serializer);
279+
$request = $this->createRequest();
280+
$request->headers->remove('CONTENT_TYPE');
281+
$this->expectException(UnsupportedMediaTypeHttpException::class);
282+
$this->launchExecution($converter, $request);
283+
}
284+
276285
protected function launchExecution($converter, $request = null, $configuration = null)
277286
{
278287
if (null === $request) {

0 commit comments

Comments
 (0)