Skip to content

Commit

Permalink
Merge pull request #718 from teohhanhui/add-vary-accept-header
Browse files Browse the repository at this point in the history
Add "Vary: Accept" response header
  • Loading branch information
dunglas committed Sep 1, 2016
2 parents 255873d + 0a1d9a3 commit f2427de
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/EventListener/AddFormatListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct(Negotiator $negotiator, array $formats)
/**
* Sets the applicable format to the HttpFoundation Request.
*
* @param $event GetResponseEvent
* @param GetResponseEvent $event
*/
public function onKernelRequest(GetResponseEvent $event)
{
Expand Down
1 change: 1 addition & 0 deletions src/EventListener/RespondListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public function onKernelView(GetResponseForControllerResultEvent $event)
self::METHOD_TO_CODE[$request->getMethod()] ?? Response::HTTP_OK,
[
'Content-Type' => sprintf('%s; charset=utf-8', $request->getMimeType($request->getRequestFormat())),
'Vary' => 'Accept',
'X-Content-Type-Options' => 'nosniff',
'X-Frame-Options' => 'deny',
]
Expand Down
3 changes: 3 additions & 0 deletions tests/EventListener/RespondListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public function testCreate200Response()
$this->assertEquals('foo', $response->getContent());
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
$this->assertEquals('text/xml; charset=utf-8', $response->headers->get('Content-Type'));
$this->assertEquals('Accept', $response->headers->get('Vary'));
$this->assertEquals('nosniff', $response->headers->get('X-Content-Type-Options'));
$this->assertEquals('deny', $response->headers->get('X-Frame-Options'));
}
Expand All @@ -81,6 +82,7 @@ public function testCreate201Response()
$this->assertEquals('foo', $response->getContent());
$this->assertEquals(Response::HTTP_CREATED, $response->getStatusCode());
$this->assertEquals('text/xml; charset=utf-8', $response->headers->get('Content-Type'));
$this->assertEquals('Accept', $response->headers->get('Vary'));
$this->assertEquals('nosniff', $response->headers->get('X-Content-Type-Options'));
$this->assertEquals('deny', $response->headers->get('X-Frame-Options'));
}
Expand All @@ -107,6 +109,7 @@ public function testCreate204Response()
$this->assertEquals('foo', $response->getContent());
$this->assertEquals(Response::HTTP_NO_CONTENT, $response->getStatusCode());
$this->assertEquals('text/xml; charset=utf-8', $response->headers->get('Content-Type'));
$this->assertEquals('Accept', $response->headers->get('Vary'));
$this->assertEquals('nosniff', $response->headers->get('X-Content-Type-Options'));
$this->assertEquals('deny', $response->headers->get('X-Frame-Options'));
}
Expand Down

0 comments on commit f2427de

Please sign in to comment.