Skip to content

Commit

Permalink
Use the detected mime type as Content-Type (#1683)
Browse files Browse the repository at this point in the history
  • Loading branch information
GuilhemN committed Mar 16, 2017
1 parent 6ecf0e7 commit 66b66dd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 4 additions & 1 deletion Tests/Functional/VersionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ public function testAcceptHeaderVersion()
[],
['HTTP_Accept' => 'application/vnd.foo.api+json;myversion=2.3']
);
$this->assertEquals('{"version":"2.3"}', $this->client->getResponse()->getContent());

$response = $this->client->getResponse();
$this->assertEquals('{"version":"2.3"}', $response->getContent());
$this->assertEquals('application/vnd.foo.api+json;myversion=2.3', $response->headers->get('Content-Type'));
}

public function testDefaultVersion()
Expand Down
7 changes: 6 additions & 1 deletion View/ViewHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,12 @@ public function createResponse(View $view, Request $request, $format)
$response = $this->initResponse($view, $format);

if (!$response->headers->has('Content-Type')) {
$response->headers->set('Content-Type', $request->getMimeType($format));
$mimeType = $request->attributes->get('media_type');
if (null === $mimeType) {
$mimeType = $request->getMimeType($format);
}

$response->headers->set('Content-Type', $mimeType);
}

return $response;
Expand Down

0 comments on commit 66b66dd

Please sign in to comment.