Skip to content

Commit

Permalink
Pass the raw mime type to Request
Browse files Browse the repository at this point in the history
  • Loading branch information
GuilhemN committed Mar 21, 2016
1 parent a0e671a commit 52a5d82
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
4 changes: 0 additions & 4 deletions DependencyInjection/FOSRestExtension.php
Expand Up @@ -154,10 +154,6 @@ private function loadFormatListener(array $config, XmlFileLoader $loader, Contai
'fos_rest.format_listener.rules',
$config['format_listener']['rules']
);

if ($config['view']['mime_types']['enabled'] && !method_exists(Request::class, 'getMimeTypes')) {
$container->getDefinition('fos_rest.format_negotiator')->addArgument($config['view']['mime_types']['formats']);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion EventListener/FormatListener.php
Expand Up @@ -59,7 +59,7 @@ public function onKernelRequest(GetResponseEvent $event)
if (null === $format) {
$accept = $this->formatNegotiator->getBest('');
if (null !== $accept && 0.0 < $accept->getQuality()) {
$format = $request->getFormat($accept->getType());
$format = $request->getFormat($accept->getValue());
if (null !== $format) {
$request->attributes->set('media_type', $accept->getValue());
}
Expand Down
4 changes: 3 additions & 1 deletion EventListener/MimeTypeListener.php
Expand Up @@ -58,7 +58,9 @@ public function onKernelRequest(GetResponseEvent $event)
} elseif (null !== $request->getMimeType($format)) {
$class = new \ReflectionClass(Request::class);
$properties = $class->getStaticProperties();
$mimeTypes = array_merge($mimeTypes, $properties['formats'][$format]);
if (isset($properties['formats'][$format])) {
$mimeTypes = array_merge($mimeTypes, $properties['formats'][$format]);
}
}

$request->setFormat($format, $mimeTypes);
Expand Down
4 changes: 2 additions & 2 deletions Tests/Functional/VersionTest.php
Expand Up @@ -30,7 +30,7 @@ public function testCustomHeaderVersion()
'/version?query_version=3.2',
[],
[],
['HTTP_Version-Header' => '2.1', 'HTTP_Accept' => 'application/json;myversion=2.3']
['HTTP_Version-Header' => '2.1', 'HTTP_Accept' => 'application/vnd.foo.api+json;myversion=2.3']
);
$this->assertEquals('{"version":"2.1"}', $this->client->getResponse()->getContent());
}
Expand All @@ -54,7 +54,7 @@ public function testAcceptHeaderVersion()
'/version?query_version=3.2',
[],
[],
['HTTP_Accept' => 'application/json;myversion=2.3']
['HTTP_Accept' => 'application/vnd.foo.api+json;myversion=2.3']
);
$this->assertEquals('{"version":"2.3"}', $this->client->getResponse()->getContent());
}
Expand Down
5 changes: 4 additions & 1 deletion Tests/Functional/app/Version/config.yml
Expand Up @@ -15,7 +15,10 @@ fos_rest:
view:
view_response_listener: true
mime_types:
json: ['application/json', 'application/json;myversion=2.3']
json:
- application/json
- application/vnd.foo.api+json;myversion=2.3
- application/vnd.foo.api+json # Fix for https://github.com/FriendsOfSymfony/FOSRestBundle/issues/1399
versioning:
enabled: true
default_version: 3.4.2
Expand Down

0 comments on commit 52a5d82

Please sign in to comment.