10000 Pass the raw mime type to Request · FriendsOfSymfony/FOSRestBundle@52a5d82 · GitHub
[go: up one dir, main page]

Skip to content

Commit 52a5d82

Browse files
committed
Pass the raw mime type to Request
1 parent a0e671a commit 52a5d82

File tree

5 files changed

+10
-9
lines changed

5 files changed

+10
-9
lines changed

DependencyInjection/FOSRestExtension.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,6 @@ private function loadFormatListener(array $config, XmlFileLoader $loader, Contai
154154
'fos_rest.format_listener.rules',
155155
$config['format_listener']['rules']
156156
);
157-
158-
if ($config['view']['mime_types']['enabled'] && !method_exists(Request::class, 'getMimeTypes')) {
159-
$container->getDefinition('fos_rest.format_negotiator')->addArgument($config['view']['mime_types']['formats']);
160-
}
161157
}
162158
}
163159

EventListener/FormatListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function onKernelRequest(GetResponseEvent $event)
5959
if (null === $format) {
6060
$accept = $this->formatNegotiator->getBest('');
6161
if (null !== $accept && 0.0 < $accept->getQuality()) {
62-
$format = $request->getFormat($accept->getType());
62+
$format = $request->getFormat($accept->getValue());
6363
if (null !== $format) {
6464
$request->attributes->set('media_type', $accept->getValue());
6565
}

EventListener/MimeTypeListener.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ public function onKernelRequest(GetResponseEvent $event)
5858
} elseif (null !== $request->getMimeType($format)) {
5959
$class = new \ReflectionClass(Request::class);
6060
$properties = $class->getStaticProperties();
61-
$mimeTypes = array_merge($mimeTypes, $properties['formats'][$format]);
61+
if (isset($properties['formats'][$format])) {
62+
$mimeTypes = array_merge($mimeTypes, $properties['formats'][$format]);
63+
}
6264
}
6365

6466
$request->setFormat($format, $mimeTypes);

Tests/Functional/VersionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function testCustomHeaderVersion()
3030
'/version?query_version=3.2',
3131
[],
3232
[],
33-
['HTTP_Version-Header' => '2.1', 'HTTP_Accept' => 'application/json;myversion=2.3']
33+
['HTTP_Version-Header' => '2.1', 'HTTP_Accept' => 'application/vnd.foo.api+json;myversion=2.3']
3434
);
3535
$this->assertEquals('{"version":"2.1"}', $this->client->getResponse()->getContent());
3636
}
@@ -54,7 +54,7 @@ public function testAcceptHeaderVersion()
5454
'/version?query_version=3.2',
5555
[],
5656
[],
57-
['HTTP_Accept' => 'application/json;myversion=2.3']
57+
['HTTP_Accept' => 'application/vnd.foo.api+json;myversion=2.3']
5858
);
5959
$this->assertEquals('{"version":"2.3"}', $this->client->getResponse()->getContent());
6060
}

Tests/Functional/app/Version/config.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ fos_rest:
1515
view:
1616
view_response_listener: true
1717
mime_types:
18-
json: ['application/json', 'application/json;myversion=2.3']
18+
json:
19+
- application/json
20+
- application/vnd.foo.api+json;myversion=2.3
21+
- application/vnd.foo.api+json # Fix for https://github.com/FriendsOfSymfony/FOSRestBundle/issues/1399
1922
versioning:
2023
enabled: true
2124
default_version: 3.4.2

0 commit comments

Comments
 (0)
0